Skip to content

Commit fec96a5

Browse files
committed
Added getStreamsRoute #30
1 parent 8c02771 commit fec96a5

File tree

7 files changed

+96
-0
lines changed

7 files changed

+96
-0
lines changed

src/Strava/API/Client.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ public function getAthleteStats($id)
6868
}
6969
}
7070

71+
/**
72+
* Retrieve athlete routes
73+
*
74+
* @link https://strava.github.io/api/v3/athlete/#stats
75+
* @param int $id
76+
* @return array
77+
* @throws ClientException
78+
*/
79+
public function getAthleteRoutes($id)
80+
{
81+
try {
82+
return $this->service->getAthleteRoutes($id);
83+
} catch (ServiceException $e) {
84+
throw new ClientException('[SERVICE] ' . $e->getMessage());
85+
}
86+
}
87+
7188
/**
7289
* List athlete clubs
7390
*
@@ -760,4 +777,21 @@ public function getStreamsSegment($id, $types, $resolution = null, $series_type
760777
throw new ClientException('[SERVICE] ' . $e->getMessage());
761778
}
762779
}
780+
781+
/**
782+
* Retrieve route streams
783+
*
784+
* @link https://strava.github.io/api/v3/streams/#routes
785+
* @param int $id
786+
* @return array
787+
* @throws Exception
788+
*/
789+
public function getStreamsRoute($id)
790+
{
791+
try {
792+
return $this->service->getStreamsRoute($id);
793+
} catch (ServiceException $e) {
794+
throw new ClientException('[SERVICE] ' . $e->getMessage());
795+
}
796+
}
763797
}

src/Strava/API/Service/REST.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,14 @@ public function getStreamsSegment($id, $types, $resolution = null, $series_type
460460
return $this->format($result);
461461
}
462462

463+
public function getStreamsRoute($id)
464+
{
465+
$path = '/routes/' . $id . '/streams/';
466+
467+
$result = $this->adapter->get($path, array(), $this->getHeaders());
468+
return $this->format($result);
469+
}
470+
463471
/**
464472
* Convert the JSON output to an array
465473
* @param string $result

src/Strava/API/Service/ServiceInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,9 @@ public function getStreamsEffort($id, $types, $resolution = null, $series_type =
266266
* @param string $types
267267
*/
268268
public function getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance');
269+
270+
/**
271+
* @param integer $id
272+
*/
273+
public function getStreamsRoute($id);
269274
}

src/Strava/API/Service/Stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ public function getStreamsSegment($id, $types, $resolution = null, $series_type
239239
return $this->format($json);
240240
}
241241

242+
public function getStreamsRoute($id)
243+
{
244+
$json = '{"response": 1}';
245+
return $this->format($json);
246+
}
247+
242248
/**
243249
* @param string $result
244250
*/

tests/Strava/API/ClientTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,4 +895,28 @@ public function testGetStreamsSegmentException()
895895
$output = $client->getStreamsSegment(1234, 'abc');
896896
}
897897

898+
public function testGetStreamsRoute()
899+
{
900+
$serviceMock = $this->getServiceMock();
901+
$serviceMock->expects($this->once())->method('getStreamsRoute')
902+
->will($this->returnValue('output'));
903+
904+
$client = new Strava\API\Client($serviceMock);
905+
$output = $client->getStreamsRoute(1234);
906+
907+
$this->assertEquals('output', $output);
908+
}
909+
910+
public function testGetStreamsRouteException()
911+
{
912+
$this->setExpectedException('Strava\API\Exception');
913+
914+
$serviceMock = $this->getServiceMock();
915+
$serviceMock->expects($this->once())->method('getStreamsRoute')
916+
->will($this->throwException(new ServiceException));
917+
918+
$client = new Strava\API\Client($serviceMock);
919+
$output = $client->getStreamsRoute(1234);
920+
}
921+
898922
}

tests/Strava/API/Service/RESTTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,4 +516,16 @@ public function testGetStreamsSegment()
516516
$output = $service->getStreamsSegment(1234, 'latlng');
517517
$this->assertArrayHasKey('response', $output);
518518
}
519+
520+
public function testGetStreamsRoute()
521+
{
522+
$pestMock = $this->getPestMock();
523+
$pestMock->expects($this->once())->method('get')
524+
->with($this->equalTo('/routes/1234/streams/'))
525+
->will($this->returnValue('{"response": 1}'));
526+
527+
$service = new Strava\API\Service\REST('TOKEN', $pestMock);
528+
$output = $service->getStreamsRoute(1234);
529+
$this->assertArrayHasKey('response', $output);
530+
}
519531
}

tests/Strava/API/Service/StubTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,11 @@ public function testGetStreamsSegment()
267267
$output = $service->getStreamsSegment(1234, 'abc');
268268
$this->assertTrue(is_array($output));
269269
}
270+
271+
public function testGetStreamsRoute()
272+
{
273+
$service = new Strava\API\Service\Stub();
274+
$output = $service->getStreamsRoute(1234);
275+
$this->assertTrue(is_array($output));
276+
}
270277
}

0 commit comments

Comments
 (0)