/** * Create the request object and send it out to listening events. * * @param $path * @param $method * @param array $parameters * @param array $headers * @param null $body * @return string */ private function send($path, $method, array $parameters = [], array $headers = [], $body = null) { $request = $this->createRequest($path, $method, $parameters, $headers, $body); $event = new RequestEvent($request); $this->eventDispatcher->dispatch(TmdbEvents::REQUEST, $event); $this->lastResponse = $event->getResponse(); if ($this->lastResponse instanceof Response) { return (string) $this->lastResponse->getBody(); } return []; }
/** * Create the unified exception to throw * * @param Request $request * @param Response $response * @return TmdbApiException */ protected function createApiException(Request $request, Response $response) { $errors = json_decode((string) $response->getBody()); return new TmdbApiException($errors->status_code, $errors->status_message, $request, $response); }