Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REST API #8

Merged
merged 50 commits into from
Jan 31, 2020
Merged

Add REST API #8

merged 50 commits into from
Jan 31, 2020

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented Jan 14, 2020

This PR aims to provide a foundation for the WP REST API and the extensibility of Unsplash's API.

To have the API working correctly, copy the .env.example to .env and update it with the specified Unsplash credentials.

Routes:

  • Get Unsplash photos
  • Get Unsplash photo by ID
  • Search Unsplash photos

Todo:

  • Add unit tests for Router class
  • Add integration tests for REST API

@pierlon
Copy link
Contributor Author

pierlon commented Jan 14, 2020

⚠️ Rebasing with latest changes from master.

@pierlon pierlon force-pushed the enhancement/28-unsplash-proxy branch from 62ab71d to 1b8d1a0 Compare January 14, 2020 06:13
@pierlon pierlon changed the title Add REST API WIP: Add REST API Jan 14, 2020
@spacedmonkey
Copy link
Contributor

Can you make sure that travis test pass before I review.

unsplash.php Outdated Show resolved Hide resolved
@spacedmonkey spacedmonkey mentioned this pull request Jan 16, 2020
@spacedmonkey
Copy link
Contributor

Based on my feedback here I have created a PR see #10

php/Router.php Outdated Show resolved Hide resolved
* @param \Exception $e Exception.
*/
private function log_error( \Exception $e ) {
$message = sprintf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could even intergrate with stream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of that function. Any better/simpler solutions are appreciated.

@pierlon pierlon changed the title WIP: Add REST API Add REST API Jan 20, 2020
@pierlon
Copy link
Contributor Author

pierlon commented Jan 21, 2020

@derekherman The UNSPLASH_APP_ID and UNSPLASH_APP_SECRET env vars need to be added to Travis so the integration tests can be run.

@pierlon
Copy link
Contributor Author

pierlon commented Jan 21, 2020

⚠️ Rebasing to squash commits that add code coverage support only for PHP 7.

@pierlon pierlon force-pushed the enhancement/28-unsplash-proxy branch from 9fdd854 to 0325121 Compare January 21, 2020 06:43
@spacedmonkey spacedmonkey changed the base branch from master to develop January 23, 2020 10:34
@pierlon pierlon force-pushed the enhancement/28-unsplash-proxy branch 2 times, most recently from 3aca14f to 241c390 Compare January 24, 2020 04:53
php/Router.php Outdated Show resolved Hide resolved
* @param string $path URL path.
* @return string Route path.
*/
private function get_route( $path = '' ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this need to be private?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a get_route method in the RestController class that this is mimicking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, its just a helper method for the test class. No specific reason as to why its private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically if we need to duplicate something by creating helper functions then it's probably better to create a method in the class not the test class.

@@ -0,0 +1,34 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pierlon I'd assume that the tests would be integration tests not unit. What is the reasoning behind mocking instead of creating actual tests that load WP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason in particular. Just wanted to add a test to ensure the actions in init() were being called. Writing tests for the other functions would be in vain since they will most likely change very soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add an integration test as well (and/or remove the unit test) if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding them now

@derekherman
Copy link
Contributor

@pierlon I've added a bit more to the settings class to encrypt and decrypt the stored values. Could you please save them in the settings page and test all is working.

php/Settings.php Outdated
}
}
return $settings;
return $sanitized_settings;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could be adding additional keys to the array, so this is overlooking that use case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd assume we'd want to validate those key-value pairs as well, and not just pass in the settings we received from the user.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would add that in when we know more. The logic was broken anyhow as it would clear out values on re-save.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea you're right 😅 , that's on me

*
* @covers ::access_key_render()
*/
public function test_access_key_render() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Methods like this are testing output and not functionality which is less useful. We can leave it but I suspect these fields will be changing anyhow.

@derekherman derekherman merged commit 317da14 into develop Jan 31, 2020
@derekherman derekherman deleted the enhancement/28-unsplash-proxy branch January 31, 2020 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants