Skip to content

Commit

Permalink
Merge pull request #140 from JamesFreeman/feature/refactor-request-to…
Browse files Browse the repository at this point in the history
…-method

Refactored Request to Method
  • Loading branch information
freekmurze authored Jan 10, 2023
2 parents 24b1652 + cd7a4e6 commit 0c4d4ea
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/CallWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,14 @@ class CallWebhookJob implements ShouldQueue

public function handle()
{
$client = $this->getClient();

$lastAttempt = $this->attempts() >= $this->tries;

try {
$body = strtoupper($this->httpVerb) === 'GET'
? ['query' => $this->payload]
: ['body' => json_encode($this->payload)];

$this->response = $client->request($this->httpVerb, $this->webhookUrl, array_merge([
'timeout' => $this->requestTimeout,
'verify' => $this->verifySsl,
'headers' => $this->headers,
'on_stats' => function (TransferStats $stats) {
$this->transferStats = $stats;
},
], $body, is_null($this->proxy) ? [] : ['proxy' => $this->proxy]));
$this->response = $this->createRequest($body);

if (! Str::startsWith($this->response->getStatusCode(), 2)) {
throw new Exception('Webhook call failed');
Expand Down Expand Up @@ -135,6 +126,20 @@ protected function getClient(): ClientInterface
return app(Client::class);
}

protected function createRequest(array $body): Response
{
$client = $this->getClient();

return $client->request($this->httpVerb, $this->webhookUrl, array_merge([
'timeout' => $this->requestTimeout,
'verify' => $this->verifySsl,
'headers' => $this->headers,
'on_stats' => function (TransferStats $stats) {
$this->transferStats = $stats;
},
], $body, is_null($this->proxy) ? [] : ['proxy' => $this->proxy]));
}

protected function shouldBeRemovedFromQueue(): bool
{
return false;
Expand Down

0 comments on commit 0c4d4ea

Please sign in to comment.