Exemplo n.º 1
0
 /**
  * Get Item Count
  *
  * @param sentItems - optional -
  *         If true, the API returns the number of items in user's Sent Items
  *         otherwise it returns the number of the items in user's Inbox and Sent Items.
  * @param filter - optional -
  * 			all: return all items
  *			expired: returns all expired items
  *			unexpired: returns only unexpired items
  * @return The Count object containing the number of items or the error code and message
  * returned by the server.
  * 	 */
 public function getItemsCount($sentItems = '', $filter = '')
 {
     $parameters = array();
     $urld = 'dpi/v1/item/count';
     if ($sentItems !== '') {
         $parameters['sentItems'] = $sentItems;
     }
     if ($filter !== '') {
         $parameters['filter'] = $filter;
     }
     $this->response = $this->_restTransportInstance->sendRequest($urld, $parameters, 'GET', $this->_authToken);
     $responseBody = simplexml_load_string($this->response);
     $returnObject = new Count();
     if ($responseBody === false) {
         $errorCode = 'N/A';
         $errorMessage = 'The server has encountered an error, please try again.';
         $errorObject = new ErrorStatus($errorCode, $errorMessage);
         $returnObject->setErrorStatus($errorObject);
     } else {
         if (empty($responseBody->errorStatus)) {
             $itemCount = (string) $responseBody->itemCount;
             $returnObject->setItemCount($itemCount);
         } else {
             $errorCode = (string) $responseBody->errorStatus->code;
             $errorMessage = (string) $responseBody->errorStatus->message;
             $errorObject = new ErrorStatus($errorCode, $errorMessage);
             $returnObject->setErrorStatus($errorObject);
         }
     }
     return $returnObject;
 }