From fec96a5fcd107fc2e4b3fb5b4b6f3a1b225b14ab Mon Sep 17 00:00:00 2001 From: Bas van Dorst Date: Sat, 21 Oct 2017 17:21:05 +0200 Subject: [PATCH] Added getStreamsRoute #30 --- src/Strava/API/Client.php | 34 +++++++++++++++++++++ src/Strava/API/Service/REST.php | 8 +++++ src/Strava/API/Service/ServiceInterface.php | 5 +++ src/Strava/API/Service/Stub.php | 6 ++++ tests/Strava/API/ClientTest.php | 24 +++++++++++++++ tests/Strava/API/Service/RESTTest.php | 12 ++++++++ tests/Strava/API/Service/StubTest.php | 7 +++++ 7 files changed, 96 insertions(+) diff --git a/src/Strava/API/Client.php b/src/Strava/API/Client.php index b113177..33e18ff 100644 --- a/src/Strava/API/Client.php +++ b/src/Strava/API/Client.php @@ -68,6 +68,23 @@ public function getAthleteStats($id) } } + /** + * Retrieve athlete routes + * + * @link https://strava.github.io/api/v3/athlete/#stats + * @param int $id + * @return array + * @throws ClientException + */ + public function getAthleteRoutes($id) + { + try { + return $this->service->getAthleteRoutes($id); + } catch (ServiceException $e) { + throw new ClientException('[SERVICE] ' . $e->getMessage()); + } + } + /** * List athlete clubs * @@ -760,4 +777,21 @@ public function getStreamsSegment($id, $types, $resolution = null, $series_type throw new ClientException('[SERVICE] ' . $e->getMessage()); } } + + /** + * Retrieve route streams + * + * @link https://strava.github.io/api/v3/streams/#routes + * @param int $id + * @return array + * @throws Exception + */ + public function getStreamsRoute($id) + { + try { + return $this->service->getStreamsRoute($id); + } catch (ServiceException $e) { + throw new ClientException('[SERVICE] ' . $e->getMessage()); + } + } } diff --git a/src/Strava/API/Service/REST.php b/src/Strava/API/Service/REST.php index 1a43b5f..de7ddbc 100644 --- a/src/Strava/API/Service/REST.php +++ b/src/Strava/API/Service/REST.php @@ -460,6 +460,14 @@ public function getStreamsSegment($id, $types, $resolution = null, $series_type return $this->format($result); } + public function getStreamsRoute($id) + { + $path = '/routes/' . $id . '/streams/'; + + $result = $this->adapter->get($path, array(), $this->getHeaders()); + return $this->format($result); + } + /** * Convert the JSON output to an array * @param string $result diff --git a/src/Strava/API/Service/ServiceInterface.php b/src/Strava/API/Service/ServiceInterface.php index e56c459..ec1ed79 100644 --- a/src/Strava/API/Service/ServiceInterface.php +++ b/src/Strava/API/Service/ServiceInterface.php @@ -266,4 +266,9 @@ public function getStreamsEffort($id, $types, $resolution = null, $series_type = * @param string $types */ public function getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance'); + + /** + * @param integer $id + */ + public function getStreamsRoute($id); } diff --git a/src/Strava/API/Service/Stub.php b/src/Strava/API/Service/Stub.php index 1db3294..3d4ba3d 100644 --- a/src/Strava/API/Service/Stub.php +++ b/src/Strava/API/Service/Stub.php @@ -239,6 +239,12 @@ public function getStreamsSegment($id, $types, $resolution = null, $series_type return $this->format($json); } + public function getStreamsRoute($id) + { + $json = '{"response": 1}'; + return $this->format($json); + } + /** * @param string $result */ diff --git a/tests/Strava/API/ClientTest.php b/tests/Strava/API/ClientTest.php index 95bf75d..c80e617 100644 --- a/tests/Strava/API/ClientTest.php +++ b/tests/Strava/API/ClientTest.php @@ -895,4 +895,28 @@ public function testGetStreamsSegmentException() $output = $client->getStreamsSegment(1234, 'abc'); } + public function testGetStreamsRoute() + { + $serviceMock = $this->getServiceMock(); + $serviceMock->expects($this->once())->method('getStreamsRoute') + ->will($this->returnValue('output')); + + $client = new Strava\API\Client($serviceMock); + $output = $client->getStreamsRoute(1234); + + $this->assertEquals('output', $output); + } + + public function testGetStreamsRouteException() + { + $this->setExpectedException('Strava\API\Exception'); + + $serviceMock = $this->getServiceMock(); + $serviceMock->expects($this->once())->method('getStreamsRoute') + ->will($this->throwException(new ServiceException)); + + $client = new Strava\API\Client($serviceMock); + $output = $client->getStreamsRoute(1234); + } + } diff --git a/tests/Strava/API/Service/RESTTest.php b/tests/Strava/API/Service/RESTTest.php index b579bcf..ad61193 100644 --- a/tests/Strava/API/Service/RESTTest.php +++ b/tests/Strava/API/Service/RESTTest.php @@ -516,4 +516,16 @@ public function testGetStreamsSegment() $output = $service->getStreamsSegment(1234, 'latlng'); $this->assertArrayHasKey('response', $output); } + + public function testGetStreamsRoute() + { + $pestMock = $this->getPestMock(); + $pestMock->expects($this->once())->method('get') + ->with($this->equalTo('/routes/1234/streams/')) + ->will($this->returnValue('{"response": 1}')); + + $service = new Strava\API\Service\REST('TOKEN', $pestMock); + $output = $service->getStreamsRoute(1234); + $this->assertArrayHasKey('response', $output); + } } diff --git a/tests/Strava/API/Service/StubTest.php b/tests/Strava/API/Service/StubTest.php index ef13ab8..5c850c8 100644 --- a/tests/Strava/API/Service/StubTest.php +++ b/tests/Strava/API/Service/StubTest.php @@ -267,4 +267,11 @@ public function testGetStreamsSegment() $output = $service->getStreamsSegment(1234, 'abc'); $this->assertTrue(is_array($output)); } + + public function testGetStreamsRoute() + { + $service = new Strava\API\Service\Stub(); + $output = $service->getStreamsRoute(1234); + $this->assertTrue(is_array($output)); + } }