示例#1
0
 /**
  * Sends a message.
  * @param mixed $message
  * @return MessageResponse|HttpResponse|null
  * @throws ErrorException
  */
 public function sendMessage($message)
 {
     $resource = "/messages/";
     if (is_null($message)) {
         throw new ErrorException("Parameter 'message' cannot be null");
     } elseif (!$message instanceof Message && !is_array($message)) {
         throw new ErrorException("Parameter 'message' must be an instance of Message or an array");
     }
     try {
         $params = array();
         $params = is_array($message) ? $message : json_decode(JsonHelper::toJson($message), true);
         $params["Direction"] = MessageDirection::OUT;
         $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 MessageResponse($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }
示例#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;
 }
示例#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;
 }
示例#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;
 }
示例#5
0
 /**
  * Update Account Settings or Preferences and returns the updated preference object.
  * In case of errors an error is triggered
  * @param mixed $request Preference Object to update
  * @return Setting|HttpResponse|null Updated preference
  * @throws ErrorException
  */
 public function updateAccountSettings($request)
 {
     $resource = "/account/settings/";
     if (is_null($request)) {
         throw new ErrorException("Parameter 'preference' cannot be null");
     } elseif (!is_array($request) || !$request instanceof Setting) {
         throw new ErrorException("Parameter 'request' must be an array");
     }
     try {
         $params = array();
         $params = is_array($request) ? $request : json_decode(JsonHelper::toJson($request), true);
         $response = $this->httpClient->post($resource, $params);
         if ($response instanceof HttpResponse) {
             if ($response->getStatus() === HttpStatusCode::HTTP_OK) {
                 $json = JsonHelper::getJson($response->getBody());
                 if (isset($json)) {
                     return new Setting($json);
                 }
             } else {
                 return $response;
             }
         }
     } catch (Exception $ex) {
         echo $ex->getTraceAsString();
     }
     return null;
 }