Skip to content

Commit

Permalink
Added getAthleteZones
Browse files Browse the repository at this point in the history
  • Loading branch information
basvandorst committed Oct 21, 2017
1 parent 6a30a30 commit 8c02771
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ $client->getAthleteFriends($id = null, $page = null, $per_page = null);
$client->getAthleteFollowers($id = null, $page = null, $per_page = null);
$client->getAthleteBothFollowing($id, $page = null, $per_page = null);
$client->getAthleteKom($id, $page = null, $per_page = null);
$client->getAthleteZones();
$client->getAthleteStarredSegments($id = null, $page = null, $per_page = null);
$client->updateAthlete($city, $state, $country, $sex, $weight);
$client->getActivityFollowing($before = null, $page = null, $per_page = null)
Expand Down
18 changes: 18 additions & 0 deletions src/Strava/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ public function getAthleteKom($id, $page = null, $per_page = null)
}
}

/**
* List athlete zones
*
* @link https://strava.github.io/api/v3/athlete/#zones
* @return array
* @throws Exception
*/
public function getAthleteZones()
{
try {
return $this->service->getAthleteZones();
} catch (ServiceException $e) {
throw new ClientException('[SERVICE] ' . $e->getMessage());
}
}



/**
* List starred segment
*
Expand Down
7 changes: 7 additions & 0 deletions src/Strava/API/Service/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ public function getAthleteKom($id, $page = null, $per_page = null)
return $this->format($result);
}

public function getAthleteZones()
{
$path = '/athlete/zones';
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function getAthleteStarredSegments($id = null, $page = null, $per_page = null)
{
$path = '/segments/starred';
Expand Down
2 changes: 2 additions & 0 deletions src/Strava/API/Service/ServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function getAthleteBothFollowing($id, $page = null, $per_page = null);
*/
public function getAthleteKom($id, $page = null, $per_page = null);

public function getAthleteZones();

/**
* @param integer $id
* @param integer $page
Expand Down
8 changes: 8 additions & 0 deletions src/Strava/API/Service/Stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
class Stub implements ServiceInterface
{


public function getAthlete($id = null)
{
$json = '{ "id": 227615, "resource_state": 2, "firstname": "John", "lastname": "Applestrava", "profile_medium": "http://pics.com/227615/medium.jpg", "profile": "http://pics.com/227615/large.jpg", "city": "San Francisco", "state": "CA", "country": "United States", "sex": "M", "friend": null, "follower": "accepted", "premium": true, "created_at": "2011-03-19T21:59:57Z", "updated_at": "2013-09-05T16:46:54Z", "approve_followers": false }';
Expand Down Expand Up @@ -57,6 +59,12 @@ public function getAthleteKom($id, $page = null, $per_page = null)
return $this->format($json);
}

public function getAthleteZones()
{
$json = '{"heart_rate":{"custom_zones":false,"zones":[{"min":0,"max":115},{"min":115,"max":152},{"min":152,"max":171},{"min":171,"max":190},{"min":190,"max":-1}]},"power":{"zones":[{"min":0,"max":180},{"min":181,"max":246},{"min":247,"max":295},{"min":296,"max":344},{"min":345,"max":393},{"min":394,"max":492},{"min":493,"max":-1}]}}';
return $this->format($json);
}

public function getAthleteStarredSegments($id = null, $page = null, $per_page = null)
{
$json = '{"response": 1}';
Expand Down
25 changes: 25 additions & 0 deletions tests/Strava/API/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,31 @@ public function testGetAthleteKomException()
$output = $client->getAthleteKom(1234);
}


public function testGetAthleteZones()
{
$serviceMock = $this->getServiceMock();
$serviceMock->expects($this->once())->method('getAthleteZones')
->will($this->returnValue('output'));

$client = new Strava\API\Client($serviceMock);
$output = $client->getAthleteZones();

$this->assertEquals('output', $output);
}

public function testGetAthleteZonesException()
{
$this->setExpectedException('Strava\API\Exception');

$serviceMock = $this->getServiceMock();
$serviceMock->expects($this->once())->method('getAthleteZones')
->will($this->throwException(new ServiceException));

$client = new Strava\API\Client($serviceMock);
$output = $client->getAthleteZones();
}

public function testGetAthleteStarredSegments()
{
$serviceMock = $this->getServiceMock();
Expand Down
12 changes: 12 additions & 0 deletions tests/Strava/API/Service/RESTTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@ public function testGetAthleteKOM()
$this->assertArrayHasKey('response', $output);
}

public function testGetAthleteZones()
{
$pestMock = $this->getPestMock();
$pestMock->expects($this->once())->method('get')
->with($this->equalTo('/athlete/zones'))
->will($this->returnValue('{"response": 1}'));

$service = new Strava\API\Service\REST('TOKEN', $pestMock);
$output = $service->getAthleteZones();
$this->assertArrayHasKey('response', $output);
}

public function testGetAthleteStarredSegments()
{
$pestMock = $this->getPestMock();
Expand Down
7 changes: 7 additions & 0 deletions tests/Strava/API/Service/StubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public function testGetAthleteKom()
$this->assertTrue(is_array($output));
}

public function testGetAthleteZones()
{
$service = new Strava\API\Service\Stub();
$output = $service->getAthleteZones();
$this->assertTrue(is_array($output));
}

public function testGetAthleteStarredSegments()
{
$service = new Strava\API\Service\Stub();
Expand Down

0 comments on commit 8c02771

Please sign in to comment.