Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
15 / 15 |
WSUrl | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
15 / 15 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
get | |
100.00% |
1 / 1 |
5 | |
100.00% |
13 / 13 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\ApiExternal\Services\Adserving; |
4 | |
5 | use Qmp\Laravel\CDNApi\Cdn\KeyCDNProvider\KeyCDN; |
6 | use Qmp\Laravel\MicroService\Client\Tools\Request as ClientRequest; |
7 | use Qmp\Laravel\MicroService\Client\Client; |
8 | |
9 | class WSUrl |
10 | { |
11 | protected $data; |
12 | |
13 | public function __construct(Data $data) |
14 | { |
15 | $this->data = $data; |
16 | } |
17 | |
18 | public function get() |
19 | { |
20 | $response = $this->data->service(Data::SERVICE_ADSERVING_LOCATE); |
21 | |
22 | // Check $response |
23 | if (!isset($response->content['link_url']) || !isset($response->content['link_img'])) { |
24 | $this->data->debugData('Error on adserving service :', [ |
25 | 'response' => $response->content |
26 | ]); |
27 | abort(410, "Gone"); |
28 | } |
29 | |
30 | if ($this->data->type === Data::URL) { |
31 | $url = $response->content['link_url']; |
32 | } else { |
33 | $prefixUrl = config('app.env') === 'production' ? 'https://' . KeyCDN::PLATFORM_V3 : env('APP_CDN_MIRROR_URL', 'https://cdn-mirror-digital.advertise-me.net'); |
34 | $url = $prefixUrl . $response->content['link_img']; |
35 | } |
36 | |
37 | $this->data->debugData('Success adserving service :', [ |
38 | 'url' => $url, |
39 | 'distance' => ($response->content['distance'] ?? null) |
40 | ]); |
41 | |
42 | return $url; |
43 | } |
44 | } |