Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vredeling committed Jun 16, 2020
2 parents 70a1d4a + 925f034 commit 72fb83a
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Use composer to install this StravaPHP package.
```
{
"require": {
"basvandorst/stravaphp": "1.3.1"
"basvandorst/stravaphp": "1.4.0"
}
}
```
Expand Down Expand Up @@ -195,6 +195,8 @@ $client->getClub($id);
$client->getClubMembers($id, $page = null, $per_page = null);
$client->getClubActivities($id, $page = null, $per_page = null);
$client->getRoute($id);
$client->getRouteAsGPX($id);
$client->getRouteAsTCX($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);
Expand Down
34 changes: 34 additions & 0 deletions src/Strava/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,40 @@ public function getRoute($id)
}
}

/**
* Get route as GPX.
*
* @link https://developers.strava.com/docs/reference/#api-Routes-getRouteAsGPX
* @param int $id
* @return string
* @throws Exception
*/
public function getRouteAsGPX($id)
{
try {
return $this->service->getRouteAsGPX($id);
} catch (ServerException $e) {
throw new ClientException('[SERVICE] ' . $e->getMessage());
}
}

/**
* Get route as TCX.
*
* @link https://developers.strava.com/docs/reference/#api-Routes-getRouteAsTCX
* @param int $id
* @return string
* @throws Exception
*/
public function getRouteAsTCX($id)
{
try {
return $this->service->getRouteAsTCX($id);
} catch (ServerException $e) {
throw new ClientException('[SERVICE] ' . $e->getMessage());
}
}

/**
* Retrieve a segment
*
Expand Down
16 changes: 15 additions & 1 deletion src/Strava/API/Service/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;


/**
* Strava REST Service
*
Expand Down Expand Up @@ -56,6 +55,7 @@ private function getToken()
private function getResult($response)
{
$status = $response->getStatusCode();

if ($status == 200 || $status == 201) {
return json_decode($response->getBody(), JSON_PRETTY_PRINT);
} else {
Expand Down Expand Up @@ -416,6 +416,20 @@ public function getRoute($id)
return $this->getResponse('GET', $path, $parameters);
}

public function getRouteAsGPX($id)
{
$path = 'routes/' . $id . '/export_gpx';
$parameters['query'] = ['access_token' => $this->getToken()];
return $this->getResponse('GET', $path, $parameters);
}

public function getRouteAsTCX($id)
{
$path = 'routes/' . $id . '/export_tcx';
$parameters['query'] = ['access_token' => $this->getToken()];
return $this->getResponse('GET', $path, $parameters);
}

public function getSegment($id)
{
$path = 'segments/' . $id;
Expand Down
12 changes: 11 additions & 1 deletion src/Strava/API/Service/ServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use GuzzleHttp\Exception\ClientException;

/**
* Service interace.
* Service interface.
* Just to make sure we can trust the method signatures of all the
* service classes.
*
Expand Down Expand Up @@ -230,6 +230,16 @@ public function leaveClub($id);
*/
public function getRoute($id);

/**
* @param $id
*/
public function getRouteAsGPX($id);

/**
* @param $id
*/
public function getRouteAsTCX($id);

/**
* @param int $id
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Strava/API/Service/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ public function getRoute($id)
$json = '{"response": 1}';
return $this->format($json);
}

public function getRouteAsGPX($id)
{
$gpx = '<?xml version="1.0" encoding="UTF-8"?><gpx creator="StravaGPX"/>';
return $gpx;
}

public function getRouteAsTCX($id)
{
$tcx = '<?xml version="1.0" encoding="UTF-8"?><TrainingCenterDatabase/>';
return $tcx;
}

public function getSegment($id)
{
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 @@ -499,6 +499,30 @@ public function testGetRoute()
$this->assertArrayHasKey('response', $output);
}

public function testGetRouteAsGPX()
{
$restMock = $this->getRestMock();
$restMock->expects($this->once())->method('get')
->with($this->equalTo('routes/1234/export_gpx'))
->will($this->returnValue('<?xml version="1.0" encoding="UTF-8"?><gpx creator="StravaGPX"/>'));

$service = new \Strava\API\Service\REST('TOKEN', $restMock);
$output = $service->getRouteAsGPX(1234);
$this->assertInternalType('string', $output);
}

public function testGetRouteAsTCX()
{
$restMock = $this->getRestMock();
$restMock->expects($this->once())->method('get')
->with($this->equalTo('routes/1234/export_tcx'))
->will($this->returnValue('<?xml version="1.0" encoding="UTF-8"?><TrainingCenterDatabase/>'));

$service = new \Strava\API\Service\REST('TOKEN', $restMock);
$output = $service->getRouteAsTCX(1234);
$this->assertInternalType('string', $output);
}

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

public function testGetRouteAsGPX()
{
$service = new Strava\API\Service\Stub();
$output = $service->getRouteAsGPX(1234);
$this->assertTrue(is_string($output));
}

public function testGetRouteAsTCX()
{
$service = new Strava\API\Service\Stub();
$output = $service->getRouteAsTCX(1234);
$this->assertTrue(is_string($output));
}

public function testGetSegment()
{
Expand Down

0 comments on commit 72fb83a

Please sign in to comment.