Working multi tokens with nicknames

This commit is contained in:
Justin Foell
2017-07-21 16:12:15 -05:00
parent 6c15a669f1
commit 8fc5ea3407
4 changed files with 173 additions and 61 deletions
+6 -10
View File
@@ -11,7 +11,7 @@ class WPStrava {
private static $instance = null;
private $settings = null;
private $api = null;
private $api = array(); // Holds an array of APIs.
private $rides = null;
private function __construct() {
@@ -38,10 +38,6 @@ class WPStrava {
public function __get( $name ) {
// On-demand classes.
if ( $name == 'api' ) {
return $this->get_api();
}
if ( $name == 'rides' ) {
return $this->get_rides();
}
@@ -53,13 +49,13 @@ class WPStrava {
return null;
}
public function get_api() {
if ( ! $this->api ) {
public function get_api( $id = '0' ) {
if ( ! $this->api[$id] ) {
require_once WPSTRAVA_PLUGIN_DIR . 'lib/API.class.php';
$this->api = new WPStrava_API( get_option( 'strava_token' ) );
$this->api[$id] = new WPStrava_API( $this->settings->get_setting( 'strava_token', $id ) );
}
return $this->api;
return $this->api[$id];
}
public function get_rides() {
@@ -75,4 +71,4 @@ class WPStrava {
// Register a personalized stylesheet
wp_register_style( 'wp-strava-style', WPSTRAVA_PLUGIN_URL . 'css/wp-strava.css' );
}
}
}