Files
wp-strava/lib/Rides.class.php
T

108 lines
3.0 KiB
PHP
Raw Normal View History

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 ) {
return WPStrava::get_instance()->api->get( "rides/{$rideId}" );
} // 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
2013-04-07 17:56:07 -05:00
public function getRidesSimple( $searchOption, $searchId ) {
$api = WPStrava::get_instance()->api;
$data = NULL;
2011-08-23 09:34:28 -05:00
//Get the json results using the constructor specified values.
2013-04-07 17:56:07 -05:00
if ( $searchOption == 'athlete' ) {
if ( is_numeric( $searchId ) ) {
$data = $api->get( 'rides', array( 'athleteId' => $searchId ), 1 );
2011-08-23 09:34:28 -05:00
} else {
2013-04-07 17:56:07 -05:00
$data = $api->get( 'rides', array( 'athleteName' => $searchId ), 1 );
2011-08-23 09:34:28 -05:00
}
2013-04-07 17:56:07 -05:00
} elseif ($searchOption == 'club' && is_numeric($searchId)) {
$data = $api->get( 'rides', array( 'clubId' => $searchId ), 1 );
2011-08-23 09:34:28 -05:00
} else {
2013-04-07 17:56:07 -05:00
return new WP_Error( 'wp-strava_options', __("There's an error in your simple options.", 'wp-strava') );
2011-08-23 09:34:28 -05:00
}
2013-04-07 17:56:07 -05:00
if ( is_wp_error( $data ) )
return $data;
if ( isset( $data->rides ) )
return $data->rides;
return array();
} // getRidesSimple
public function getRidesAdvanced( $params ) {
$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
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
?>