public function createNotificationChannel(Channel $channel) { $endpoint = $this->getFqdn() . '/notification/v1/channels'; $req = new RestfulRequest($endpoint); $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/json'); // PHP strips out .0 from 1.0 during json_encode; therefore, the string // has to be manually constructed. // Issue has been fixed in future PHP versions by specifying the // JSON_PRESERVE_ZERO_FRACTION flag. // See: https://bugs.php.net/bug.php?id=50224 $bodyString = '{"channel":{"serviceName":'; $bodyString .= '"' . $channel->getServiceName() . '"'; $bodyString .= ',"notificationContentType":'; $bodyString .= json_encode($channel->getNotificationContentType()); $bodyString .= ',"notificationVersion":1.0}}'; $httpPost = new HttpPost(); $httpPost->setBody($bodyString); $result = $req->sendHttpPost($httpPost); $location = $result->getHeader('location'); $systemTransId = $result->getHeader('x-systemTransactionId'); $successCodes = array(201); $arr = Service::parseJson($result, $successCodes); $arrChannel = $arr['channel']; $channelResponseId = $arrChannel['channelId']; $channelResponseMaxEvts = null; if (isset($arrChannel['maxEventsPerNotification'])) { $channelResponseMaxEvts = $arrChannel['maxEventsPerNotification']; } $channelResponse = new ChannelResponse($channelResponseId, $channelResponseMaxEvts); return new CreateNotificationResponse($location, $systemTransId, $channelResponse); }
/** * 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 createMessageIndex() { $endpoint = $this->getFqdn() . '/myMessages/v2/messages/index'; $req = new RestfulRequest($endpoint); $req->setHeader('Accept', 'application/json')->setAuthorizationHeader($this->getToken()); $httpPost = new HttpPost(); $httpPost->setBody(' '); //empty body $result = $req->sendHttpPost($httpPost); if ($result->getResponseCode() != 202) { $body = $result->getResponseBody(); throw new ServiceException($result->getResponseCode(), $body); } }
/** * Sends a request to the API gateway for creating a group. * * @param Group $group group information to create * * @return string location of created resource * @throws ServiceException if request was not successful */ public function createGroup(Group $group) { $endpoint = $this->getFqdn() . '/addressBook/v1/groups'; $req = new RestfulRequest($endpoint); $req->setAuthorizationHeader($this->getToken())->setHeader('Accept', 'application/json')->setHeader('Content-Type', 'application/json'); $httpPost = new HttpPost(); $httpPost->setBody(json_encode($group->toArray())); $result = $req->sendHttpPost($httpPost); $code = $result->getResponseCode(); if ($code != 201 && $code != 204) { throw new ServiceException($code, $result->getResponseBody()); } return $result->getHeader('location'); }
/** * 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); }