CheckCampaignsChange.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace App\Service\Requests\Direct;
use App\Jobs\ProcessCallLimitedAPI;
use App\Models\Campaigns;
use App\Service\API\API;
use App\Service\Requests\APIRequest;
use App\Service\Requests\DirectRequest;
class CheckCampaignsChange extends DirectRequest {
CONST SELF = 'SELF';
CONST CHILDREN = 'CHILDREN';
CONST STAT = 'STAT';
protected $next;
function call($params = null){
$this->requestPrepare($params);
$process = new ProcessCallLimitedAPI($this);
dispatch($process)->onQueue('limits');
}
function handle($response){
foreach ($response['result']['Campaigns'] as $campaign){
if ($campaign['ChangesIn']==self::SELF || $campaign['ChangesIn']==self::CHILDREN){
Campaigns::firstOrCreate([
'external_id' => $campaign['CampaignId']
],
[
'updated' => $campaign['ChangesIn']
]);
}
}
$this->getToken()->timestamp = $response['result']['Timestamp'];
$this->getToken()->save();
}
private function requestPrepare($params){
$this->setService('changes');
$this->setMethod('checkDictionaries');
$this->setParams([
"Timestamp" => $this->getToken()->timestamp
]);
}
}