Completed
Push — master ( 440b93...a38dd7 )
by Ari
01:04
created

IPStackFinder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Arimolzer\IPStackFinder;
4
5
use GuzzleHttp\Client;
6
7
/**
8
 * Class IPStackFinder
9
 * @package Arimolzer\IPStackFinder
10
 */
11
class IPStackFinder
12
{
13
    /** @var string */
14
    const BASE_URI = 'http://api.ipstack.com/';
15
16
    /** @var Client $client */
17
    public $client;
18
19
    /** @var array $supportedLanguages */
20
    private $supportedLanguages = [
21
        'en',    // English/US
22
        'de',    // German
23
        'es',    // Spanish
24
        'fr',    // French
25
        'ja',    // Japanese
26
        'pt-br', // Portugues (Brazil)
27
        'ru',    // Russian
28
        'zh',    // Chinese
29
    ];
30
31
    /**
32
     * IPStackHelper constructor.
33
     */
34
    public function __construct()
35
    {
36
        $this->client = new Client([
37
            'base_uri' => self::BASE_URI,
38
            'query' => [
39
                'access_key' => config('ipstack-finder.api_key'),
40
                'language' => config('ipstack-finder.default_language')
41
            ]
42
        ]);
43
    }
44
45
    /**
46
     * @param $ipAddress
47
     * @return array
48
     * @throws \GuzzleHttp\Exception\GuzzleException
49
     */
50
    public function get($ipAddress) : array
51
    {
52
        /** @var string $responseJson */
53
        $responseJson = $this->client
54
            ->request('GET', $ipAddress)
55
            ->getBody()
56
            ->getContents();
57
58
        /** @var array */
59
        return json_decode($responseJson, true);
60
    }
61
}
62