Skip to content

Instantly share code, notes, and snippets.

@eduwass
Last active Sep 14, 2018
Embed
What would you like to do?
Fitmetrix quick'n'dirty API Wrapper
<?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