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