public static function reportingCall($operation, Model $model, array $postData, $businessSubdomain = '') { $accessToken = Businesses::get($businessSubdomain); if ($businessSubdomain == '') { $businessSubdomain = Businesses::$defaultBusinessSubdomain; } if (!isset($model::$endPoints[$operation])) { throw new Exception($operation . ' is not defined in ' . get_class($model) . '\'s endpoints'); } $endPoint = $model::$endPoints[$operation]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://' . $businessSubdomain . '.frontdeskhq.com' . $endPoint['urlPath']); switch (strtoupper($endPoint['httpMethod'])) { case 'POST': curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData, JSON_PRETTY_PRINT)); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $accessToken, 'Content-Type: application/vnd.api+json')); curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem'); $rawResponse = curl_exec($ch); if ($rawResponse === false) { throw new \Exception("Error while communicating with FrontDesk " . curl_error($ch)); } $response = json_decode($rawResponse, true); if ($response == null) { throw new \Exception("Error when decoding response to json... Response was: " . substr($rawResponse, 0, 100)); } if (isset($response['errors'])) { throw new \Exception("Error from FrontDesk: " . implode(",", $response['errors'])); } return $response; }
<?php \NovakSolutions\FrontDesk\Businesses::add("mybiz", "your_access_token_goes_here");