1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Crowdin API implementation in PHP. |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2016 Nikolai Plath (elkuku) |
6
|
|
|
* @license WTFPL - See license.txt |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace ElKuKu\Crowdin\Package; |
10
|
|
|
|
11
|
|
|
use ElKuKu\Crowdin\ |
12
|
|
|
{ |
13
|
|
|
Languageproject, Package |
14
|
|
|
}; |
15
|
|
|
|
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Project |
20
|
|
|
* |
21
|
|
|
* @since 1.0.5 |
22
|
|
|
*/ |
23
|
|
|
Class Project extends Package |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Create Crowdin project. |
27
|
|
|
* |
28
|
|
|
* @param string $login The user login. |
29
|
|
|
* @param string $accountKey The user account key. |
30
|
|
|
* @param Languageproject $project The project object. |
31
|
|
|
* |
32
|
|
|
* @see https://crowdin.com/page/api/create-project |
33
|
|
|
* @since 1.0.7 |
34
|
|
|
* |
35
|
|
|
* @return ResponseInterface |
36
|
|
|
*/ |
37
|
1 |
|
public function create(string $login, string $accountKey, Languageproject $project) : ResponseInterface |
38
|
|
|
{ |
39
|
1 |
|
$path = 'account/create-project?account-key=' . $accountKey; |
40
|
|
|
|
41
|
1 |
|
$params = $project->toQuery(); |
42
|
|
|
|
43
|
1 |
|
$params[] = [ |
44
|
1 |
|
'name' => 'login', |
45
|
1 |
|
'contents' => $login |
46
|
|
|
]; |
47
|
|
|
|
48
|
1 |
|
return $this->getHttpClient() |
49
|
1 |
|
->post($path, ['multipart' => $params]); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Edit Crowdin project. |
54
|
|
|
* |
55
|
|
|
* @param Languageproject $project The language project object. |
56
|
|
|
* |
57
|
|
|
* @see https://crowdin.com/page/api/edit-project |
58
|
|
|
* @since 1.0.7 |
59
|
|
|
* |
60
|
|
|
* @return ResponseInterface |
61
|
|
|
*/ |
62
|
1 |
|
public function edit(Languageproject $project) : ResponseInterface |
63
|
|
|
{ |
64
|
1 |
|
$project->identifier = null; |
65
|
1 |
|
$project->source_language = null; |
66
|
|
|
|
67
|
1 |
|
return $this->getHttpClient() |
68
|
1 |
|
->post($this->getBasePath('edit-project'), ['multipart' => $project->toQuery()]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get Crowdin Project details. |
73
|
|
|
* |
74
|
|
|
* @param string $login Your Crowdin Account login name. |
75
|
|
|
* @param string $accountKey Account API key (profile settings -> "API & SSO" tab). |
76
|
|
|
* |
77
|
|
|
* @see https://crowdin.com/page/api/get-projects |
78
|
|
|
* @since 1.0.7 |
79
|
|
|
* |
80
|
|
|
* @return ResponseInterface |
81
|
|
|
*/ |
82
|
1 |
|
public function getList(string $login, string $accountKey) : ResponseInterface |
83
|
|
|
{ |
84
|
1 |
|
$path = sprintf( |
85
|
1 |
|
'account/get-projects?account-key=%s&login=%s', |
86
|
1 |
|
$accountKey, |
87
|
1 |
|
$login |
88
|
|
|
); |
89
|
|
|
|
90
|
1 |
|
return $this->getHttpClient() |
91
|
1 |
|
->post($path); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get Crowdin Project details. |
96
|
|
|
* |
97
|
|
|
* @since 1.0.5 |
98
|
|
|
* @see https://crowdin.com/page/api/info |
99
|
|
|
* |
100
|
|
|
* @return ResponseInterface |
101
|
|
|
*/ |
102
|
1 |
|
public function getInfo() : ResponseInterface |
103
|
|
|
{ |
104
|
1 |
|
return $this->getHttpClient() |
105
|
1 |
|
->post($this->getBasePath('info')); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Delete Crowdin project with all translations. |
110
|
|
|
* |
111
|
|
|
* @since 1.0.5 |
112
|
|
|
* @see https://crowdin.com/page/api/delete-project |
113
|
|
|
* |
114
|
|
|
* @return ResponseInterface |
115
|
|
|
*/ |
116
|
1 |
|
public function delete() : ResponseInterface |
117
|
|
|
{ |
118
|
1 |
|
return $this->getHttpClient() |
119
|
1 |
|
->get($this->getBasePath('delete-project')); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|