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