Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
apirequest.php
1<?
2
4
12use COption;
13
15{
16 public const ACCESS_CODE = 'toloka_access_code';
17
21 public function __construct()
22 {
23 if (!Loader::includeModule('seo'))
24 {
25 throw new SystemException('Module seo not installed.');
26 }
27
28 if (!Service::isRegistered())
29 {
30 Service::register();
31 $this->registerOnCloudAdv();
32 }
33 $authorizeData = Service::getAuthorizeData(\Bitrix\Seo\Engine\Bitrix::ENGINE_ID, 'M');
34
35 $this->setAccessToken(COption::GetOptionString('sender', self::ACCESS_CODE));
36 $this->setClientId($authorizeData['client_id']);
37 $this->setClientSecret($authorizeData['client_secret']);
38 }
39
46 public function getTaskList($params = [])
47 {
48 $this->sendRequest(
49 [
50 'methodName' => 'project.list',
51 'pool_id' => $params['pool_id'] ?? 0,
52 'limit' => $params['limit'] ?? 10,
53 'status' => $params['status'] ?? 'ACTIVE',
54 'sort' => $params['sort'] ?? '-id',
55 ]
56 );
57
58 return $this->result;
59 }
60
67 public function getPoolList($params = [])
68 {
69 $this->sendRequest(
70 [
71 'methodName' => 'pool.list',
72 'parameters' => [
73 'project_id' => $params['project_id'] ?? 0,
74 'limit' => $params['limit'] ?? 10,
75 'sort' => $params['sort'] ?? '-id',
76 ]
77 ]
78 );
79
80 return $this->result;
81 }
82
89 public function getProjectList($params = [])
90 {
91 $this->sendRequest(
92 [
93 'methodName' => 'project.list',
94 'parameters' => [
95
96 'limit' => $params['limit'] ?? 10,
97 'status' => $params['status'] ?? 'ACTIVE',
98 'sort' => $params['sort'] ?? '-id',
99 ]
100 ]
101 );
102
103 return $this->result;
104 }
105
112 public function getGeoList($params = [])
113 {
114 $this->sendRequest(
115 [
116 'methodName' => 'geo.list',
117 'parameters' => [
118 'limit' => $params['limit'] ?? 10,
119 'regionType' => $params['regionType'] ?? 'all',
120 'lang' => strtoupper(LANGUAGE_ID),
121 'name' => $params['name'] ? ucfirst($params['name']): ''
122 ]
123 ]
124 );
125
126 return $this->result;
127 }
128
135 public function getProjectInfo($params = [])
136 {
137 $this->sendRequest(
138 [
139 'methodName' => 'project.info',
140 'id' => $params['id'] ?? 0,
141 ]
142 );
143
144 return $this->result;
145 }
146
153 public function createProject(Project $project)
154 {
155 $this->sendRequest(
156 [
157 'methodName' => 'project.create',
158 'parameters' => $project->toArray()
159 ]
160 );
161
162 return $this->result;
163 }
164
171 public function createPool(Pool $pool)
172 {
173 $this->sendRequest(
174 [
175 'methodName' => 'pool.create',
176 'parameters' => $pool->toArray()
177 ]
178 );
179
180 return $this->result;
181 }
182
189 public function editProject(Project $project)
190 {
191
192 $this->sendRequest(
193 [
194 'methodName' => 'project.edit',
195 'parameters' => array_merge(
196 ['id' => $project->getId()],
197 $project->toArray()
198 )
199 ]
200 );
201
202 return $this->result;
203 }
204
211 public function editPool(Pool $pool)
212 {
213 $this->sendRequest(
214 [
215 'methodName' => 'pool.edit',
216 'parameters' => array_merge(
217 ['id' => $pool->getId()],
218 $pool->toArray()
219 )
220 ]
221 );
222
223 return $this->result;
224 }
225
232 public function createTask(Task $task)
233 {
234 $this->sendRequest(
235 [
236 'methodName' => 'task.create',
237 'parameters' => $task->toArray()
238
239 ]
240 );
241
242 return $this->result;
243 }
244
251 public function createTaskSuite(TaskSuite $taskSuite)
252 {
253 $this->sendRequest(
254 [
255 'methodName' => 'task-suites.create',
256 'parameters' => $taskSuite->toArray()
257
258 ]
259 );
260
261 return $this->result;
262 }
263
264 public function getOperations()
265 {
266 $this->sendRequest(
267 [
268 'methodName' => 'operations.list'
269 ]
270 );
271
272 return $this->result;
273 }
274
281 public function createTasks(array $taskList)
282 {
283 $tasks = [];
284 foreach ($taskList as $item)
285 {
286 $tasks[] = $item->toArray();
287 }
288
289 $this->sendRequest(
290 [
291 'methodName' => 'task.create',
292 'parameters' => $tasks
293 ]
294 );
295
296 return $this->result;
297 }
298
305 public function stopTaskSuite(string $suiteId)
306 {
307 $this->sendRequest(
308 [
309 'methodName' => 'task-suites.stop',
310 'parameters' => [
311 'id' => $suiteId,
312 'overlap' => 0
313 ]
314 ]
315 );
316
317 return $this->result;
318 }
319
326 public function deleteTasks(int $poolId)
327 {
328 $this->sendRequest(
329 [
330 'methodName' => 'task.delete',
331 'parameters' => [
332 'id' => $poolId
333 ]
334 ]
335 );
336
337 return $this->result;
338 }
339
346 public function openPool($poolId)
347 {
348 $this->sendRequest(
349 [
350 'methodName' => 'pool.open',
351 'id' => $poolId
352 ]
353 );
354
355 return $this->result;
356 }
357
364 public function closePool($poolId)
365 {
366 $this->sendRequest(
367 [
368 'methodName' => 'pool.close',
369 'parameters' => [
370 'id' => $poolId
371 ]
372 ]
373 );
374
375 return $this->result;
376 }
377
378 function getScope(): string
379 {
380 return 'seo.client.toloka.';
381 }
382}