Skip to content

Commit

Permalink
Added getAthleteRoutes and getRoute #30
Browse files Browse the repository at this point in the history
  • Loading branch information
basvandorst committed Oct 21, 2017
1 parent fec96a5 commit 082b8a2
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ print_r($athlete);
$client->getAthlete($id = null);
$client->getAthleteStats($id);
$client->getAthleteClubs();
$client->getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null);
$client->getAthleteActivities($before = null, $after = null, $page = null, $per_page = null);
$client->getAthleteFriends($id = null, $page = null, $per_page = null);
$client->getAthleteFollowers($id = null, $page = null, $per_page = null);
Expand All @@ -185,13 +186,15 @@ $client->getGear($id);
$client->getClub($id);
$client->getClubMembers($id, $page = null, $per_page = null);
$client->getClubActivities($id, $page = null, $per_page = null);
$client->getRoute($id);
$client->getSegment($id);
$client->getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $page = null, $per_page = null);
$client->getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null);
$client->getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null);
$client->getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance');
$client->getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance');
$client->getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance');
$client->getStreamsRoute($id);
```

## UML diagrams
Expand Down
23 changes: 20 additions & 3 deletions src/Strava/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public function getAthleteStats($id)
/**
* Retrieve athlete routes
*
* @link https://strava.github.io/api/v3/athlete/#stats
* @link https://strava.github.io/api/v3/routes/#list
* @param int $id
* @return array
* @throws ClientException
*/
public function getAthleteRoutes($id)
public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null)
{
try {
return $this->service->getAthleteRoutes($id);
return $this->service->getAthleteRoutes($id, $type, $after, $page, $per_page);
} catch (ServiceException $e) {
throw new ClientException('[SERVICE] ' . $e->getMessage());
}
Expand Down Expand Up @@ -634,6 +634,23 @@ public function leaveClub($id)
}
}

/**
* Get route details
*
* @link https://strava.github.io/api/v3/routes/#list
* @param int $id
* @return array
* @throws Exception
*/
public function getRoute($id)
{
try {
return $this->service->getRoute($id);
} catch (ServiceException $e) {
throw new ClientException('[SERVICE] ' . $e->getMessage());
}
}

/**
* Retrieve a segment
*
Expand Down
20 changes: 20 additions & 0 deletions src/Strava/API/Service/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ public function getAthleteStats($id)
return $this->format($result);
}

public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null)
{
$path = '/athletes/' . $id . '/routes';
$parameters = array(
'type' => $type,
'after' => $after,
'page' => $page,
'per_page' => $per_page,
);
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getAthleteClubs()
{
$path = '/athlete/clubs';
Expand Down Expand Up @@ -369,6 +382,13 @@ public function leaveClub($id)
return $this->format($result);
}

public function getRoute($id)
{
$path = '/routes/' . $id;
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function getSegment($id)
{
$path = '/segments/' . $id;
Expand Down
14 changes: 14 additions & 0 deletions src/Strava/API/Service/ServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public function getAthlete($id = null);
*/
public function getAthleteStats($id);

/**
* @param integer $id
* @param string $type
* @param integer $after
* @param integer $page
* @param integer $per_page
*/
public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null);

public function getAthleteClubs();

/**
Expand Down Expand Up @@ -214,6 +223,11 @@ public function joinClub($id);
*/
public function leaveClub($id);

/**
* @param integer $id
*/
public function getRoute($id);

/**
* @param integer $id
*/
Expand Down
14 changes: 12 additions & 2 deletions src/Strava/API/Service/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/
class Stub implements ServiceInterface
{


public function getAthlete($id = null)
{
$json = '{ "id": 227615, "resource_state": 2, "firstname": "John", "lastname": "Applestrava", "profile_medium": "http://pics.com/227615/medium.jpg", "profile": "http://pics.com/227615/large.jpg", "city": "San Francisco", "state": "CA", "country": "United States", "sex": "M", "friend": null, "follower": "accepted", "premium": true, "created_at": "2011-03-19T21:59:57Z", "updated_at": "2013-09-05T16:46:54Z", "approve_followers": false }';
Expand All @@ -23,6 +21,12 @@ public function getAthleteStats($id)
return $this->format($json);
}

public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null)
{
$json = '[{"athlete":{"id":19,"resource_state":2},"id":743064,"resource_state":2,"description":"","distance":17781.6,"elevation_gain":207.8}]';
return $this->format($json);
}

public function getAthleteClubs()
{
$json = '[ { "id": 1, "resource_state": 2, "name": "Team Strava Cycling", "profile_medium": "http://pics.com/clubs/1/medium.jpg", "profile": "http://pics.com/clubs/1/large.jpg" } ]';
Expand Down Expand Up @@ -197,6 +201,12 @@ public function leaveClub($id)
return $this->format($json);
}

public function getRoute($id)
{
$json = '{"response": 1}';
return $this->format($json);
}

public function getSegment($id)
{
$json = '{"response": 1}';
Expand Down
36 changes: 36 additions & 0 deletions tests/Strava/API/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ public function testGetAthleteStats()
$this->assertEquals('output', $output);
}

public function testGetAthleteRoutes()
{
$serviceMock = $this->getServiceMock();
$serviceMock->expects($this->once())->method('getAthleteRoutes')
->will($this->returnValue('output'));

$client = new Strava\API\Client($serviceMock);
$output = $client->getAthleteRoutes(1234);

$this->assertEquals('output', $output);
}

public function testGetAthleteClubs()
{
$serviceMock = $this->getServiceMock();
Expand Down Expand Up @@ -727,6 +739,30 @@ public function testLeaveClubException()
$output = $client->leaveClub(1234);
}

public function testGetRoute()
{
$serviceMock = $this->getServiceMock();
$serviceMock->expects($this->once())->method('getRoute')
->will($this->returnValue('output'));

$client = new Strava\API\Client($serviceMock);
$output = $client->getRoute(1234);

$this->assertEquals('output', $output);
}

public function testGetRouteException()
{
$this->setExpectedException('Strava\API\Exception');

$serviceMock = $this->getServiceMock();
$serviceMock->expects($this->once())->method('getRoute')
->will($this->throwException(new ServiceException));

$client = new Strava\API\Client($serviceMock);
$output = $client->getRoute(1234);
}

public function testGetSegment()
{
$serviceMock = $this->getServiceMock();
Expand Down
24 changes: 24 additions & 0 deletions tests/Strava/API/Service/RESTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ public function testGetStats()
$this->assertArrayHasKey('response', $output);
}

public function testGetRoutes()
{
$pestMock = $this->getPestMock();
$pestMock->expects($this->once())->method('get')
->with($this->equalTo('/athletes/1234/routes'))
->will($this->returnValue('{"response": 1}'));

$service = new Strava\API\Service\REST('TOKEN', $pestMock);
$output = $service->getAthleteRoutes(1234);
$this->assertArrayHasKey('response', $output);
}

public function testGetAthleteClubs()
{
$pestMock = $this->getPestMock();
Expand Down Expand Up @@ -433,6 +445,18 @@ public function testLeaveClub()
$this->assertArrayHasKey('response', $output);
}

public function testGetRoute()
{
$pestMock = $this->getPestMock();
$pestMock->expects($this->once())->method('get')
->with($this->equalTo('/routes/1234'))
->will($this->returnValue('{"response": 1}'));

$service = new Strava\API\Service\REST('TOKEN', $pestMock);
$output = $service->getRoute(1234);
$this->assertArrayHasKey('response', $output);
}

public function testGetSegment()
{
$pestMock = $this->getPestMock();
Expand Down
15 changes: 15 additions & 0 deletions tests/Strava/API/Service/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ public function testGetAthleteStats()
$this->assertTrue(is_array($output));
}

public function testGetAthleteRoutes()
{
$service = new Strava\API\Service\Stub();
$output = $service->getAthleteRoutes(1234);
$this->assertTrue(is_array($output));
}

public function testGetAthleteClubs()
{
$service = new Strava\API\Service\Stub();
Expand Down Expand Up @@ -219,6 +226,14 @@ public function testLeaveClub()
$this->assertTrue(is_array($output));
}

public function testGetRoute()
{
$service = new Strava\API\Service\Stub();
$output = $service->getRoute(1234);
$this->assertTrue(is_array($output));
}


public function testGetSegment()
{
$service = new Strava\API\Service\Stub();
Expand Down

0 comments on commit 082b8a2

Please sign in to comment.