diff --git a/src/LaravelSendy.php b/src/LaravelSendy.php index d75fa91..5dd50c2 100644 --- a/src/LaravelSendy.php +++ b/src/LaravelSendy.php @@ -80,16 +80,17 @@ protected function guzzle(string $type, string $request, array $data = [], array $mainHeaders = [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', - 'Authorization' => 'Bearer '.$this->apiKey, ]; $headers = is_array($headers) && count($headers) > 0 ? array_merge($mainHeaders, $headers) : $mainHeaders; - $response = $client->$type($this->apiUrl.$request, [ + $response = $client->{$type}($this->apiUrl.$request, [ 'headers' => $headers, - 'body' => json_encode($data), + 'body' => json_encode(array_merge($data, [ + 'api_key' => $this->apiKey, + ])), ]); $responseObject = $response->getBody()->getContents(); diff --git a/src/Resources/Campaigns.php b/src/Resources/Campaigns.php index 6338fb0..3d2f861 100644 --- a/src/Resources/Campaigns.php +++ b/src/Resources/Campaigns.php @@ -9,10 +9,7 @@ class Campaigns { public function create(array $data) { - $data = CompaignDTO::from($data)->toArray(); - - // validate the data - // $this->validate($data); + $data = CompaignDTO::validateAndCreate($data)->toArray(); return LaravelSendy::post('/api/campaigns/create.php', $data); } diff --git a/src/Resources/Subscribers.php b/src/Resources/Subscribers.php index 382b322..10879de 100644 --- a/src/Resources/Subscribers.php +++ b/src/Resources/Subscribers.php @@ -9,9 +9,7 @@ class Subscribers { public function subscribe(array $data) { - $data = SubscribersDTO::from($data)->toArray(); - - // validate the data + $data = SubscribersDTO::validateAndCreate($data)->toArray(); return LaravelSendy::post('subscribe', $data); }