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

73 lines
1.9 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
const ACTIVITIES_URL = 'http://app.strava.com/activities/';
const ATHLETES_URL = 'http://app.strava.com/athletes/';
2017-05-26 10:53:24 -05:00
/**
* Get single activity by ID.
*
* @param string $athlete_token Token of athlete to retrieve for
* @param int $activity_id ID of activity to retrieve.
* @return object stdClass representing this activty.
* @author Justin Foell
*/
public function getRide( $athlete_token, $activity_id ) {
return WPStrava::get_instance()->get_api( $athlete_token )->get( "activities/{$activity_id}" );
2013-04-07 17:56:07 -05:00
} // getRideDetails
2017-05-26 10:53:24 -05:00
/**
* Get activity list from Strava API.
*
* @author Justin Foell
*
* @param string $athlete_token Token of athlete to retrieve for
* @param int $club_id Club ID of all club riders (optional).
* @param int|null $quantity Number of records to retrieve (optional).
* @return array|WP_Error Array of rides or WP_Error.
*/
public function getRides( $athlete_token, $club_id = null, $quantity = null ) {
$api = WPStrava::get_instance()->get_api( $athlete_token );
2013-04-07 17:56:07 -05:00
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.
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 ) ) {
2013-04-07 17:56:07 -05:00
return $data;
}
2017-05-26 10:53:24 -05:00
if ( is_array( $data ) ) {
return $data;
}
2017-05-26 10:53:24 -05:00
return array();
} // getRides
public function getRidesLongerThan( $rides, $dist ) {
$som = WPStrava_SOM::get_som();
$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 ) {
$long_rides[] = $ride_info;
}
}
2017-05-26 10:53:24 -05:00
return $long_rides;
}
2017-05-26 10:53:24 -05:00
2011-08-23 09:34:28 -05:00
} // class Rides