Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add http request options #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/WebhookChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ public function send($notifiable, Notification $notification)

$webhookData = $notification->toWebhook($notifiable)->toArray();

$response = $this->client->post($url, [
'query' => Arr::get($webhookData, 'query'),
'body' => json_encode(Arr::get($webhookData, 'data')),
'verify' => Arr::get($webhookData, 'verify'),
'headers' => Arr::get($webhookData, 'headers'),
]);
$response = $this->client->post($url, array_merge(
[
'query' => Arr::get($webhookData, 'query'),
'body' => json_encode(Arr::get($webhookData, 'data')),
'verify' => Arr::get($webhookData, 'verify'),
'headers' => Arr::get($webhookData, 'headers'),
],
Arr::get($webhookData, 'http')
));

if ($response->getStatusCode() >= 300 || $response->getStatusCode() < 200) {
throw CouldNotSendNotification::serviceRespondedWithAnError($response);
Expand Down
22 changes: 22 additions & 0 deletions src/WebhookMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class WebhookMessage
*/
protected $verify = false;


/**
* Additional request options for the Guzzle HTTP client.
*
* @var array
*/
protected $http = [];

/**
* @param mixed $data
*
Expand Down Expand Up @@ -126,6 +134,19 @@ public function verify($value = true)
return $this;
}

/**
* Set additional request options for the Guzzle HTTP client.
*
* @param array $options
* @return $this
*/
public function http(array $options)
{
$this->http = $options;

return $this;
}

/**
* @return array
*/
Expand All @@ -136,6 +157,7 @@ public function toArray()
'data' => $this->data,
'headers' => $this->headers,
'verify' => $this->verify,
'http' => $this->http,
];
}
}
7 changes: 7 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,11 @@ public function it_can_verify_the_request()
$this->message->verify();
$this->assertEquals(true, Arr::get($this->message->toArray(), 'verify'));
}

/** @test */
public function it_can_add_request_options()
{
$this->message->http(['timeout' => 3.14]);
$this->assertEquals(3.14, Arr::get($this->message->toArray(), 'http.timeout'));
}
}