Esempio n. 1
0
 /**
  * Gets Message based upon some filters
  * @param mixed $start The date to start querying from.
  * @param mixed $end The last possible time in the query.
  * @param integer $index The number of results to skip from the result set. The default is 0.
  * @param integer $limit The maximum number of results to return. This has a hard limit of 1000 messages.
  * @param boolean $pending A true or false value used to indicate if only scheduled messages should be returned in the result set. By default only sent message are returned
  * @param string $direction Used to filter the result by the direction of the message. Possible values are "in" (to return only inbound messages) and "out" (to return only outbound messages).
  * @return ApiList|HttpResponse|null
  * @throws ErrorException
  */
 public function getMessages($start = null, $end = null, $index = null, $limit = null, $pending = null, $direction = null)
 {
     $resource = "/messages/";
     if (!is_null($start)) {
         if (!is_int($start) || !is_string($start)) {
             throw new ErrorException("Parameter 'start' must be an integer Unix timestamp or a string time in this format (YYYY-MM-DD HH:MM:SS)");
         }
         if (is_string($start)) {
             if (!CommonUtil::is_datetime($time)) {
                 throw new ErrorException("Parameter 'start' must be a string time in this format (YYYY-MM-DD HH:MM:SS)");
             }
         }
         if (is_int($start) && $start < 0) {
             throw new ErrorException("Parameter 'start' must be a positive integer");
         }
     }
     if (!is_null($end)) {
         if (!is_int($end) || !is_string($end)) {
             throw new ErrorException("Parameter 'end' must be an integer Unix timestamp or a string time in this format (YYYY-MM-DD HH:MM:SS)");
         }
         if (is_string($end)) {
             if (!CommonUtil::is_datetime($time)) {
                 throw new ErrorException("Parameter 'end' must be a string time in this format (YYYY-MM-DD HH:MM:SS)");
             }
         }
         if (is_int($end) && $end < 0) {
             throw new ErrorException("Parameter 'end' must be a positive integer");
         }
     }
     if (!is_null($index) && !is_int($index)) {
         throw new ErrorException("Parameter 'index' must be an integer");
     }
     if (!is_null($limit) && !is_int($limit)) {
         throw new ErrorException("Parameter 'limit' must be an integer");
     }
     if (!is_null($pending) && (!CommonUtil::is_boolean($pending) || !is_bool($pending))) {
         throw new ErrorException("Parameter 'pending' must be a boolean (1, 0, true, false)");
     }
     if (!is_null($direction)) {
         if (!is_string($direction)) {
             throw new ErrorException("Parameter 'direction' must be string");
         } elseif ($direction !== MessageDirection::IN || $direction !== MessageDirection::OUT) {
             throw new ErrorException("Parameter 'direction' must be string. Possible values are in or out");
         }
     }
     try {
         $params = array();
         if (!is_null($start)) {
             $params["start"] = is_string($start) ? $start : gmdate('Y-m-d H:i:s', $start);
         }
         if (!is_null($end)) {
             $params["end"] = is_string($end) ? $end : gmdate('Y-m-d H:i:s', $end);
         }
         if (!is_null($index)) {
             $params["index"] = $index > 0 ? $index : 0;
         }
         if (!is_null($limit)) {
             $params["limit"] = $limit > 0 && $limit <= 1000 ? $limit : 1000;
         }
         if (!is_null($pending)) {
             if ($pending === "true" || $pending || $pending === "1") {
                 $params["pending"] = "true";
             }
             if ($pending === "false" || $pending === false || $pending === "0") {
                 $params["pending"] = "false";
             }
         }
         if (!is_null($direction)) {
             $params["direction"] = $direction;
         }
         $response = $this->httpClient->get($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new ApiList($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
Esempio n. 2
0
 /**
  * Creates a new Contact Group
  * @param mixed $group The contact group data. It can be an associative array or an instance of ContactGroup
  * @return HttpResponse|null|ContactGroup
  * @throws ErrorException
  */
 public function addContactGroup($group)
 {
     $resource = "/contacts/groups/";
     if (is_null($group)) {
         throw new ErrorException("Parameter 'group' cannot be null");
     }
     if (!is_string($group) || !$group instanceof ContactGroup || !is_array($group)) {
         throw new ErrorException("Parameter 'group' must be of type ContactGroup or an array or a string");
     }
     try {
         $params = array();
         if (is_string($group)) {
             $params["Name"] = $group;
         } else {
             $params = is_array($group) ? $group : json_decode(JsonHelper::toJson($group), true);
         }
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_CREATED) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new ContactGroup($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (\Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
Esempio n. 3
0
 /**
  * Replies to a Support Ticket
  * @param integer $ticketId
  * @param mixed $request
  * @return HttpResponse|null|Ticket
  * @throws \ErrorException
  */
 public function updateSupportTicket($ticketId, $request)
 {
     $resource = "/tickets/";
     if (is_null($ticketId)) {
         throw new \ErrorException("Parameter 'ticketId' cannot be null");
     } elseif (!is_int($ticketId)) {
         throw new \ErrorException("Parameter 'ticketId' must be an integer");
     }
     if (is_null($request)) {
         throw new \ErrorException("Parameter 'request' cannot be null");
     } elseif (!$request instanceof TicketResponse || !is_array($request)) {
         throw new \ErrorException("Parameter 'request' must be of type TicketResponse or an array");
     }
     try {
         $params = array();
         $params = is_array($request) ? $request : json_decode(JsonHelper::toJson($request), true);
         $response = $this->httpClient->put($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new Ticket($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (\Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
Esempio n. 4
0
 /**
  * Updates the details of an existing content media.
  * @param UUID $mediaId The content media
  * @param MediaInfo $mediaInfo The content media details
  * @return HttpResponse|ContentMedia|null
  * @throws ErrorException
  */
 public function updateContentMedia($mediaId, $mediaInfo = null)
 {
     $resource = "/media/";
     if (is_null($mediaId)) {
         throw new ErrorException("Parameter 'mediaId' cannot be null");
     } elseif (!CommonUtil::is_uuid($mediaId)) {
         throw new ErrorException("Parameter 'mediaId' must be a valid UUID");
     }
     if (!is_null($mediaInfo) && !$mediaInfo instanceof MediaInfo) {
         throw new ErrorException("Parameter 'mediaInfo' cannot be null and must be an instance of MediaInfo.");
     }
     try {
         $resource .= $mediaId;
         // Set the mediainfo data
         $params["ContentName"] = $mediaInfo->contentName;
         $params["LibraryId"] = $mediaInfo->libraryId;
         $params["DestinationFolder"] = $mediaInfo->destinationFolder;
         $params["Preference"] = $mediaInfo->preference;
         $params["Width"] = $mediaInfo->width;
         $params["Height"] = $mediaInfo->height;
         $params["DrmProtect"] = $mediaInfo->drmProtect;
         $params["Streamable"] = $mediaInfo->streamable;
         $params["DisplayText"] = $mediaInfo->displayText;
         $params["ContentText"] = $mediaInfo->contentText;
         $params["Tags"] = "";
         // set the medainfo tags
         if (!is_null($mediaInfo->tags) && is_array($mediaInfo->tags) && count($mediaInfo->tags) > 0) {
             $params["Tags"] = JsonHelper::toJson($mediaInfo->tags);
         }
         $response = $this->httpClient->put($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new ContentMedia($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         $ex->getTraceAsString();
     }
     return null;
 }
Esempio n. 5
0
 /**
  * Get a voucher topup
  * @param string $voucherNumber
  * @return HttpResponse|Topup|null
  * @throws ErrorException
  */
 public function getVoucher($voucherNumber)
 {
     $resource = "/topup/voucher/";
     if (is_null($voucherNumber)) {
         throw new ErrorException("Parameter 'voucherNumber' cannot be null");
     } elseif (!is_string($voucherNumber)) {
         throw new ErrorException("Parameter 'voucherNumber' must be a string");
     }
     try {
         $resource .= $voucherNumber;
         $response = $this->httpClient->get($resource);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new Topup($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }