/** * Sends a request to the API for getting device capabilities. * * @return DCResponse API response. * @throws ServiceException if API request was not successful */ public function getDeviceInformation() { $endpoint = $this->getFqdn() . '/rest/2/Devices/Info'; $req = new RESTFulRequest($endpoint); $result = $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->sendHttpGet(); $arr = Service::parseJson($result); return DCResponse::fromArray($arr); }
/** * Sends a request to the API for getting any SMS messages that were sent * to the specified short code. * * @param string $shortCode gets messages sent to this short code * * @return GetSMSResponse API response * @throws ServiceException if API request was not successful */ public function getMessages($shortCode, $raw_response = false) { $endpoint = $this->getFqdn() . '/sms/v3/messaging/inbox/' . urlencode($shortCode); $req = new RESTFulRequest($endpoint); $result = $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/x-www-form-urlencoded')->sendHttpGet(); // Handle the flag to return json. if ($raw_response) { $body = Service::parseApiResposeBody($result); // Note: This could throw ServiceExeption return $body; } $arr = Service::parseJson($result); return GetSMSResponse::fromArray($arr); }
/** * Sends a request to the API for converting text to speech. * * @param string $ctype content type. * @param string $txt text to convert to speech. * @param string|null $xArg optional arguments to set, if not null. * * @return raw audio/x-wave data. * @throws ServiceException if API request was not successful. */ public function textToSpeech($ctype, $txt, $xArg = null) { $endpoint = $this->getFqdn() . '/speech/v3/textToSpeech'; $req = new RESTFulRequest($endpoint); $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'audio/x-wav')->setHeader('Content-Type', $ctype); if ($xArg != null) { $req->setHeader('X-Arg', $xArg); } $httpPost = new HttpPost(); $httpPost->setBody($txt); $result = $req->sendHttpPost($httpPost); $code = $result->getResponseCode(); if ($code != 200 && $code != 201) { throw new ServiceException($body, $code); } $body = $result->getResponseBody(); return $body; }
/** * Sends a request to the API for getting any SMS messages that were sent * to the specified short code. * * @param string $shortCode gets messages sent to this short code * * @return GetSMSResponse API response * @throws ServiceException if API request was not successful */ public function getMessages($shortCode) { $endpoint = $this->getFqdn() . '/sms/v3/messaging/inbox/' . urlencode($shortCode); $req = new RESTFulRequest($endpoint); $result = $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/x-www-form-urlencoded')->sendHttpGet(); $arr = Service::parseJson($result); return GetSMSResponse::fromArray($arr); }
/** * Sends a request to the API gateway for getting subscriber's personal * contact card. * * @return Contact contact information for subscriber * @throws ServiceException if request was not successful */ public function getMyInfo() { $endpoint = $this->getFqdn() . '/addressBook/v1/myInfo'; $req = new RESTFulRequest($endpoint); $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json'); $result = $req->sendHttpGet(); $successCodes = array(200); $arr = Service::parseJson($result, $successCodes); return Contact::fromArray($arr['myInfo']); }