Completed
Push — master ( 5e7012...84911a )
by Vladimir
02:39
created

Api   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findDriver() 0 4 1
A getDrivers() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation;
6
7
use FondBot\FondBot;
8
use GuzzleHttp\Client;
9
use Illuminate\Support\Collection;
10
11
class Api
12
{
13
    public const URL = 'https://api.fondbot.io';
14
15
    private $client;
16
17
    public function __construct(Client $client)
18
    {
19
        $this->client = $client;
20
    }
21
22
    /**
23
     * Get all available drivers.
24
     *
25
     * @return Collection
26
     */
27
    public function getDrivers(): Collection
28
    {
29
        $response = $this->client->get(self::URL.'/drivers', ['json' => ['version' => FondBot::VERSION]]);
30
31
        return collect(json_decode((string) $response->getBody(), true));
32
    }
33
34
    /**
35
     * Find driver by name.
36
     *
37
     * @param string $name
38
     *
39
     * @return array|null
40
     */
41
    public function findDriver(string $name): ?array
42
    {
43
        return $this->getDrivers()->first(function ($item) use ($name) {
44
            return $item['name'] === $name;
45
        });
46
    }
47
}
48