2011-08-23 09:34:28 -05:00
|
|
|
<?php
|
|
|
|
|
/*
|
2013-02-03 20:38:55 -06:00
|
|
|
* Rides is a class wrapper for the Strava REST API functions.
|
2011-08-23 09:34:28 -05:00
|
|
|
*/
|
2013-02-03 20:38:55 -06:00
|
|
|
class WPStrava_Rides {
|
2012-06-12 17:36:49 -05:00
|
|
|
|
2013-04-07 17:56:07 -05:00
|
|
|
const RIDES_URL = "http://app.strava.com/rides/";
|
|
|
|
|
const ATHLETES_URL = "http://app.strava.com/athletes/";
|
2011-08-23 09:34:28 -05:00
|
|
|
|
2013-04-07 17:56:07 -05:00
|
|
|
public function getRideDetails( $rideId ) {
|
2014-09-11 10:48:03 -05:00
|
|
|
return WPStrava::get_instance()->api->get( "activities/{$rideId}" );
|
2013-04-07 17:56:07 -05:00
|
|
|
} // getRideDetails
|
|
|
|
|
|
|
|
|
|
public function getRidesDetails( $rides ) {
|
|
|
|
|
$rides_details = array();
|
|
|
|
|
foreach ( $rides as $stravaRide ) {
|
|
|
|
|
$detail = $this->getRideDetails( $stravaRide->id );
|
|
|
|
|
|
|
|
|
|
if ( is_wp_error( $detail ) )
|
|
|
|
|
return $detail;
|
|
|
|
|
|
|
|
|
|
$rides_details[] = $detail;
|
2011-08-23 09:34:28 -05:00
|
|
|
}
|
2013-04-07 17:56:07 -05:00
|
|
|
return $rides_details;
|
2011-08-23 09:34:28 -05:00
|
|
|
} // getRidesDetails
|
|
|
|
|
|
2014-09-11 10:48:03 -05:00
|
|
|
public function getRides( $quantity, $club_id = NULL ) {
|
2013-04-07 17:56:07 -05:00
|
|
|
$api = WPStrava::get_instance()->api;
|
|
|
|
|
|
|
|
|
|
$data = NULL;
|
2011-08-23 09:34:28 -05:00
|
|
|
//Get the json results using the constructor specified values.
|
2014-09-11 10:48:03 -05:00
|
|
|
if ( is_numeric( $club_id ) ) {
|
|
|
|
|
$data = $api->get( "clubs/{$club_id}/activities", array( 'per_page' => $quantity ) );
|
2011-08-23 09:34:28 -05:00
|
|
|
} else {
|
2014-09-11 10:48:03 -05:00
|
|
|
$data = $api->get( 'athlete/activities', array( 'per_page' => $quantity ) );
|
2011-08-23 09:34:28 -05:00
|
|
|
}
|
2013-04-07 17:56:07 -05:00
|
|
|
|
|
|
|
|
if ( is_wp_error( $data ) )
|
|
|
|
|
return $data;
|
|
|
|
|
|
2014-09-11 10:48:03 -05:00
|
|
|
if ( is_array( $data ) )
|
|
|
|
|
return $data;
|
2013-04-07 17:56:07 -05:00
|
|
|
|
|
|
|
|
return array();
|
|
|
|
|
|
2014-09-11 10:48:03 -05:00
|
|
|
} // getRides
|
2013-04-07 17:56:07 -05:00
|
|
|
|
|
|
|
|
public function getRidesAdvanced( $params ) {
|
2013-04-07 18:09:50 -05:00
|
|
|
$data = WPStrava::get_instance()->api->get( 'rides', $params, 1 ); //version 1
|
2013-04-07 17:56:07 -05:00
|
|
|
|
|
|
|
|
if ( is_wp_error( $data ) )
|
|
|
|
|
return $data;
|
|
|
|
|
|
|
|
|
|
if ( isset( $data->rides ) )
|
|
|
|
|
return $data->rides;
|
|
|
|
|
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2013-03-31 21:28:49 -05:00
|
|
|
|
2011-08-23 09:34:28 -05:00
|
|
|
public function getRideMap($rideId, $token, $efforts, $threshold) {
|
|
|
|
|
if($rideId != 0 AND $token != "") {
|
2012-06-12 17:36:49 -05:00
|
|
|
$url = preg_replace('/:id/', $rideId, $this->rideMapDetailsUrlV2);
|
2011-08-23 09:34:28 -05:00
|
|
|
$json = file_get_contents($url . '?token=' . $token . '&threshold=' . $threshold);
|
|
|
|
|
|
|
|
|
|
if($json) {
|
|
|
|
|
//$map_details = json_decode($json);
|
|
|
|
|
//return $map_details;
|
|
|
|
|
return $json;
|
|
|
|
|
} else {
|
|
|
|
|
$this->feedback .= _e("There was an error pulling data of strava.com.", "wp-strava");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->feedback .= _e("You need to provide both parameters to complete the call.", "wp-strava");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} // getRideDetails
|
2013-04-07 18:09:50 -05:00
|
|
|
|
|
|
|
|
public function getRidesLongerThan( $rides, $dist ) {
|
|
|
|
|
$som = WPStrava_SOM::get_som();
|
|
|
|
|
$meters = $som->distance_inverse( $dist );
|
|
|
|
|
|
|
|
|
|
$long_rides = array();
|
|
|
|
|
foreach ( $rides as $ride ) {
|
|
|
|
|
$ride_info = $this->getRideDetails( $ride->id );
|
|
|
|
|
if ( $ride_info->ride->distance > $meters ) {
|
|
|
|
|
$long_rides[] = $ride_info;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $long_rides;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getMapDetails( $ride_id ) {
|
|
|
|
|
$token = WPStrava::get_instance()->settings->token;
|
|
|
|
|
return WPStrava::get_instance()->api->get( "rides/{$ride_id}/map_details", array( 'token' => $token ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-08-23 09:34:28 -05:00
|
|
|
} // class Rides
|
2012-03-15 08:57:10 -06:00
|
|
|
?>
|