Skip to content

Commit 0c4d4ea

Browse files
authored
Merge pull request #140 from JamesFreeman/feature/refactor-request-to-method
Refactored Request to Method
2 parents 24b1652 + cd7a4e6 commit 0c4d4ea

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/CallWebhookJob.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,14 @@ class CallWebhookJob implements ShouldQueue
6464

6565
public function handle()
6666
{
67-
$client = $this->getClient();
68-
6967
$lastAttempt = $this->attempts() >= $this->tries;
7068

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

76-
$this->response = $client->request($this->httpVerb, $this->webhookUrl, array_merge([
77-
'timeout' => $this->requestTimeout,
78-
'verify' => $this->verifySsl,
79-
'headers' => $this->headers,
80-
'on_stats' => function (TransferStats $stats) {
81-
$this->transferStats = $stats;
82-
},
83-
], $body, is_null($this->proxy) ? [] : ['proxy' => $this->proxy]));
74+
$this->response = $this->createRequest($body);
8475

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

129+
protected function createRequest(array $body): Response
130+
{
131+
$client = $this->getClient();
132+
133+
return $client->request($this->httpVerb, $this->webhookUrl, array_merge([
134+
'timeout' => $this->requestTimeout,
135+
'verify' => $this->verifySsl,
136+
'headers' => $this->headers,
137+
'on_stats' => function (TransferStats $stats) {
138+
$this->transferStats = $stats;
139+
},
140+
], $body, is_null($this->proxy) ? [] : ['proxy' => $this->proxy]));
141+
}
142+
138143
protected function shouldBeRemovedFromQueue(): bool
139144
{
140145
return false;

0 commit comments

Comments
 (0)