diff --git a/.travis.yml b/.travis.yml index 8000536..7257881 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - 5.5 + - 5.6 install: - composer --no-interaction install script: phpunit --configuration phpunit.xml --coverage-clover=coverage.clover diff --git a/README.md b/README.md index ea822be..e77db1a 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ use Strava\API\Exception; use Strava\API\Service\REST; try { - $adapter = new Pest('https://www.strava.com/api/v3'); + $adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']); $service = new REST($token, $adapter); // Define your user token here. $client = new Client($service); @@ -146,8 +146,8 @@ $oauth->getAccessToken($grant = 'authorization_code', $params = []); ### Strava\API\Client #### Usage ```php -// REST adapter (We use `Pest` in this project) -$adapter = new Pest('https://www.strava.com/api/v3'); +// REST adapter (We use `Guzzle` in this project) +$adapter = new \GuzzleHttp\Client(['base_uri' => 'https://www.strava.com/api/v3']); // Service to use (Service\Stub is also available for test purposes) $service = new Service\REST('RECEIVED-TOKEN', $adapter); @@ -207,7 +207,7 @@ $client->getStreamsRoute($id); ### Used libraries - [Strava API](https://strava.github.io/api/) - [thephpleague/oauth2-client](https://github.com/thephpleague/oauth2-client/) -- [educoder/pest](https://github.com/educoder/pest) +- [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) ### Development The StravaPHP library was created by Bas van Dorst, [software engineer](https://www.linkedin.com/in/basvandorst) and cyclist enthusiast. diff --git a/composer.json b/composer.json index b4b4ca3..6e4fcd3 100644 --- a/composer.json +++ b/composer.json @@ -9,12 +9,12 @@ "StravaPHP" ], "require": { - "php": ">=5.5.0", - "educoder/pest": "~1.0", - "league/oauth2-client": "~1.0" + "php": ">=5.6", + "league/oauth2-client": "~2.3", + "guzzlehttp/guzzle": "~6.3" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^5" }, "license": "MIT", "authors": [ diff --git a/src/Strava/API/Factory.php b/src/Strava/API/Factory.php index f340f2f..786b6c1 100644 --- a/src/Strava/API/Factory.php +++ b/src/Strava/API/Factory.php @@ -1,8 +1,6 @@ self::$endpoint]); $service = new Service\REST($token, $adapter); $APIClient = new Client($service); diff --git a/src/Strava/API/Service/REST.php b/src/Strava/API/Service/REST.php index 76113f4..ac052cf 100644 --- a/src/Strava/API/Service/REST.php +++ b/src/Strava/API/Service/REST.php @@ -1,7 +1,9 @@ token = $token; $this->adapter = $adapter; } - private function getHeaders() + private function getToken() { - return array('Authorization: Bearer ' . $this->token); + return $this->token; + } + + /** + * Get a request result. + * Returns an array with a response body or and error code => reason. + * @param \GuzzleHttp\Psr7\Response $response + * @return array|mixed + */ + private function getResult($response) + { + $status = $response->getStatusCode(); + if ($status == 200) { + return json_decode($response->getBody(), JSON_PRETTY_PRINT); + } else { + return [$status => $response->getReasonPhrase()]; + } + } + + /** + * Get an API request response and handle possible exceptions. + * + * @param string $method + * @param string $path + * @param array $parameters + * + * @return array|mixed|string + */ + private function getResponse($method, $path, $parameters) + { + try { + $response = $this->adapter->request($method, $path, $parameters); + return $this->getResult($response); + } + catch (\Exception $e) { + return $e->getMessage(); + } } public function getAthlete($id = null) { - $path = '/athlete'; + $path = 'athlete'; if (isset($id) && $id !== null) { - $path = '/athletes/' . $id; + $path = 'athletes/' . $id; } - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteStats($id) { - $path = '/athletes/' . $id . '/stats'; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'athletes/' . $id . '/stats'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null) { - $path = '/athletes/' . $id . '/routes'; - $parameters = array( + $path = 'athletes/' . $id . '/routes'; + $parameters['query'] = [ 'type' => $type, 'after' => $after, 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteClubs() { - $path = '/athlete/clubs'; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'athlete/clubs'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteActivities($before = null, $after = null, $page = null, $per_page = null) { - $path = '/athlete/activities'; - $parameters = array( + $path = 'athlete/activities'; + $parameters['query'] = [ 'before' => $before, 'after' => $after, 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteFriends($id = null, $page = null, $per_page = null) { - $path = '/athlete/friends'; + $path = 'athlete/friends'; if (isset($id) && $id !== null) { - $path = '/athletes/' . $id . '/friends'; + $path = 'athletes/' . $id . '/friends'; } - - $parameters = array( + $parameters['query'] = [ 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteFollowers($id = null, $page = null, $per_page = null) { - $path = '/athlete/followers'; + $path = 'athlete/followers'; if (isset($id) && $id !== null) { - $path = '/athletes/' . $id . '/followers'; + $path = 'athletes/' . $id . '/followers'; } - - $parameters = array( + $parameters['query'] = [ 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteBothFollowing($id, $page = null, $per_page = null) { - $path = '/athletes/' . $id . '/both-following'; - - $parameters = array( + $path = 'athletes/' . $id . '/both-following'; + $parameters['query'] = [ 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteKom($id, $page = null, $per_page = null) { - $path = '/athletes/' . $id . '/koms'; - - $parameters = array( + $path = 'athletes/' . $id . '/koms'; + $parameters['query'] = [ 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteZones() { - $path = '/athlete/zones'; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'athlete/zones'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getAthleteStarredSegments($id = null, $page = null, $per_page = null) { - $path = '/segments/starred'; + $path = 'segments/starred'; if (isset($id) && $id !== null) { - $path = '/athletes/' . $id . '/segments/starred'; + $path = 'athletes/' . $id . '/segments/starred'; // ...wrong in Strava documentation } - - $parameters = array( + $parameters['query'] = [ 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function updateAthlete($city, $state, $country, $sex, $weight) { - $path = '/athlete'; - $parameters = array( + $path = 'athlete'; + $parameters['query'] = [ 'city' => $city, 'state' => $state, 'country' => $country, 'sex' => $sex, 'weight' => $weight, - ); - $result = $this->adapter->put($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('PUT', $path, $parameters); } public function getActivityFollowing($before = null, $page = null, $per_page = null) { - $path = '/activities/following'; - $parameters = array( + $path = 'activities/following'; + $parameters['query'] = [ 'before' => $before, 'page' => $page, - 'per_page' => $per_page - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'per_page' => $per_page, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } - + public function getActivity($id, $include_all_efforts = null) { - $path = '/activities/' . $id; - $parameters = array( + $path = 'activities/' . $id; + $parameters['query'] = [ 'include_all_efforts' => $include_all_efforts, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getActivityComments($id, $markdown = null, $page = null, $per_page = null) { - $path = '/activities/' . $id . '/comments'; - $parameters = array( + $path = 'activities/' . $id . '/comments'; + $parameters['query'] = [ 'markdown' => $markdown, 'page' => $page, - 'per_page' => $per_page - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'per_page' => $per_page, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getActivityKudos($id, $page = null, $per_page = null) { - $path = '/activities/' . $id . '/kudos'; - $parameters = array( + $path = 'activities/' . $id . '/kudos'; + $parameters['query'] = [ 'page' => $page, - 'per_page' => $per_page - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'per_page' => $per_page, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getActivityPhotos($id, $size = 2048, $photo_sources = 'true') { - $path = '/activities/' . $id . '/photos'; - $parameters = array( + $path = 'activities/' . $id . '/photos'; + $parameters['query'] = [ 'size' => $size, 'photo_sources' => $photo_sources, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getActivityZones($id) { - $path = '/activities/' . $id . '/zones'; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'activities/' . $id . '/zones'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getActivityLaps($id) { - $path = '/activities/' . $id . '/laps'; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'activities/' . $id . '/laps'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getActivityUploadStatus($id) { - $path = '/uploads/' . $id; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'uploads/' . $id; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function createActivity($name, $type, $start_date_local, $elapsed_time, $description = null, $distance = null, $private = null, $trainer = null) { - $path = '/activities'; - $parameters = array( + $path = 'activities'; + $parameters['query'] = [ 'name' => $name, 'type' => $type, 'start_date_local' => $start_date_local, @@ -271,15 +304,15 @@ public function createActivity($name, $type, $start_date_local, $elapsed_time, $ 'distance' => $distance, 'private' => $private, 'trainer' => $trainer, - ); - $result = $this->adapter->post($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('POST', $path, $parameters); } public function uploadActivity($file, $activity_type = null, $name = null, $description = null, $private = null, $trainer = null, $commute = null, $data_type = null, $external_id = null) { - $path = '/uploads'; - $parameters = array( + $path = 'uploads'; + $parameters['query'] = [ 'activity_type' => $activity_type, 'name' => $name, 'description' => $description, @@ -290,15 +323,15 @@ public function uploadActivity($file, $activity_type = null, $name = null, $desc 'external_id' => $external_id, 'file' => curl_file_create($file), 'file_hack' => '@' . ltrim($file, '@'), - ); - $result = $this->adapter->post($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('POST', $path, $parameters); } public function updateActivity($id, $name = null, $type = null, $private = false, $commute = false, $trainer = false, $gear_id = null, $description = null) { - $path = '/activities/' . $id; - $parameters = array( + $path = 'activities/' . $id; + $parameters['query'] = [ 'name' => $name, 'type' => $type, 'private' => $private, @@ -306,100 +339,100 @@ public function updateActivity($id, $name = null, $type = null, $private = false 'trainer' => $trainer, 'gear_id' => $gear_id, 'description' => $description, - ); - $result = $this->adapter->put($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('PUT', $path, $parameters); } public function deleteActivity($id) { - $path = '/activities/' . $id; - $result = $this->adapter->delete($path, $this->getHeaders()); - return $this->format($result); + $path = 'activities/' . $id; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('DELETE', $path, $parameters); } public function getGear($id) { - $path = '/gear/' . $id; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'gear/' . $id; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getClub($id) { - $path = '/clubs/' . $id; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'clubs/' . $id; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getClubMembers($id, $page = null, $per_page = null) { - $path = '/clubs/' . $id . '/members'; - $parameters = array( + $path = 'clubs/' . $id . '/members'; + $parameters['query'] = [ 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getClubActivities($id, $page = null, $per_page = null) { - $path = '/clubs/' . $id . '/activities'; - $parameters = array( + $path = 'clubs/' . $id . '/activities'; + $parameters['query'] = [ 'page' => $page, 'per_page' => $per_page, - ); - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getClubAnnouncements($id) { - $path = '/clubs/' . $id . '/announcements'; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'clubs/' . $id . '/announcements'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getClubGroupEvents($id) { - $path = '/clubs/' . $id . '/group_events'; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'clubs/' . $id . '/group_events'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function joinClub($id) { - $path = '/clubs/' . $id . '/join'; - $result = $this->adapter->post($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'clubs/' . $id . '/join'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('POST', $path, $parameters); } public function leaveClub($id) { - $path = '/clubs/' . $id . '/leave'; - $result = $this->adapter->post($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'clubs/' . $id . '/leave'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('POST', $path, $parameters); } public function getRoute($id) { - $path = '/routes/' . $id; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'routes/' . $id; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getSegment($id) { - $path = '/segments/' . $id; - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'segments/' . $id; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } public function getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $context_entries = null, $page = null, $per_page = null) { - $path = '/segments/' . $id . '/leaderboard'; - $parameters = array( + $path = 'segments/' . $id . '/leaderboard'; + $parameters['query'] = [ 'gender' => $gender, 'age_group' => $age_group, 'weight_class' => $weight_class, @@ -408,92 +441,77 @@ public function getSegmentLeaderboard($id, $gender = null, $age_group = null, $w 'date_range' => $date_range, 'context_entries' => $context_entries, 'page' => $page, - 'per_page' => $per_page - ); - - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'per_page' => $per_page, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null) { - $path = '/segments/explore'; - $parameters = array( + $path = 'segments/explore'; + $parameters['query'] = [ 'bounds' => $bounds, 'activity_type' => $activity_type, 'min_cat' => $min_cat, - 'max_cat' => $max_cat - ); - - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'max_cat' => $max_cat, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null) { - $path = '/segments/' . $id . '/all_efforts'; - $parameters = array( + $path = 'segments/' . $id . '/all_efforts'; + $parameters['query'] = [ 'athlete_id' => $athlete_id, 'start_date_local' => $start_date_local, 'end_date_local' => $end_date_local, 'page' => $page, - 'per_page' => $per_page - ); - - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'per_page' => $per_page, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance') { - $path = '/activities/' . $id . '/streams/' . $types; - $parameters = array( + $path = 'activities/' . $id . '/streams/' . $types; + $parameters['query'] = [ 'resolution' => $resolution, - 'series_type' => $series_type - ); - - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'series_type' => $series_type, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance') { - $path = '/segment_efforts/' . $id . '/streams/' . $types; - $parameters = array( + $path = 'segment_efforts/' . $id . '/streams/' . $types; + $parameters['query'] = [ 'resolution' => $resolution, - 'series_type' => $series_type - ); - - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'series_type' => $series_type, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance') { - $path = '/segments/' . $id . '/streams/' . $types; - $parameters = array( + $path = 'segments/' . $id . '/streams/' . $types; + $parameters['query'] = [ 'resolution' => $resolution, - 'series_type' => $series_type - ); - - $result = $this->adapter->get($path, $parameters, $this->getHeaders()); - return $this->format($result); + 'series_type' => $series_type, + 'access_token' => $this->getToken(), + ]; + return $this->getResponse('GET', $path, $parameters); } public function getStreamsRoute($id) { - $path = '/routes/' . $id . '/streams'; - - $result = $this->adapter->get($path, array(), $this->getHeaders()); - return $this->format($result); + $path = 'routes/' . $id . '/streams'; + $parameters['query'] = ['access_token' => $this->getToken()]; + return $this->getResponse('GET', $path, $parameters); } - /** - * Convert the JSON output to an array - * @param string $result - */ - private function format($result) - { - return json_decode($result, true); - } } diff --git a/tests/Strava/API/Service/RESTTest.php b/tests/Strava/API/Service/RESTTest.php index d5ccfe9..1e73320 100644 --- a/tests/Strava/API/Service/RESTTest.php +++ b/tests/Strava/API/Service/RESTTest.php @@ -9,190 +9,190 @@ */ class RESTTest extends PHPUnit_Framework_TestCase { - private function getPestMock() + private function getRestMock() { - $pestMock = $this->getMockBuilder('Pest') + $restMock = $this->getMockBuilder('\GuzzleHttp\Client') ->disableOriginalConstructor() ->getMock(); - return $pestMock; + return $restMock; } public function testGetAthlete() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athlete')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthlete(); $this->assertArrayHasKey('response', $output); } public function testGetAthleteWithId() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athletes/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthlete(1234); $this->assertArrayHasKey('response', $output); } public function testGetStats() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athletes/1234/stats')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteStats(1234); $this->assertArrayHasKey('response', $output); } public function testGetRoutes() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athletes/1234/routes')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteRoutes(1234); $this->assertArrayHasKey('response', $output); } public function testGetAthleteClubs() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athlete/clubs')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteClubs(); $this->assertArrayHasKey('response', $output); } public function testGetAthleteActivities() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athlete/activities')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteActivities(); $this->assertArrayHasKey('response', $output); } public function testGetAthleteFriends() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athlete/friends')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteFriends(); $this->assertArrayHasKey('response', $output); } public function testGetAthleteFriendsWithId() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athletes/1234/friends')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteFriends(1234); $this->assertArrayHasKey('response', $output); } public function testGetAthleteFollowers() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athlete/followers')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteFollowers(); $this->assertArrayHasKey('response', $output); } public function testGetAthleteFollowersWithId() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athletes/1234/followers')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteFollowers(1234); $this->assertArrayHasKey('response', $output); } public function testGetAthleteBothFollowing() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athletes/1234/both-following')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteBothFollowing(1234); $this->assertArrayHasKey('response', $output); } public function testGetAthleteKOM() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athletes/1234/koms')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteKom(1234); $this->assertArrayHasKey('response', $output); } public function testGetAthleteZones() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athlete/zones')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteZones(); $this->assertArrayHasKey('response', $output); } public function testGetAthleteStarredSegments() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/segments/starred')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteStarredSegments(); $this->assertArrayHasKey('response', $output); } public function testGetAthleteStarredSegmentsWithId() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/athletes/1234/segments/starred')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getAthleteStarredSegments(1234); $this->assertArrayHasKey('response', $output); } @@ -207,348 +207,348 @@ public function testUpdateAthlete() 'weight' => 83.00, ); - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('put') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('put') ->with($this->equalTo('/athlete'), $this->equalTo($parameters)) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->updateAthlete('Xyz', 'ABC', 'The Netherlands', 'M', 83.00); $this->assertArrayHasKey('response', $output); } public function testGetActivity() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/activities/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getActivity(1234); $this->assertArrayHasKey('response', $output); } public function testGetActivityComments() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/activities/1234/comments')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getActivityComments(1234); $this->assertArrayHasKey('response', $output); } public function testGetActivityKudos() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/activities/1234/kudos')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getActivityKudos(1234); $this->assertArrayHasKey('response', $output); } public function testGetActivityPhotos() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/activities/1234/photos')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getActivityPhotos(1234); $this->assertArrayHasKey('response', $output); } public function testGetActivityZones() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/activities/1234/zones')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getActivityZones(1234); $this->assertArrayHasKey('response', $output); } public function testGetActivityLaps() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/activities/1234/laps')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getActivityLaps(1234); $this->assertArrayHasKey('response', $output); } public function testGetActivityUploadStatus() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/uploads/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getActivityUploadStatus(1234); $this->assertArrayHasKey('response', $output); } public function testCreateActivity() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('post') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('post') ->with($this->equalTo('/activities')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->createActivity('test', 'test', '20130101', 100); $this->assertArrayHasKey('response', $output); } public function testUploadActivity() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('post') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('post') ->with($this->equalTo('/uploads')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->uploadActivity('file'); $this->assertArrayHasKey('response', $output); } public function testUpdateActivity() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('put') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('put') ->with($this->equalTo('/activities/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->updateActivity(1234, 'test'); $this->assertArrayHasKey('response', $output); } public function testDeleteActivity() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('delete') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('delete') ->with($this->equalTo('/activities/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->deleteActivity(1234); $this->assertArrayHasKey('response', $output); } public function testGetGear() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/gear/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getGear(1234); $this->assertArrayHasKey('response', $output); } public function testGetClub() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/clubs/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getClub(1234); $this->assertArrayHasKey('response', $output); } public function testGetClubMembers() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/clubs/1234/members')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getClubMembers(1234); $this->assertArrayHasKey('response', $output); } public function testGetClubActivities() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/clubs/1234/activities')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getClubActivities(1234); $this->assertArrayHasKey('response', $output); } public function testGetClubAnnouncements() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/clubs/1234/announcements')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getClubAnnouncements(1234); $this->assertArrayHasKey('response', $output); } public function testGetClubGroupEvents() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/clubs/1234/group_events')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getClubGroupEvents(1234); $this->assertArrayHasKey('response', $output); } public function testJoinClub() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('post') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('post') ->with($this->equalTo('/clubs/1234/join')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->joinClub(1234); $this->assertArrayHasKey('response', $output); } public function testLeaveClub() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('post') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('post') ->with($this->equalTo('/clubs/1234/leave')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->leaveClub(1234); $this->assertArrayHasKey('response', $output); } public function testGetRoute() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/routes/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getRoute(1234); $this->assertArrayHasKey('response', $output); } public function testGetSegment() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/segments/1234')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getSegment(1234); $this->assertArrayHasKey('response', $output); } public function testGetSegmentLeaderboard() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/segments/1234/leaderboard')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getSegmentLeaderboard(1234); $this->assertArrayHasKey('response', $output); } public function testGetSegmentExplorer() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/segments/explore')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getSegmentExplorer('37.821362,-122.505373,37.842038,-122.465977'); $this->assertArrayHasKey('response', $output); } public function testGetSegmentEffort() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/segments/1234/all_efforts')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getSegmentEffort(1234); $this->assertArrayHasKey('response', $output); } public function testGetStreamsActivity() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/activities/1234/streams/latlng')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getStreamsActivity(1234, 'latlng'); $this->assertArrayHasKey('response', $output); } public function testGetStreamsEffort() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/segment_efforts/1234/streams/latlng')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getStreamsEffort(1234, 'latlng'); $this->assertArrayHasKey('response', $output); } public function testGetStreamsSegment() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/segments/1234/streams/latlng')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getStreamsSegment(1234, 'latlng'); $this->assertArrayHasKey('response', $output); } public function testGetStreamsRoute() { - $pestMock = $this->getPestMock(); - $pestMock->expects($this->once())->method('get') + $restMock = $this->getRestMock(); + $restMock->expects($this->once())->method('get') ->with($this->equalTo('/routes/1234/streams')) ->will($this->returnValue('{"response": 1}')); - $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $service = new Strava\API\Service\REST('TOKEN', $restMock); $output = $service->getStreamsRoute(1234); $this->assertArrayHasKey('response', $output); }