generated from combindma/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Points endpoint & migrated to saloon v3
- Loading branch information
Combind
committed
Dec 31, 2023
1 parent
2e691d0
commit 416b17d
Showing
7 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Combindma\Mautic\Requests; | ||
|
||
use Saloon\Contracts\Body\HasBody; | ||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
use Saloon\Traits\Body\HasJsonBody; | ||
|
||
class AddPointsToContactRequest extends Request implements HasBody | ||
{ | ||
use HasJsonBody; | ||
|
||
protected Method $method = Method::POST; | ||
|
||
public function __construct(protected int $contactId, protected int $pointDelta, protected ?array $attributes = null) | ||
{ | ||
// | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/contacts/'.$this->contactId.'/points/plus/'.$this->pointDelta; | ||
} | ||
|
||
protected function defaultBody(): array | ||
{ | ||
return $this->attributes ?? []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Combindma\Mautic\Requests; | ||
|
||
use Saloon\Enums\Method; | ||
use Saloon\Http\Request; | ||
|
||
class RemovePointsFromContactRequest extends Request | ||
{ | ||
protected Method $method = Method::POST; | ||
|
||
public function __construct(protected int $contactId, protected int $pointDelta, protected ?array $attributes = null) | ||
{ | ||
// | ||
} | ||
|
||
public function resolveEndpoint(): string | ||
{ | ||
return '/contacts/'.$this->contactId.'/points/minus/'.$this->pointDelta; | ||
} | ||
|
||
protected function defaultBody(): array | ||
{ | ||
return $this->attributes ?? []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Combindma\Mautic\Resources; | ||
|
||
use Combindma\Mautic\Requests\AddPointsToContactRequest; | ||
use Combindma\Mautic\Requests\RemovePointsFromContactRequest; | ||
use Exception; | ||
use Illuminate\Support\Facades\Log; | ||
use Saloon\Http\Response; | ||
|
||
class PointsResource extends Resource | ||
{ | ||
public function addPoints(int $contactId, int $pointDelta, ?array $attributes = null): ?Response | ||
{ | ||
if ($this->connector->isApiDisabled()) { | ||
return null; | ||
} | ||
|
||
try { | ||
return $this->connector->send(new AddPointsToContactRequest($contactId, $pointDelta, $attributes)); | ||
} catch (Exception $e) { | ||
Log::error($e); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function subtractPoints(int $contactId, int $pointDelta, ?array $attributes = null): ?Response | ||
{ | ||
if ($this->connector->isApiDisabled()) { | ||
return null; | ||
} | ||
|
||
try { | ||
return $this->connector->send(new RemovePointsFromContactRequest($contactId, $pointDelta, $attributes)); | ||
} catch (Exception $e) { | ||
Log::error($e); | ||
} | ||
|
||
return null; | ||
} | ||
} |