Skip to content

Commit

Permalink
Merge branch 'fbonzon-photos'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas van Dorst committed Sep 19, 2016
2 parents 73e4617 + 94a1122 commit 5c78257
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -157,7 +157,7 @@ $client->updateAthlete($city, $state, $country, $sex, $weight);
$client->getActivity($id, $include_all_efforts = null);
$client->getActivityComments($id, $markdown = null, $page = null, $per_page = null);
$client->getActivityKudos($id, $page = null, $per_page = null);
$client->getActivityPhotos($id);
$client->getActivityPhotos($id, $size = 2048, $photo_sources = 'true');
$client->getActivityZones($id);
$client->getActivityLaps($id);
$client->getActivityUploadStatus($id);
Expand Down
6 changes: 4 additions & 2 deletions src/Strava/API/Client.php
Expand Up @@ -269,12 +269,14 @@ public function getActivityKudos($id, $page = null, $per_page = null) {
*
* @link http://strava.github.io/api/v3/photos/#list
* @param int $id
* @param int $size In pixels.
* @param string $photo_sources Must be "true".
* @return array
* @throws Exception
*/
public function getActivityPhotos($id) {
public function getActivityPhotos($id, $size = 2048, $photo_sources = 'true') {
try {
return $this->service->getActivityPhotos($id);
return $this->service->getActivityPhotos($id, $size, $photo_sources);
} catch (ServiceException $e) {
throw new ClientException('[SERVICE] '.$e->getMessage());
}
Expand Down
108 changes: 56 additions & 52 deletions src/Strava/API/Service/REST.php
Expand Up @@ -5,39 +5,39 @@

/**
* Strava REST Service
*
*
* @author Bas van Dorst
* @package StravaPHP
*/
class REST implements ServiceInterface {
class REST implements ServiceInterface {
/**
* REST adapter
* @var Pest
*/
protected $adapter;

/**
* Application token
* @var string
*/
private $token = null;

/**
* Inititate this REST servcie with the application token and a instance
* Inititate this REST servcie with the application token and a instance
* of the REST adapter (Pest)
*
*
* @param string $token
* @param Pest $adapter
*/
public function __construct($token, Pest $adapter) {
$this->token = $token;
$this->adapter = $adapter;
}

private function getHeaders() {
return array('Authorization: Bearer '.$this->token);
}

public function getAthlete($id = null) {
$path = '/athlete';
if(isset($id) && $id !== null) {
Expand All @@ -46,7 +46,7 @@ public function getAthlete($id = null) {
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function getAthleteStats($id) {
$path = '/athletes/'.$id.'/stats';
$result = $this->adapter->get($path, array(), $this->getHeaders());
Expand All @@ -58,7 +58,7 @@ public function getAthleteClubs() {
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function getAthleteActivities($before = null, $after = null, $page = null, $per_page = null) {
$path = '/athlete/activities';
$parameters = array(
Expand All @@ -70,72 +70,72 @@ public function getAthleteActivities($before = null, $after = null, $page = null
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getAthleteFriends($id = null, $page = null, $per_page = null) {
public function getAthleteFriends($id = null, $page = null, $per_page = null) {
$path = '/athlete/friends';
if(isset($id) && $id !== null) {
$path = '/athletes/'.$id.'/friends';
}

$parameters = array(
'page' => $page,
'per_page' => $per_page,
);
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getAthleteFollowers($id = null, $page = null, $per_page = null) {
$path = '/athlete/followers';
if(isset($id) && $id !== null) {
$path = '/athletes/'.$id.'/followers';
}

$parameters = array(
'page' => $page,
'per_page' => $per_page,
);
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getAthleteBothFollowing($id, $page = null, $per_page = null) {
$path = '/athletes/'.$id.'/both-following';

$parameters = array(
'page' => $page,
'per_page' => $per_page,
);
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getAthleteKom($id, $page = null, $per_page = null) {
$path = '/athletes/'.$id.'/koms';

$parameters = array(
'page' => $page,
'per_page' => $per_page,
);
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getAthleteStarredSegments($id = null, $page = null, $per_page = null) {
$path = '/segments/starred';
if(isset($id) && $id !== null) {
$path = '/athletes/'.$id.'/segments/starred';
// ...wrong in Strava documentation
}

$parameters = array(
'page' => $page,
'per_page' => $per_page,
);
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function updateAthlete($city, $state, $country, $sex, $weight) {
$path = '/athlete';
$parameters = array(
Expand All @@ -148,7 +148,7 @@ public function updateAthlete($city, $state, $country, $sex, $weight) {
$result = $this->adapter->put($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getActivity($id, $include_all_efforts = null) {
$path = '/activities/'.$id;
$parameters = array(
Expand All @@ -157,7 +157,7 @@ public function getActivity($id, $include_all_efforts = null) {
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getActivityComments($id, $markdown = null, $page = null, $per_page = null) {
$path = '/activities/'.$id.'/comments';
$parameters = array(
Expand All @@ -168,7 +168,7 @@ public function getActivityComments($id, $markdown = null, $page = null, $per_pa
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getActivityKudos($id, $page = null, $per_page = null) {
$path = '/activities/'.$id.'/kudos';
$parameters = array(
Expand All @@ -178,31 +178,35 @@ public function getActivityKudos($id, $page = null, $per_page = null) {
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getActivityPhotos($id) {
public function getActivityPhotos($id, $size = 2048, $photo_sources = 'true') {
$path = '/activities/'.$id.'/photos';
$result = $this->adapter->get($path, array(), $this->getHeaders());
$parameters = array(
'size' => $size,
'photo_sources' => $photo_sources,
);
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

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

public function getActivityLaps($id) {
$path = '/activities/'.$id.'/laps';
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function getActivityUploadStatus($id) {
$path = '/uploads/'.$id;
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function createActivity($name, $type, $start_date_local, $elapsed_time, $description = null, $distance = null) {
$path = '/activities';
$parameters = array(
Expand All @@ -216,7 +220,7 @@ public function createActivity($name, $type, $start_date_local, $elapsed_time, $
$result = $this->adapter->post($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function uploadActivity($file, $activity_type = null, $name = null, $description = null, $private = null, $trainer = null, $data_type = null, $external_id = null) {
$path = '/uploads';
$parameters = array(
Expand All @@ -232,7 +236,7 @@ public function uploadActivity($file, $activity_type = null, $name = null, $desc
$result = $this->adapter->post($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function updateActivity($id, $name = null, $type = null, $private = false, $commute = false, $trainer = false, $gear_id = null, $description = null) {
$path = '/activities/'.$id;
$parameters = array(
Expand All @@ -247,25 +251,25 @@ public function updateActivity($id, $name = null, $type = null, $private = false
$result = $this->adapter->put($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function deleteActivity($id) {
$path = '/activities/'.$id;
$result = $this->adapter->delete($path, array());
return $this->format($result);
}

public function getGear($id) {
$path = '/gear/'.$id;
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function getClub($id) {
$path = '/clubs/'.$id;
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function getClubMembers($id, $page = null, $per_page = null) {
$path = '/clubs/'.$id.'/members';
$parameters = array(
Expand All @@ -275,7 +279,7 @@ public function getClubMembers($id, $page = null, $per_page = null) {
$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getClubActivities($id, $page = null, $per_page = null) {
$path = '/clubs/'.$id.'/activities';
$parameters = array(
Expand Down Expand Up @@ -315,7 +319,7 @@ public function getSegment($id) {
$result = $this->adapter->get($path, array(), $this->getHeaders());
return $this->format($result);
}

public function getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $page = null, $per_page = null) {
$path = '/segments/'.$id.'/leaderboard';
$parameters = array(
Expand All @@ -328,11 +332,11 @@ public function getSegmentLeaderboard($id, $gender = null, $age_group = null, $w
'page' => $page,
'per_page' => $per_page
);

$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null) {
$path = '/segments/explore';
$parameters = array(
Expand All @@ -341,11 +345,11 @@ public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat
'min_cat' => $min_cat,
'max_cat' => $max_cat
);

$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null) {
$path = '/segments/'.$id.'/all_efforts';
$parameters = array(
Expand All @@ -355,44 +359,44 @@ public function getSegmentEffort($id, $athlete_id = null, $start_date_local = nu
'page' => $page,
'per_page' => $per_page
);

$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getStreamsActivity($id, $types, $resolution = 'all', $series_type = 'distance') {
$path = '/activities/'.$id.'/streams/'.$types;
$parameters = array(
'resolution' => $resolution,
'series_type' => $series_type
);

$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getStreamsEffort($id, $types, $resolution = 'all', $series_type = 'distance') {
$path = '/segment_efforts/'.$id.'/streams/'.$types;
$parameters = array(
'resolution' => $resolution,
'series_type' => $series_type
);

$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

public function getStreamsSegment($id, $types, $resolution = 'all', $series_type = 'distance') {
$path = '/segments/'.$id.'/streams/'.$types;
$parameters = array(
'resolution' => $resolution,
'series_type' => $series_type
);

$result = $this->adapter->get($path, $parameters, $this->getHeaders());
return $this->format($result);
}

/**
* Convert the JSON output to an array
* @param string $result
Expand Down

0 comments on commit 5c78257

Please sign in to comment.