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

IPStackFinder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A get() 0 11 1
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