public function getModel($make, $model, array $options = []) { $resolver = new OptionsResolver(); $resolver->setDefaults(['year' => 1990, 'view' => 'basic']); $resolver->setDefined('state'); $resolver->setRequired(['state', 'view']); $resolver->setAllowedTypes('year', 'integer'); $resolver->setAllowedValues('state', ['new', 'used']); $resolver->setDefault('state', function (Options $options, $previousValue) { if ($options['year'] >= 2015) { return 'new'; } return $previousValue; }); // $resolver->isDefined('state'); $options = $resolver->resolve($options); $client = new GuzzleHttp\Client(); $queryParams = array_merge($options, ['fmt' => 'json', 'api_key' => $this->apiKey]); $query = GuzzleHttp\Psr7\build_query($queryParams); $request = new GuzzleHttp\Psr7\Request('GET', $this->apiEndpoint . $make . '/' . $model . '?' . $query); /** @var ResponseInterface $response */ $response = $client->send($request); if ($this->dispatcher) { $this->dispatcher->dispatch(ApiCallEvent::EVENT_NAME, new GenericEvent($this, ['make' => $make, 'model' => $model, 'options' => $options])); } return $this->delegatingSerializer->deserialize($response->getBody(), 'json', ['type' => 'array']); }
public function getMakes($state, $year, $view = 'full') { $client = new GuzzleHttp\Client(); $query = GuzzleHttp\Psr7\build_query(['api_key' => $this->apiKey, 'state' => $state, 'year' => $year, 'view' => $view, 'fmt' => 'json']); /** @var ResponseInterface $result */ $result = $client->request('GET', $this->apiEndpoint . self::API_METHOD . '?' . $query); if ($this->logger) { $this->logger->log(LogLevel::INFO, sprintf('Makes response : %s', $result->getBody())); } if ($this->dispatcher) { $this->dispatcher->dispatch(ApiCallEvent::EVENT_NAME, new GenericEvent($this, ['state' => $state, 'year' => $year, 'view' => $view])); } return $this->delegatingSerializer->deserialize((string) $result->getBody(), 'json', ['type' => 'array']); }