| Total Complexity | 7 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class Api |
||
| 8 | { |
||
| 9 | protected string $key; |
||
| 10 | |||
| 11 | protected Client $client; |
||
| 12 | |||
| 13 | public string $format; |
||
| 14 | |||
| 15 | public function __construct( |
||
| 16 | string $apiKey, |
||
| 17 | string $format = 'php_serial', |
||
| 18 | string $endpoint = 'https://api.flickr.com/services/rest/' |
||
| 19 | ) { |
||
| 20 | $this->key = $apiKey; |
||
| 21 | $this->format = $format; |
||
| 22 | |||
| 23 | $this->client = new Client([ |
||
| 24 | 'base_uri' => $endpoint, |
||
| 25 | ]); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function request(string $call, ?array $parameters = null) |
||
| 29 | { |
||
| 30 | $guzzleResponse = $this->client->get($this->api().'&method='.$call.$this->parameters($parameters)); |
||
|
|
|||
| 31 | |||
| 32 | if ($guzzleResponse->getStatusCode() === 200) { |
||
| 33 | return new Response($guzzleResponse); |
||
| 34 | } |
||
| 35 | |||
| 36 | return 'Failed request'; |
||
| 37 | } |
||
| 38 | |||
| 39 | protected function api(): string |
||
| 40 | { |
||
| 41 | return '?api_key='.$this->key.'&format='.$this->format; |
||
| 42 | } |
||
| 43 | |||
| 44 | protected function parameters(array $array): string |
||
| 57 | } |
||
| 58 | } |
||
| 59 |