Last active
September 14, 2018 18:06
-
-
Save eduwass/db30173d966dcdca41b99ad634f0b908 to your computer and use it in GitHub Desktop.
Fitmetrix quick'n'dirty API Wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class FitmetrixAPI{ | |
private $base_url; | |
private $encoded_auth; | |
private $facility_location_id; | |
public function __construct($token, $token_key, $facility_location_id){ | |
$this->base_url = 'https://api.fitmetrix.io/api/'; | |
$this->encoded_auth = base64_encode("$token:$token_key"); | |
$this->facility_location_id = $facility_location_id; | |
} | |
public function getTrainers(){ | |
$api_query = self::curlRequest('instructor?pageSize=999'); | |
return $api_query; | |
} | |
public function getPackages(){ | |
$api_query = self::curlRequest('facility/locations/'.$this->facility_location_id.'/packages'); | |
return $api_query; | |
} | |
public function getActivities(){ | |
$api_query = self::curlRequest('facility/locations/'.$this->facility_location_id.'/upcoming'); | |
return $api_query; | |
} | |
private function curlRequest($endpoint){ | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => $this->base_url . $endpoint, | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_HTTPHEADER => array( | |
"authorization: Basic " . $this->encoded_auth | |
), | |
CURLOPT_RETURNTRANSFER => true, | |
)); | |
$response = curl_exec($curl); | |
$err = curl_error($curl); | |
curl_close($curl); | |
if ($err) { | |
return "cURL Error #:" . $err; | |
} else { | |
return $response; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment