Skip to content

Commit

Permalink
Added getStreamsRoute #30
Browse files Browse the repository at this point in the history
  • Loading branch information
basvandorst committed Oct 21, 2017
1 parent 8c02771 commit fec96a5
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Strava/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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());
}
}
}
8 changes: 8 additions & 0 deletions src/Strava/API/Service/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Strava/API/Service/ServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions src/Strava/API/Service/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
24 changes: 24 additions & 0 deletions tests/Strava/API/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
12 changes: 12 additions & 0 deletions tests/Strava/API/Service/RESTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 7 additions & 0 deletions tests/Strava/API/Service/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit fec96a5

Please sign in to comment.