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

Refactored Request to Method #140

Merged
merged 1 commit into from
Jan 10, 2023
Merged

Refactored Request to Method #140

merged 1 commit into from
Jan 10, 2023

Conversation

JamesFreeman
Copy link
Contributor

I need to be able to use the built-in Laravel HTTP Client instead of Guzzle, I don't want to override the whole handle method as there is a bunch of unrelated functionality there.

It would be nice to refactor the request into it's own method

@freekmurze freekmurze merged commit 0c4d4ea into spatie:main Jan 10, 2023
@freekmurze
Copy link
Member

Thanks!

@JamesFreeman JamesFreeman deleted the feature/refactor-request-to-method branch January 10, 2023 14:28
@JamesFreeman
Copy link
Contributor Author

Thanks for the quick merge, just for future reference, I've got the HTTP Client working with the following code:

namespace App\Jobs\Webhooks;

use GuzzleHttp\Psr7\Response;
use GuzzleHttp\TransferStats;
use Illuminate\Support\Facades\Http;
use Spatie\WebhookServer\CallWebhookJob as SpatieCallWebhookJob;

class CallWebhookJob extends SpatieCallWebhookJob
{
    protected ?TransferStats $transferStats = null;

    protected function createRequest(array $body): Response
    {
        return Http::timeout($this->requestTimeout)
            ->withHeaders($this->headers)
            ->withOptions([
                'verify' => $this->verifySsl,
                'on_stats' => function (TransferStats $stats) {
                    $this->transferStats = $stats;
                },
            ])
            ->{$this->httpVerb}($this->webhookUrl, $this->payload)
            ->toPsrResponse();
    }
}

I'm not sure why transferStatus are private, but I've just overridden that in my class. I also haven't wired in the proxy as I'm not using those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants