Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
10 / 10 |
| Campaigns | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
10 / 10 |
| getEntityCampaigns | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
| manageEntityCampaigns | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\Entities\Services\Campaigns; |
| 4 | |
| 5 | use Illuminate\Support\Str; |
| 6 | use Qmp\Laravel\Entities\Models\Entity; |
| 7 | use Qmp\Laravel\MicroService\Client\Client; |
| 8 | use Qmp\Laravel\MicroService\Client\Tools\Request as ClientRequest; |
| 9 | |
| 10 | class Campaigns |
| 11 | { |
| 12 | const SERVICE_NAME = 'service_campaigns'; |
| 13 | |
| 14 | /** |
| 15 | * Get all campaigns for one entity |
| 16 | * |
| 17 | * @param Entity $entity |
| 18 | * @return mixed|null |
| 19 | * @throws \Exception |
| 20 | */ |
| 21 | public static function getEntityCampaigns(Entity $entity) |
| 22 | { |
| 23 | $request = ClientRequest::createObject(self::SERVICE_NAME, 'get-entity-campaigns/' . $entity->id); |
| 24 | $response = Client::systemSend('get', $request); |
| 25 | |
| 26 | if(!Str::startsWith($response->code, '2')) { |
| 27 | throw new \Exception('Unable to get entity campaign'); |
| 28 | } |
| 29 | |
| 30 | return $response->content; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Manage relationships entity campaign on service-campaigns-laravel |
| 35 | * |
| 36 | * @param array $data |
| 37 | * @return mixed|null |
| 38 | * @throws \Exception |
| 39 | */ |
| 40 | public static function manageEntityCampaigns(array $data) |
| 41 | { |
| 42 | $request = ClientRequest::createObject(self::SERVICE_NAME, 'manage-entites', [ 'body' => $data]); |
| 43 | $response = Client::systemSend('post', $request); |
| 44 | |
| 45 | if(!Str::startsWith($response->code, '2')) { |
| 46 | throw new \Exception('Unable to manage entities'); |
| 47 | } |
| 48 | |
| 49 | return $response->content; |
| 50 | } |
| 51 | |
| 52 | } |