/** * Authenticate on OAuth server with the specific authorization code. * * @param string $code The authorization code * * @return array The struct array('access_token' => string, 'expires_in' => integer) * * @throws Exception\AuthException * @throws Exception\NetworkException */ public function authenticate($code) { $request = new FormRequest(); $response = new Response(); $request->setHost(self::BASEURL); $request->setResource('/token'); $request->setField('grant_type', 'authorization_code'); $request->setField('code', $code); $request->setField('client_id', $this->appId); $request->setField('client_secret', $this->appSecret); try { $this->client->send($request, $response); } catch (ClientException $ex) { throw new Exception\NetworkException($ex, $request, $response); } if ($response->getStatusCode() === 200) { return json_decode($response->getContent(), true); } throw new Exception\AuthException('Could not authenticate. Reason: ' . $response->getContent(), $response->getStatusCode()); }
/** * @param $referenceFull * * @return Response * * @throws MediaStorageClientApiException */ public function getMedia($referenceFull) { if (empty($referenceFull)) { throw new MediaStorageClientApiException('Param referenceFull is empty'); } try { $request = new FormRequest(); $request->setMethod(FormRequest::METHOD_GET); $request->setHost($this->getApiUrlConfig('base_url')); $url = $this->getApiUrlConfig('get_media_by_reference_full_url') . '/' . ltrim($referenceFull, '/'); $request->setResource($url); $this->logger->debug('Send ' . $this->getApiUrlConfig('base_url') . $url); /** @var Response $response */ $response = $this->client->send($request, null); $this->logger->debug('Response: ' . $response->getStatusCode() . ' ' . substr($response->getContent(), 0, 300)); } catch (\Exception $e) { throw new MediaStorageClientApiException($e->getMessage()); } return $response; }