/** 
  * Adds the required http headers to the specified request object.
  *
  * @param RestfulRequest $req restful request object
  *
  * @return void
  */
 private function _setHeaders($req)
 {
     $req->setHeader('Content-Type', 'application/json');
     $req->setHeader('Accept', 'application/json');
     $req->setHeader('Client_id', $this->_clientId);
     $req->setHeader('Client_secret', $this->_clientSecret);
 }
 /**
  * Associates a token with the specified user id.
  *
  * @param string $userId user id to associate with token
  *
  * @return void
  * @throws ServiceException if request was not successful
  */
 public function associateToken($userId)
 {
     $endpoint = $this->getFqdn() . '/RTC/v1/userIds/' . urlencode($userId);
     $req = new RestfulRequest($endpoint);
     $result = $req->setAuthorizationHeader($this->getToken())->setHeader('Content-Type', 'application/json')->sendHttpPut(new HttpPut(''));
     $code = $result->getResponseCode();
     if ($code != 204) {
         throw new ServiceException($result->getResponseBody(), $code);
     }
 }
 /**
  * Revokes the specified token.
  *
  * @param string $token token to revoke
  * @param string $hint hint for token type
  *
  * @throws OAuthException if API gateway returned an error
  */
 public function revokeToken($token, $hint = 'access_token')
 {
     $httpPost = new HttpPost();
     $httpPost->setParam('client_id', $this->_clientId)->setParam('client_secret', $this->_clientSecret)->setParam('token', $token)->setParam('token_type_hint', $hint);
     $req = new RestfulRequest($this->_revoke_url);
     $result = $req->sendHttpPost($httpPost);
     if ($result->getResponseCode() != 200) {
         throw new OAuthException('HTTP Code', $result->getResponseBody());
     }
 }
 public function getNotificationConnectionDetails($queues)
 {
     $endpoint = $this->getFqdn() . '/myMessages/v2/notificationConnectionDetails';
     $req = new RestfulRequest($endpoint);
     $req->setHeader('Accept', 'application/json')->setAuthorizationHeader($this->getToken());
     $httpGet = new HttpGet();
     $httpGet->setParam('queues', $queues);
     $result = $req->sendHttpGet($httpGet);
     $arr = Service::parseJson($result);
     return IMMNNotificactionCD::fromArray($arr);
 }
Example #5
0
 /**
  * Sends a request to the API for getting an advertisement. 
  * 
  * @param string       $category  category of this app.
  * @param string       $userAgent user agent string to send to API.
  * @param string       $udid      specifies a universially unique
  *                                identifier, which must be at least 30
  *                                characters in length.
  * @param OptArgs|null $optArgs   any optional values.
  *
  * @return null|ADSResponse null if no ads were returned, 
  *                          otherwise an ADSResponse object
  * @throws ServiceException if API request was not successful
  */
 public function getAdvertisement($category, $userAgent, $udid, OptArgs $optArgs = null, $raw_response = false)
 {
     $endpoint = $this->getFqdn() . '/rest/1/ads';
     $req = new RestfulRequest($endpoint);
     $req->setAuthorizationHeader($this->getToken())->setHeader('User-agent', $userAgent)->setHeader('Udid', $udid);
     $httpGet = new HttpGet();
     $httpGet->setParam('Category', $category);
     if ($optArgs != null) {
         $this->_appendOptArgs($httpGet, $optArgs);
     }
     $result = $req->sendHttpGet($httpGet);
     // no ads returned
     if ($result->getResponseCode() == 204) {
         if ($raw_response) {
             return $result->getResponseBody();
         }
         return null;
     }
     if ($raw_response) {
         return Service::parseApiResposeBody($result);
     }
     // response as json array
     $jarr = Service::parseJson($result);
     return ADSResponse::fromArray($jarr);
 }
 /**
  * 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 updateMyInfo(ContactCommon $contact)
 {
     $endpoint = $this->getFqdn() . '/addressBook/v1/myInfo';
     $req = new RestfulRequest($endpoint);
     $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/json');
     $body = json_encode(array('myInfo' => $contact->toArray()));
     $httpPatch = new HttpPatch($body);
     $result = $req->sendHttpPatch($httpPatch);
     $code = $result->getResponseCode();
     if ($code != 201 && $code != 204) {
         throw new ServiceException($code, $result->getResponseBody());
     }
 }
 /**
  * Gets a new OAuth token using the refresh token of the specified OAuth
  * token.
  *
  * The token request is done using the <i>refresh_token</i> grant type.
  *
  * @param OAuthToken $token OAuth token to use for refreshing
  *
  * @return OAuthToken an OAuth token
  * @throws OAuthException if server did not return valid access token
  */
 public function refreshToken(OAuthToken $token)
 {
     $httpPost = new HttpPost();
     $httpPost->setParam('refresh_token', $token->getRefreshToken())->setParam('grant_type', 'refresh_token')->setParam('client_id', $this->_clientId)->setParam('client_secret', $this->_clientSecret);
     $req = new RestfulRequest($this->_url);
     $result = $req->sendHttpPost($httpPost);
     return $this->parseResult($result);
 }
 public function deleteNotificationSubscription($channelId, $subscriptionId)
 {
     $channelId = urlencode($channelId);
     $subscriptionId = urlencode($subscriptionId);
     $suburl = '/notification/v1/channels/' . $channelId . '/subscriptions/';
     $suburl = $suburl . $subscriptionId;
     $endpoint = $this->getFqdn() . $suburl;
     $req = new RestfulRequest($endpoint);
     $req->setAuthorizationHeader($this->getToken());
     $result = $req->sendHttpDelete();
     $code = $result->getResponseCode();
     $body = $result->getResponseBody();
     if ($code != 204) {
         throw new ServiceException($body, $code);
     }
     return $result->getHeader('x-systemTransactionId');
 }
 /**
  * Internal function used for sending common transaction operation 
  * statuses, such as refunding a transaction or cancelling a subscription.
  *
  * @param string $rReasonTxt     reason for refunding
  * @param string $rReasonCode    reason code for refunding
  * @param string $transOptStatus transaction operation status 
  *                               (e.g. Refunded). 
  * @param string $url            URL used for sending request
  * 
  * @return string api response
  * @throws ServiceException if api request was not successful
  */
 private function _sendTransOptStatus($rReasonTxt, $rReasonCode, $transOptStatus, $url)
 {
     $req = new RestfulRequest($url);
     $bodyArr = array('TransactionOperationStatus' => $transOptStatus, 'RefundReasonCode' => $rReasonCode, 'RefundReasonText' => $rReasonTxt);
     $httpPut = new HttpPut(json_encode($bodyArr));
     $req->setHeader('Accept', 'application/json')->setAuthorizationHeader($this->getToken())->setHeader('Content-Type', 'application/json');
     $result = $req->sendHttpPut($httpPut);
     return Service::parseJson($result);
 }