/** * @return Response */ public function requestAccessToken() { $this->prepareRequest(); $this->request->setUri($this->configuration->getBaseUri() . self::TOKEN_ENDPOINT); $this->request->setMethod('POST'); $payload = $this->httpClient->buildQuery(array('client_id' => $this->configuration->getClientId(), 'client_secret' => $this->configuration->getClientSecret(), 'grant_type' => $this->configuration->getGrantType(), 'username' => $this->configuration->getUsername(), 'password' => $this->configuration->getPassword(), 'company' => $this->configuration->getCompany())); $this->request->setPayload($payload); return $this->httpClient->send($this->request); }
/** * @param string $resource * @param string $method * @param array $params * @return Response */ public function call($resource, $method = 'GET', array $params = array()) { $method = strtoupper($method); $this->request->setHeader('Accept', 'application/json'); $this->request->setMethod($method); $params['access_token'] = $this->oauth2Client->getAccessToken(); $this->setContentType($method); $this->setUri($resource, $method, $params); $this->setPayload($method, $params); $reponse = $this->httpClient->send($this->request); if ('401' == $reponse->getStatusCode()) { $this->oauth2Client->flushAccessToken(); } return $reponse; }