示例#1
0
 /**
  * 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);
     }
 }
示例#2
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());
     }
 }
 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');
 }