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
|
|
|
|
2017-05-26 10:53:24 -05:00
|
|
|
const RIDES_URL = 'http://app.strava.com/rides/';
|
|
|
|
|
const ATHLETES_URL = 'http://app.strava.com/athletes/';
|
|
|
|
|
|
2014-09-11 15:56:35 -05:00
|
|
|
public function getRide( $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
|
2017-05-26 10:53:24 -05:00
|
|
|
|
|
|
|
|
public function getRides( $club_id = null, $quantity = null ) {
|
2013-04-07 17:56:07 -05:00
|
|
|
$api = WPStrava::get_instance()->api;
|
|
|
|
|
|
2017-05-26 10:53:24 -05:00
|
|
|
$data = null;
|
|
|
|
|
|
|
|
|
|
$args = $quantity ? array( 'per_page' => $quantity ) : null;
|
2014-09-11 15:56:35 -05:00
|
|
|
|
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 ) ) {
|
2014-09-11 15:56:35 -05:00
|
|
|
$data = $api->get( "clubs/{$club_id}/activities", $args );
|
2011-08-23 09:34:28 -05:00
|
|
|
} else {
|
2014-09-11 15:56:35 -05:00
|
|
|
$data = $api->get( 'athlete/activities', $args );
|
2011-08-23 09:34:28 -05:00
|
|
|
}
|
2013-04-07 17:56:07 -05:00
|
|
|
|
|
|
|
|
if ( is_wp_error( $data ) )
|
|
|
|
|
return $data;
|
2017-05-26 10:53:24 -05:00
|
|
|
|
2014-09-11 10:48:03 -05:00
|
|
|
if ( is_array( $data ) )
|
|
|
|
|
return $data;
|
2017-05-26 10:53:24 -05:00
|
|
|
|
|
|
|
|
return array();
|
|
|
|
|
|
2014-09-11 10:48:03 -05:00
|
|
|
} // getRides
|
2013-04-07 18:09:50 -05:00
|
|
|
|
|
|
|
|
public function getRidesLongerThan( $rides, $dist ) {
|
2017-05-26 10:53:24 -05:00
|
|
|
$som = WPStrava_SOM::get_som();
|
2013-04-07 18:09:50 -05:00
|
|
|
$meters = $som->distance_inverse( $dist );
|
|
|
|
|
|
|
|
|
|
$long_rides = array();
|
2014-09-11 15:56:35 -05:00
|
|
|
foreach ( $rides as $ride_info ) {
|
|
|
|
|
if ( $ride_info->distance > $meters ) {
|
2013-04-07 18:09:50 -05:00
|
|
|
$long_rides[] = $ride_info;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-26 10:53:24 -05:00
|
|
|
|
2013-04-07 18:09:50 -05:00
|
|
|
return $long_rides;
|
|
|
|
|
}
|
2017-05-26 10:53:24 -05:00
|
|
|
|
2011-08-23 09:34:28 -05:00
|
|
|
} // class Rides
|