Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Mar 18, 2020
1 parent 4ebb7f8 commit ca8dbd3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-webhook-server` will be documented in this file

## 1.8.0 - 2020-03-18

- add `uuid`

## 1.7.0 - 2020-03-05

- add `dispatchNow` (#39)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ All these events have these properties:
- `tags`: the array of [tags](#adding-tags) used
- `attempt`: the attempt number
- `response`: the response returned by the remote app. Can be an instance of `\GuzzleHttp\Psr7\Response` or `null`.
- `uuid`: a unique string to identify this call. This uuid will be the same for all attempts of a webhook call.

## Testing

Expand Down
5 changes: 4 additions & 1 deletion src/CallWebhookJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CallWebhookJob implements ShouldQueue

public array $tags = [];

public string $uuid = '';

private ?Response $response = null;

private ?string $errorType = null;
Expand Down Expand Up @@ -121,7 +123,8 @@ private function dispatchEvent(string $eventClass)
$this->attempts(),
$this->response,
$this->errorType,
$this->errorMessage
$this->errorMessage,
$this->uuid
));
}
}
6 changes: 5 additions & 1 deletion src/Events/WebhookCallEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ abstract class WebhookCallEvent

public ?string $errorMessage;

public string $uuid;

public function __construct(
string $httpVerb,
string $webhookUrl,
Expand All @@ -36,7 +38,8 @@ public function __construct(
int $attempt,
?Response $response,
?string $errorType,
?string $errorMessage
?string $errorMessage,
string $uuid
) {
$this->httpVerb = $httpVerb;
$this->webhookUrl = $webhookUrl;
Expand All @@ -48,5 +51,6 @@ public function __construct(
$this->response = $response;
$this->errorType = $errorType;
$this->errorMessage = $errorMessage;
$this->uuid = $uuid;
}
}
39 changes: 25 additions & 14 deletions src/WebhookCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\WebhookServer;

use Illuminate\Support\Str;
use Spatie\WebhookServer\BackoffStrategy\BackoffStrategy;
use Spatie\WebhookServer\Exceptions\CouldNotCallWebhook;
use Spatie\WebhookServer\Exceptions\InvalidBackoffStrategy;
Expand All @@ -12,6 +13,8 @@ class WebhookCall
{
protected CallWebhookJob $callWebhookJob;

protected string $uuid = '';

protected string $secret;

protected Signer $signer;
Expand All @@ -25,6 +28,7 @@ public static function create(): self
$config = config('webhook-server');

return (new static())
->uuid(Str::uuid())
->onQueue($config['queue'])
->useHttpVerb($config['http_verb'])
->maximumTries($config['tries'])
Expand All @@ -41,14 +45,14 @@ public function __construct()
$this->callWebhookJob = app(CallWebhookJob::class);
}

public function url(string $url)
public function url(string $url): self
{
$this->callWebhookJob->webhookUrl = $url;

return $this;
}

public function payload(array $payload)
public function payload(array $payload): self
{
$this->payload = $payload;

Expand All @@ -57,35 +61,42 @@ public function payload(array $payload)
return $this;
}

public function onQueue(string $queue)
public function uuid(string $uuid): self
{
$this->uuid = $uuid;

return $this;
}

public function onQueue(string $queue): self
{
$this->callWebhookJob->queue = $queue;

return $this;
}

public function useSecret(string $secret)
public function useSecret(string $secret): self
{
$this->secret = $secret;

return $this;
}

public function useHttpVerb(string $verb)
public function useHttpVerb(string $verb): self
{
$this->callWebhookJob->httpVerb = $verb;

return $this;
}

public function maximumTries(int $tries)
public function maximumTries(int $tries): self
{
$this->callWebhookJob->tries = $tries;

return $this;
}

public function useBackoffStrategy(string $backoffStrategyClass)
public function useBackoffStrategy(string $backoffStrategyClass): self
{
if (! is_subclass_of($backoffStrategyClass, BackoffStrategy::class)) {
throw InvalidBackoffStrategy::doesNotExtendBackoffStrategy($backoffStrategyClass);
Expand All @@ -96,14 +107,14 @@ public function useBackoffStrategy(string $backoffStrategyClass)
return $this;
}

public function timeoutInSeconds(int $timeoutInSeconds)
public function timeoutInSeconds(int $timeoutInSeconds): self
{
$this->callWebhookJob->requestTimeout = $timeoutInSeconds;

return $this;
}

public function signUsing(string $signerClass)
public function signUsing(string $signerClass): self
{
if (! is_subclass_of($signerClass, Signer::class)) {
throw InvalidSigner::doesImplementSigner($signerClass);
Expand All @@ -114,35 +125,35 @@ public function signUsing(string $signerClass)
return $this;
}

public function withHeaders(array $headers)
public function withHeaders(array $headers): self
{
$this->headers = $headers;

return $this;
}

public function verifySsl(bool $verifySsl = true)
public function verifySsl(bool $verifySsl = true): self
{
$this->callWebhookJob->verifySsl = $verifySsl;

return $this;
}

public function doNotVerifySsl()
public function doNotVerifySsl(): self
{
$this->verifySsl(false);

return $this;
}

public function meta(array $meta)
public function meta(array $meta): self
{
$this->callWebhookJob->meta = $meta;

return $this;
}

public function withTags(array $tags)
public function withTags(array $tags): self
{
$this->callWebhookJob->tags = $tags;

Expand Down

0 comments on commit ca8dbd3

Please sign in to comment.