/**
  * Get zero or more objects from table Customers
  * @param   string|null $filter    Optional parameter: Arbitrary search criteria
  * @return CustomersModel response from the API call*/
 public function GetCustomers($filter = NULL)
 {
     //prepare query string for API call
     $queryBuilder = Configuration::BASEURI . "/Customers";
     //process optional query parameters
     APIHelper::appendUrlWithQueryParameters($queryBuilder, array("filter" => $filter));
     //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::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 < 200 || $response->code > 206) {
         //[200,206] = HTTP OK
         throw new APIException("HTTP Response Not OK", $response->code);
     }
     return $response->body;
 }
示例#2
0
 /**
  * The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.
  * @param   int $offset    Required parameter: Page offset for pagging
  * @param   int $limit    Required parameter: Number of items to return for pagging
  * @return UserActivityModel response from the API call*/
 public function getUserActivity($offset, $limit)
 {
     //prepare query string for API call
     $queryBuilder = Configuration::BASEURI . "/v1/history";
     //process optional query parameters
     APIHelper::appendUrlWithQueryParameters($queryBuilder, array("offset" => $offset, "limit" => $limit));
     //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;
 }