Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
apirequest.php
1
<?
2
3
namespace
Bitrix\Sender\Integration\Yandex\Toloka
;
4
5
use
Bitrix\Main\Loader
;
6
use
Bitrix\Main\SystemException
;
7
use
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Pool
;
8
use
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Project
;
9
use
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Task
;
10
use
Bitrix\Sender\Integration\Yandex\Toloka\DTO\TaskSuite
;
11
use
Bitrix\Seo\Service
;
12
use COption;
13
14
class
ApiRequest
extends
BaseApiObject
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
}
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest
Definition
apirequest.php:15
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\createTask
createTask(Task $task)
Definition
apirequest.php:232
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\__construct
__construct()
Definition
apirequest.php:21
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\getScope
getScope()
Definition
apirequest.php:378
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\createProject
createProject(Project $project)
Definition
apirequest.php:153
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\getGeoList
getGeoList($params=[])
Definition
apirequest.php:112
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\createPool
createPool(Pool $pool)
Definition
apirequest.php:171
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\createTasks
createTasks(array $taskList)
Definition
apirequest.php:281
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\editProject
editProject(Project $project)
Definition
apirequest.php:189
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\getOperations
getOperations()
Definition
apirequest.php:264
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\deleteTasks
deleteTasks(int $poolId)
Definition
apirequest.php:326
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\closePool
closePool($poolId)
Definition
apirequest.php:364
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\openPool
openPool($poolId)
Definition
apirequest.php:346
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\stopTaskSuite
stopTaskSuite(string $suiteId)
Definition
apirequest.php:305
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\getProjectList
getProjectList($params=[])
Definition
apirequest.php:89
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\editPool
editPool(Pool $pool)
Definition
apirequest.php:211
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\getProjectInfo
getProjectInfo($params=[])
Definition
apirequest.php:135
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\createTaskSuite
createTaskSuite(TaskSuite $taskSuite)
Definition
apirequest.php:251
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\ACCESS_CODE
const ACCESS_CODE
Definition
apirequest.php:16
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\getTaskList
getTaskList($params=[])
Definition
apirequest.php:46
Bitrix\Sender\Integration\Yandex\Toloka\ApiRequest\getPoolList
getPoolList($params=[])
Definition
apirequest.php:67
Bitrix\Sender\Integration\Yandex\Toloka\BaseApiObject
Definition
baseapiobject.php:22
Bitrix\Sender\Integration\Yandex\Toloka\BaseApiObject\$result
$result
Definition
baseapiobject.php:24
Bitrix\Sender\Integration\Yandex\Toloka\BaseApiObject\setClientSecret
setClientSecret($clientSecret)
Definition
baseapiobject.php:101
Bitrix\Sender\Integration\Yandex\Toloka\BaseApiObject\sendRequest
sendRequest($data=[])
Definition
baseapiobject.php:108
Bitrix\Sender\Integration\Yandex\Toloka\BaseApiObject\setClientId
setClientId($clientId)
Definition
baseapiobject.php:81
Bitrix\Sender\Integration\Yandex\Toloka\BaseApiObject\registerOnCloudAdv
registerOnCloudAdv()
Definition
baseapiobject.php:126
Bitrix\Sender\Integration\Yandex\Toloka\BaseApiObject\setAccessToken
setAccessToken($accessToken)
Definition
baseapiobject.php:61
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Pool
Definition
pool.php:6
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Pool\getId
getId()
Definition
pool.php:294
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Pool\toArray
toArray()
Definition
pool.php:351
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Project
Definition
project.php:6
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Project\getId
getId()
Definition
project.php:171
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Project\toArray
toArray()
Definition
project.php:228
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Task
Definition
task.php:6
Bitrix\Sender\Integration\Yandex\Toloka\DTO\Task\toArray
toArray()
Definition
task.php:126
Bitrix\Sender\Integration\Yandex\Toloka\DTO\TaskSuite
Definition
tasksuite.php:6
Bitrix\Sender\Integration\Yandex\Toloka\DTO\TaskSuite\toArray
toArray()
Definition
tasksuite.php:83
Bitrix\Seo\Service
Definition
service.php:33
Bitrix\Sender\Integration\Yandex\Toloka
Definition
apirequest.php:3
Bitrix
modules
sender
lib
integration
yandex
toloka
apirequest.php
Создано системой
1.10.0