Completed
Push — fix-checkstyle ( 525678...700890 )
by
unknown
03:06
created

Client::getHttpClient()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Akeneo\Crowdin;
4
5
use \InvalidArgumentException;
6
use Guzzle\Http\Client as HttpClient;
7
8
/**
9
 * Simple Crowdin PHP client
10
 *
11
 * @author Nicolas Dupont <[email protected]>
12
 */
13
class Client
14
{
15
    /** @var string base url */
16
    const BASE_URL = 'http://api.crowdin.net/api';
17
18
    /** @var HttpClient */
19
    protected $httpClient;
20
21
    /** @var string the project identifier */
22
    protected $projectIdentifier;
23
24
    /** @var string the project api key */
25
    protected $projectApiKey;
26
27
    /**
28
     * Instantiate a new Crowdin Client
29
     *
30
     * @param string $identifier the project identifier
31
     * @param string $apiKey     the project api key
32
     */
33
    public function __construct($identifier, $apiKey)
34
    {
35
        $this->projectIdentifier = $identifier;
36
        $this->projectApiKey     = $apiKey;
37
    }
38
39
    /**
40
     * @param string $method the api method
41
     *
42
     * @throws InvalidArgumentException
43
     *
44
     * @return mixed
45
     */
46
    public function api($method)
47
    {
48
        switch ($method) {
49
            case 'info':
50
                $api = new Api\Info($this);
51
                break;
52
            case 'supported-languages':
53
                $api = new Api\SupportedLanguages($this);
54
                break;
55
            case 'status':
56
                $api = new Api\Status($this);
57
                break;
58
            case 'download':
59
                $api = new Api\Download($this);
60
                break;
61
            case 'add-file':
62
                $api = new Api\AddFile($this);
63
                break;
64
            case 'update-file':
65
                $api = new Api\UpdateFile($this);
66
                break;
67
            case 'delete-file':
68
                $api = new Api\DeleteFile($this);
69
                break;
70
            case 'export':
71
                $api = new Api\Export($this);
72
                break;
73
            case 'add-directory':
74
                $api = new Api\AddDirectory($this);
75
                break;
76
            case 'delete-directory':
77
                $api = new Api\DeleteDirectory($this);
78
                break;
79
            case 'upload-translation':
80
                $api = new Api\UploadTranslation($this);
81
                break;
82
            default:
83
                throw new InvalidArgumentException(sprintf('Undefined api method "%s"', $method));
84
        }
85
86
        return $api;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getProjectIdentifier()
93
    {
94
        return $this->projectIdentifier;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getProjectApiKey()
101
    {
102
        return $this->projectApiKey;
103
    }
104
105
    /**
106
     * @return HttpClient
107
     */
108
    public function getHttpClient()
109
    {
110
        if ($this->httpClient === null) {
111
            $this->httpClient = new HttpClient(self::BASE_URL);
112
        }
113
114
        return $this->httpClient;
115
    }
116
}
117