Skip to content

Commit 082b8a2

Browse files
committed
Added getAthleteRoutes and getRoute #30
1 parent fec96a5 commit 082b8a2

File tree

8 files changed

+144
-5
lines changed

8 files changed

+144
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ print_r($athlete);
161161
$client->getAthlete($id = null);
162162
$client->getAthleteStats($id);
163163
$client->getAthleteClubs();
164+
$client->getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null);
164165
$client->getAthleteActivities($before = null, $after = null, $page = null, $per_page = null);
165166
$client->getAthleteFriends($id = null, $page = null, $per_page = null);
166167
$client->getAthleteFollowers($id = null, $page = null, $per_page = null);
@@ -185,13 +186,15 @@ $client->getGear($id);
185186
$client->getClub($id);
186187
$client->getClubMembers($id, $page = null, $per_page = null);
187188
$client->getClubActivities($id, $page = null, $per_page = null);
189+
$client->getRoute($id);
188190
$client->getSegment($id);
189191
$client->getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $page = null, $per_page = null);
190192
$client->getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null);
191193
$client->getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null);
192194
$client->getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance');
193195
$client->getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance');
194196
$client->getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance');
197+
$client->getStreamsRoute($id);
195198
```
196199

197200
## UML diagrams

src/Strava/API/Client.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ public function getAthleteStats($id)
7171
/**
7272
* Retrieve athlete routes
7373
*
74-
* @link https://strava.github.io/api/v3/athlete/#stats
74+
* @link https://strava.github.io/api/v3/routes/#list
7575
* @param int $id
7676
* @return array
7777
* @throws ClientException
7878
*/
79-
public function getAthleteRoutes($id)
79+
public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null)
8080
{
8181
try {
82-
return $this->service->getAthleteRoutes($id);
82+
return $this->service->getAthleteRoutes($id, $type, $after, $page, $per_page);
8383
} catch (ServiceException $e) {
8484
throw new ClientException('[SERVICE] ' . $e->getMessage());
8585
}
@@ -634,6 +634,23 @@ public function leaveClub($id)
634634
}
635635
}
636636

637+
/**
638+
* Get route details
639+
*
640+
* @link https://strava.github.io/api/v3/routes/#list
641+
* @param int $id
642+
* @return array
643+
* @throws Exception
644+
*/
645+
public function getRoute($id)
646+
{
647+
try {
648+
return $this->service->getRoute($id);
649+
} catch (ServiceException $e) {
650+
throw new ClientException('[SERVICE] ' . $e->getMessage());
651+
}
652+
}
653+
637654
/**
638655
* Retrieve a segment
639656
*

src/Strava/API/Service/REST.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ public function getAthleteStats($id)
5858
return $this->format($result);
5959
}
6060

61+
public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null)
62+
{
63+
$path = '/athletes/' . $id . '/routes';
64+
$parameters = array(
65+
'type' => $type,
66+
'after' => $after,
67+
'page' => $page,
68+
'per_page' => $per_page,
69+
);
70+
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
71+
return $this->format($result);
72+
}
73+
6174
public function getAthleteClubs()
6275
{
6376
$path = '/athlete/clubs';
@@ -369,6 +382,13 @@ public function leaveClub($id)
369382
return $this->format($result);
370383
}
371384

385+
public function getRoute($id)
386+
{
387+
$path = '/routes/' . $id;
388+
$result = $this->adapter->get($path, array(), $this->getHeaders());
389+
return $this->format($result);
390+
}
391+
372392
public function getSegment($id)
373393
{
374394
$path = '/segments/' . $id;

src/Strava/API/Service/ServiceInterface.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ public function getAthlete($id = null);
2828
*/
2929
public function getAthleteStats($id);
3030

31+
/**
32+
* @param integer $id
33+
* @param string $type
34+
* @param integer $after
35+
* @param integer $page
36+
* @param integer $per_page
37+
*/
38+
public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null);
39+
3140
public function getAthleteClubs();
3241

3342
/**
@@ -214,6 +223,11 @@ public function joinClub($id);
214223
*/
215224
public function leaveClub($id);
216225

226+
/**
227+
* @param integer $id
228+
*/
229+
public function getRoute($id);
230+
217231
/**
218232
* @param integer $id
219233
*/

src/Strava/API/Service/Stub.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
class Stub implements ServiceInterface
1111
{
12-
13-
1412
public function getAthlete($id = null)
1513
{
1614
$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 }';
@@ -23,6 +21,12 @@ public function getAthleteStats($id)
2321
return $this->format($json);
2422
}
2523

24+
public function getAthleteRoutes($id, $type = null, $after = null, $page = null, $per_page = null)
25+
{
26+
$json = '[{"athlete":{"id":19,"resource_state":2},"id":743064,"resource_state":2,"description":"","distance":17781.6,"elevation_gain":207.8}]';
27+
return $this->format($json);
28+
}
29+
2630
public function getAthleteClubs()
2731
{
2832
$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" } ]';
@@ -197,6 +201,12 @@ public function leaveClub($id)
197201
return $this->format($json);
198202
}
199203

204+
public function getRoute($id)
205+
{
206+
$json = '{"response": 1}';
207+
return $this->format($json);
208+
}
209+
200210
public function getSegment($id)
201211
{
202212
$json = '{"response": 1}';

tests/Strava/API/ClientTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ public function testGetAthleteStats()
5454
$this->assertEquals('output', $output);
5555
}
5656

57+
public function testGetAthleteRoutes()
58+
{
59+
$serviceMock = $this->getServiceMock();
60+
$serviceMock->expects($this->once())->method('getAthleteRoutes')
61+
->will($this->returnValue('output'));
62+
63+
$client = new Strava\API\Client($serviceMock);
64+
$output = $client->getAthleteRoutes(1234);
65+
66+
$this->assertEquals('output', $output);
67+
}
68+
5769
public function testGetAthleteClubs()
5870
{
5971
$serviceMock = $this->getServiceMock();
@@ -727,6 +739,30 @@ public function testLeaveClubException()
727739
$output = $client->leaveClub(1234);
728740
}
729741

742+
public function testGetRoute()
743+
{
744+
$serviceMock = $this->getServiceMock();
745+
$serviceMock->expects($this->once())->method('getRoute')
746+
->will($this->returnValue('output'));
747+
748+
$client = new Strava\API\Client($serviceMock);
749+
$output = $client->getRoute(1234);
750+
751+
$this->assertEquals('output', $output);
752+
}
753+
754+
public function testGetRouteException()
755+
{
756+
$this->setExpectedException('Strava\API\Exception');
757+
758+
$serviceMock = $this->getServiceMock();
759+
$serviceMock->expects($this->once())->method('getRoute')
760+
->will($this->throwException(new ServiceException));
761+
762+
$client = new Strava\API\Client($serviceMock);
763+
$output = $client->getRoute(1234);
764+
}
765+
730766
public function testGetSegment()
731767
{
732768
$serviceMock = $this->getServiceMock();

tests/Strava/API/Service/RESTTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ public function testGetStats()
5353
$this->assertArrayHasKey('response', $output);
5454
}
5555

56+
public function testGetRoutes()
57+
{
58+
$pestMock = $this->getPestMock();
59+
$pestMock->expects($this->once())->method('get')
60+
->with($this->equalTo('/athletes/1234/routes'))
61+
->will($this->returnValue('{"response": 1}'));
62+
63+
$service = new Strava\API\Service\REST('TOKEN', $pestMock);
64+
$output = $service->getAthleteRoutes(1234);
65+
$this->assertArrayHasKey('response', $output);
66+
}
67+
5668
public function testGetAthleteClubs()
5769
{
5870
$pestMock = $this->getPestMock();
@@ -433,6 +445,18 @@ public function testLeaveClub()
433445
$this->assertArrayHasKey('response', $output);
434446
}
435447

448+
public function testGetRoute()
449+
{
450+
$pestMock = $this->getPestMock();
451+
$pestMock->expects($this->once())->method('get')
452+
->with($this->equalTo('/routes/1234'))
453+
->will($this->returnValue('{"response": 1}'));
454+
455+
$service = new Strava\API\Service\REST('TOKEN', $pestMock);
456+
$output = $service->getRoute(1234);
457+
$this->assertArrayHasKey('response', $output);
458+
}
459+
436460
public function testGetSegment()
437461
{
438462
$pestMock = $this->getPestMock();

tests/Strava/API/Service/StubTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public function testGetAthleteStats()
2323
$this->assertTrue(is_array($output));
2424
}
2525

26+
public function testGetAthleteRoutes()
27+
{
28+
$service = new Strava\API\Service\Stub();
29+
$output = $service->getAthleteRoutes(1234);
30+
$this->assertTrue(is_array($output));
31+
}
32+
2633
public function testGetAthleteClubs()
2734
{
2835
$service = new Strava\API\Service\Stub();
@@ -219,6 +226,14 @@ public function testLeaveClub()
219226
$this->assertTrue(is_array($output));
220227
}
221228

229+
public function testGetRoute()
230+
{
231+
$service = new Strava\API\Service\Stub();
232+
$output = $service->getRoute(1234);
233+
$this->assertTrue(is_array($output));
234+
}
235+
236+
222237
public function testGetSegment()
223238
{
224239
$service = new Strava\API\Service\Stub();

0 commit comments

Comments
 (0)