Skip to content

Commit 72fb83a

Browse files
committed
Merge branch 'release/1.4.0'
2 parents 70a1d4a + 925f034 commit 72fb83a

File tree

7 files changed

+112
-3
lines changed

7 files changed

+112
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Use composer to install this StravaPHP package.
2727
```
2828
{
2929
"require": {
30-
"basvandorst/stravaphp": "1.3.1"
30+
"basvandorst/stravaphp": "1.4.0"
3131
}
3232
}
3333
```
@@ -195,6 +195,8 @@ $client->getClub($id);
195195
$client->getClubMembers($id, $page = null, $per_page = null);
196196
$client->getClubActivities($id, $page = null, $per_page = null);
197197
$client->getRoute($id);
198+
$client->getRouteAsGPX($id);
199+
$client->getRouteAsTCX($id);
198200
$client->getSegment($id);
199201
$client->getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $page = null, $per_page = null);
200202
$client->getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null);

src/Strava/API/Client.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,40 @@ public function getRoute($id)
630630
}
631631
}
632632

633+
/**
634+
* Get route as GPX.
635+
*
636+
* @link https://developers.strava.com/docs/reference/#api-Routes-getRouteAsGPX
637+
* @param int $id
638+
* @return string
639+
* @throws Exception
640+
*/
641+
public function getRouteAsGPX($id)
642+
{
643+
try {
644+
return $this->service->getRouteAsGPX($id);
645+
} catch (ServerException $e) {
646+
throw new ClientException('[SERVICE] ' . $e->getMessage());
647+
}
648+
}
649+
650+
/**
651+
* Get route as TCX.
652+
*
653+
* @link https://developers.strava.com/docs/reference/#api-Routes-getRouteAsTCX
654+
* @param int $id
655+
* @return string
656+
* @throws Exception
657+
*/
658+
public function getRouteAsTCX($id)
659+
{
660+
try {
661+
return $this->service->getRouteAsTCX($id);
662+
} catch (ServerException $e) {
663+
throw new ClientException('[SERVICE] ' . $e->getMessage());
664+
}
665+
}
666+
633667
/**
634668
* Retrieve a segment
635669
*

src/Strava/API/Service/REST.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\Psr7\Response;
77

8-
98
/**
109
* Strava REST Service
1110
*
@@ -56,6 +55,7 @@ private function getToken()
5655
private function getResult($response)
5756
{
5857
$status = $response->getStatusCode();
58+
5959
if ($status == 200 || $status == 201) {
6060
return json_decode($response->getBody(), JSON_PRETTY_PRINT);
6161
} else {
@@ -416,6 +416,20 @@ public function getRoute($id)
416416
return $this->getResponse('GET', $path, $parameters);
417417
}
418418

419+
public function getRouteAsGPX($id)
420+
{
421+
$path = 'routes/' . $id . '/export_gpx';
422+
$parameters['query'] = ['access_token' => $this->getToken()];
423+
return $this->getResponse('GET', $path, $parameters);
424+
}
425+
426+
public function getRouteAsTCX($id)
427+
{
428+
$path = 'routes/' . $id . '/export_tcx';
429+
$parameters['query'] = ['access_token' => $this->getToken()];
430+
return $this->getResponse('GET', $path, $parameters);
431+
}
432+
419433
public function getSegment($id)
420434
{
421435
$path = 'segments/' . $id;

src/Strava/API/Service/ServiceInterface.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use GuzzleHttp\Exception\ClientException;
66

77
/**
8-
* Service interace.
8+
* Service interface.
99
* Just to make sure we can trust the method signatures of all the
1010
* service classes.
1111
*
@@ -230,6 +230,16 @@ public function leaveClub($id);
230230
*/
231231
public function getRoute($id);
232232

233+
/**
234+
* @param $id
235+
*/
236+
public function getRouteAsGPX($id);
237+
238+
/**
239+
* @param $id
240+
*/
241+
public function getRouteAsTCX($id);
242+
233243
/**
234244
* @param int $id
235245
*/

src/Strava/API/Service/Stub.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,18 @@ public function getRoute($id)
207207
$json = '{"response": 1}';
208208
return $this->format($json);
209209
}
210+
211+
public function getRouteAsGPX($id)
212+
{
213+
$gpx = '<?xml version="1.0" encoding="UTF-8"?><gpx creator="StravaGPX"/>';
214+
return $gpx;
215+
}
216+
217+
public function getRouteAsTCX($id)
218+
{
219+
$tcx = '<?xml version="1.0" encoding="UTF-8"?><TrainingCenterDatabase/>';
220+
return $tcx;
221+
}
210222

211223
public function getSegment($id)
212224
{

tests/Strava/API/Service/RESTTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,30 @@ public function testGetRoute()
499499
$this->assertArrayHasKey('response', $output);
500500
}
501501

502+
public function testGetRouteAsGPX()
503+
{
504+
$restMock = $this->getRestMock();
505+
$restMock->expects($this->once())->method('get')
506+
->with($this->equalTo('routes/1234/export_gpx'))
507+
->will($this->returnValue('<?xml version="1.0" encoding="UTF-8"?><gpx creator="StravaGPX"/>'));
508+
509+
$service = new \Strava\API\Service\REST('TOKEN', $restMock);
510+
$output = $service->getRouteAsGPX(1234);
511+
$this->assertInternalType('string', $output);
512+
}
513+
514+
public function testGetRouteAsTCX()
515+
{
516+
$restMock = $this->getRestMock();
517+
$restMock->expects($this->once())->method('get')
518+
->with($this->equalTo('routes/1234/export_tcx'))
519+
->will($this->returnValue('<?xml version="1.0" encoding="UTF-8"?><TrainingCenterDatabase/>'));
520+
521+
$service = new \Strava\API\Service\REST('TOKEN', $restMock);
522+
$output = $service->getRouteAsTCX(1234);
523+
$this->assertInternalType('string', $output);
524+
}
525+
502526
public function testGetSegment()
503527
{
504528
$restMock = $this->getRestMock();

tests/Strava/API/Service/StubTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ public function testGetRoute()
233233
$this->assertTrue(is_array($output));
234234
}
235235

236+
public function testGetRouteAsGPX()
237+
{
238+
$service = new Strava\API\Service\Stub();
239+
$output = $service->getRouteAsGPX(1234);
240+
$this->assertTrue(is_string($output));
241+
}
242+
243+
public function testGetRouteAsTCX()
244+
{
245+
$service = new Strava\API\Service\Stub();
246+
$output = $service->getRouteAsTCX(1234);
247+
$this->assertTrue(is_string($output));
248+
}
236249

237250
public function testGetSegment()
238251
{

0 commit comments

Comments
 (0)