/**
  * Delete one object
  * @param   string $pk    Required parameter: CustomerID
  * @return CustomersModel response from the API call*/
 public function DeleteOneCustomers($pk)
 {
     //prepare query string for API call
     $queryBuilder = Configuration::BASEURI . "/Customers/{pk}";
     //process optional query parameters
     APIHelper::appendUrlWithTemplateParameters($queryBuilder, array("pk" => $pk));
     //validate and preprocess url
     $queryUrl = APIHelper::cleanUrl($queryBuilder);
     //prepare headers
     $headers = array("User-Agent" => @"APIMATIC 2.0", "Accept" => "application/json");
     //prepare API request
     $request = Unirest::delete($queryUrl, $headers);
     //and invoke the API call request to fetch the response
     $response = $request->getResponse();
     //Error handling using HTTP status codes
     if ($response->code < 200 || $response->code > 206) {
         //[200,206] = HTTP OK
         throw new APIException("HTTP Response Not OK", $response->code);
     }
     return $response->body;
 }
Ejemplo n.º 2
0
 /**
  * The User Profile endpoint returns information about the Uber user that has authorized with the application.
  * @return UserProfileModel response from the API call*/
 public function getUserProfile()
 {
     //prepare query string for API call
     $queryBuilder = Configuration::BASEURI . "/v1/me";
     //validate and preprocess url
     $queryUrl = APIHelper::cleanUrl($queryBuilder);
     //prepare headers
     $headers = array("accept" => "application/json", "Authorization", sprintf("Bearer %1{$s}", Configuration::$oAuthAccessToken));
     //prepare API request
     $request = Unirest::get($queryUrl, $headers);
     //and invoke the API call request to fetch the response
     $response = $request->getResponse();
     //Error handling using HTTP status codes
     if ($response->code == 400) {
         throw new APIException("Malformed request.", 400);
     } else {
         if ($response->code == 401) {
             throw new APIException("Unauthorized the request requires user authentication (not logged in).", 401);
         } else {
             if ($response->code == 403) {
                 throw new APIException("Forbidden. Also used for unauthorized requests such as improper OAuth 2.0 scopes or permissions issues.", 403);
             } else {
                 if ($response->code == 404) {
                     throw new APIException("Not found.", 404);
                 } else {
                     if ($response->code == 406) {
                         throw new APIException("Unacceptable content type. Client sent an accepts header for a content type which does not exist on the server. Body includes a list of acceptable content types: “Unacceptable content type. Request resource as: application/json, etc.", 406);
                     } else {
                         if ($response->code == 422) {
                             throw new APIException("Invalid request. The request body is parse-able however with invalid content.", 422);
                         } else {
                             if ($response->code == 429) {
                                 throw new APIException("Too Many Requests. Rate limited.", 429);
                             } else {
                                 if ($response->code == 500) {
                                     throw new APIException("Internal Server Error.", 500);
                                 } else {
                                     if ($response->code != 200) {
                                         //200 = HTTP OK
                                         throw new APIException("HTTP Response Not OK", $response->code);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $response->body;
 }