Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 16 |
SiteGenerator | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 16 |
createSite | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
updateSite | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
createSponsorWebservice | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
createOfferPlanning | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
getSiteData | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 12 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\ApiDigitalV2\Api\Traits; |
4 | |
5 | use Qmp\Laravel\SiteGeneratorDetail\Models\Site; |
6 | |
7 | trait SiteGenerator |
8 | { |
9 | /** |
10 | * Create site data on digitalv2 api |
11 | * |
12 | * @param Site $site |
13 | * @return mixed |
14 | * @throws \Exception |
15 | */ |
16 | public function createSite(Site $site) |
17 | { |
18 | return $this->jsonRequest('POST', 'site-generator/site', $this->getSiteData($site)); |
19 | } |
20 | |
21 | /** |
22 | * update site data on digitalv2 api |
23 | * |
24 | * @param Site $site |
25 | * @return mixed |
26 | * @throws \Exception |
27 | */ |
28 | public function updateSite(Site $site) |
29 | { |
30 | return $this->jsonRequest('PUT', 'site-generator/site', $this->getSiteData($site)); |
31 | } |
32 | |
33 | /** |
34 | * Create webservice on Digital v2 |
35 | * @param $id |
36 | * @param $id_offer |
37 | * @return mixed |
38 | * @throws \Exception |
39 | */ |
40 | public function createSponsorWebservice($id, $id_offer) |
41 | { |
42 | return $this->jsonRequest('POST', 'site-generator/site/ws', ['id' => $id, 'id_offer' => $id_offer]); |
43 | } |
44 | |
45 | /** |
46 | * Create webservice on Digital v2 |
47 | * @param $id |
48 | * @param $blockId |
49 | * @return mixed |
50 | * @throws \Exception |
51 | */ |
52 | public function createOfferPlanning($id, $blockId) |
53 | { |
54 | return $this->jsonRequest('POST', 'site-generator/site/planning', ['id' => $id, 'blockId' => $blockId]); |
55 | } |
56 | |
57 | /** |
58 | * Necessary data for create or update site on digital v2 api |
59 | * |
60 | * @param Site $site |
61 | * @return array |
62 | */ |
63 | private function getSiteData(Site $site) |
64 | { |
65 | $offers = collect($site->dotGet('config.sponsorsList')) |
66 | ->filter(function ($offer) { |
67 | return !isset($offer['ws']); |
68 | }) |
69 | ->pluck('id') |
70 | ->toArray(); |
71 | |
72 | return [ |
73 | 'id' => $site->id, |
74 | 'text' => $site->text, |
75 | 'url' => $site->config['domain']['text'], |
76 | 'blocks' => $site->blocks, |
77 | 'offers' => $offers, |
78 | 'visuals' => $site->offers |
79 | ]; |
80 | } |
81 | |
82 | |
83 | } |