From c34e609716fcdffd0cbc087f6c25573f7e12ff58 Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Fri, 12 Jul 2024 11:46:27 +0200 Subject: [PATCH 01/11] wip --- README.md | 2 +- src/Models/Tiers/Perk.php | 131 ++++++++++++++++++++ src/Resources/OAuth/Tiers/PerksResource.php | 75 +++++++++++ src/StaticMappers/Tiers/PerkMapper.php | 19 +++ src/StaticMappers/Tiers/PerksMapper.php | 17 +++ 5 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 src/Models/Tiers/Perk.php create mode 100644 src/Resources/OAuth/Tiers/PerksResource.php create mode 100644 src/StaticMappers/Tiers/PerkMapper.php create mode 100644 src/StaticMappers/Tiers/PerksMapper.php diff --git a/README.md b/README.md index 315666a..d11dfc2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - +ggi # Piggy PHP SDK # With [Piggy's](https://www.piggy.eu/) all-in-one platform you can strengthen loyalty and automate every step. From reward programs, to branded giftcards and smart email marketing - Piggy takes care of it all. diff --git a/src/Models/Tiers/Perk.php b/src/Models/Tiers/Perk.php new file mode 100644 index 0000000..3c21b98 --- /dev/null +++ b/src/Models/Tiers/Perk.php @@ -0,0 +1,131 @@ +uuid = $uuid; + $this->label = $label; + $this->name = $name; + $this->dataType = $dataType; + } + + public function getUuid(): ?string + { + return $this->uuid; + } + + public function getName(): string + { + return $this->name; + } + + public function getLabel(): ?string + { + return $this->label; + } + + public function getDataType(): string + { + return $this->dataType; + } + + /** + * @param mixed[] $params + * @return Perk[] + * + * @throws MaintenanceModeException|GuzzleException|PiggyRequestException + */ + public static function list(array $params = []): array + { + $response = ApiClient::get(self::resourceUri, $params); + + return PerksMapper::map((array) $response->getData()); + } + + /** + * @param mixed[] $body + * + * @throws MaintenanceModeException|GuzzleException|PiggyRequestException + */ + public static function create(array $body): array + { + $response = ApiClient::post(self::resourceUri, $body); + + return $response->getData(); + } + + /** + * @param mixed[] $params + * + * @throws MaintenanceModeException|GuzzleException|PiggyRequestException + */ + public static function get(string $perkUuid, array $params = []): Perk + { + $response = ApiClient::get(self::resourceUri."/$perkUuid", $params); + + return PerkMapper::map($response->getData()); + } + + /** + * @param mixed[] $body + * + * @throws MaintenanceModeException|GuzzleException|PiggyRequestException + */ + public static function update(string $perkUuid, array $body): array + { + $response = ApiClient::put(self::resourceUri."/$perkUuid", $body); + + return $response->getData(); + } + + /** + * @param mixed[] $params + * + * @throws MaintenanceModeException|GuzzleException|PiggyRequestException + */ + public static function delete(string $perkUuid, array $params = []): array + { + $response = ApiClient::delete(self::resourceUri."/$perkUuid", $params); + + return $response->getData(); + } +} diff --git a/src/Resources/OAuth/Tiers/PerksResource.php b/src/Resources/OAuth/Tiers/PerksResource.php new file mode 100644 index 0000000..3aaeb30 --- /dev/null +++ b/src/Resources/OAuth/Tiers/PerksResource.php @@ -0,0 +1,75 @@ +client->get($this->resourceUri, $params); + + $mapper = new PerksMapper(); + + return $mapper->map((array) $response->getData()); + } + + /** + * @throws PiggyRequestException + */ + public function create(string $label, string $name, string $dataType): array + { + $response = $this->client->post($this->resourceUri, [ + 'label' => $label, + 'name' => $name, + 'dataType' => $dataType, + ]); + + return $response->getData(); + } + + /** + * @param mixed[] $params + * + * @throws PiggyRequestException + */ + public function get(string $perkUuid, array $params = []): Perk + { + $response = $this->client->get("$this->resourceUri/$perkUuid", $params); + + $mapper = new PerkMapper(); + + return $mapper->map($response->getData()); + } + + /** + * @throws PiggyRequestException + */ + public function update(string $perkUuid, string $label, string $name, string $dataType): array + { + $response = $this->client->put("$this->resourceUri/$perkUuid", [ + 'label' => $label, + 'name' => $name, + 'dataType' => $dataType, + ]); + + return $response->getData(); + } +} diff --git a/src/StaticMappers/Tiers/PerkMapper.php b/src/StaticMappers/Tiers/PerkMapper.php new file mode 100644 index 0000000..14223a5 --- /dev/null +++ b/src/StaticMappers/Tiers/PerkMapper.php @@ -0,0 +1,19 @@ +uuid, + $data->label, + $data->name, + $data->dataType + ); + } +} diff --git a/src/StaticMappers/Tiers/PerksMapper.php b/src/StaticMappers/Tiers/PerksMapper.php new file mode 100644 index 0000000..13b0ef5 --- /dev/null +++ b/src/StaticMappers/Tiers/PerksMapper.php @@ -0,0 +1,17 @@ + Date: Fri, 12 Jul 2024 15:47:01 +0200 Subject: [PATCH 02/11] wip --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 3 +- src/Models/{Tiers => Perks}/Perk.php | 14 ++++---- .../OAuth/{Tiers => Perks}/PerksResource.php | 32 +++++++++++++----- .../{Tiers => Perks}/PerkMapper.php | 5 ++- .../{Tiers => Perks}/PerksMapper.php | 2 +- 6 files changed, 35 insertions(+), 21 deletions(-) delete mode 100644 .DS_Store rename src/Models/{Tiers => Perks}/Perk.php (89%) rename src/Resources/OAuth/{Tiers => Perks}/PerksResource.php (68%) rename src/StaticMappers/{Tiers => Perks}/PerkMapper.php (67%) rename src/StaticMappers/{Tiers => Perks}/PerksMapper.php (84%) diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 4177b4c24de1db933ab4968cb367917265b8a2f4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%Sr<=6g_FHXsghr8*#p%;2%sMQUzaF+)G>WHJy>x7MHX4W5kc~V_fOENl+)P z;7UaAg`1PdJ$alq$pnCDO^4e+9l#1*uu^5Rz@%M#&Pu+fMl`mME_SewBXrT2i`EKN zKo$6H3dr7FLmRtj;*k6HWB-mY+)J`SKgs%xkprShZ@gM#4p_$k8AiBeI>9-{-1XPY zWk>_&<2RTIc>~-OnPxL!);QWFeTo!UxZ{ZToIw(>9s<@XPPnorIyfLU$OzVEUIIp$ z>lkBD?6-8WIBM1#r%9GdE6+h5mUmQRVrOS(8}#xV^s@9GKPg6*+d*U%r#R-XbYj=C za3$rZfU}GlXOm(`eaFTAD_cPkI3 z>=S@kVYM~p@5U?_6q6++|0&g9Tl{EkW diff --git a/.gitignore b/.gitignore index 93effa6..df5ee6e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .idea/ .phpunit.result.cache test.php -composer.lock \ No newline at end of file +composer.lock +.DS_Store \ No newline at end of file diff --git a/src/Models/Tiers/Perk.php b/src/Models/Perks/Perk.php similarity index 89% rename from src/Models/Tiers/Perk.php rename to src/Models/Perks/Perk.php index 3c21b98..60930c4 100644 --- a/src/Models/Tiers/Perk.php +++ b/src/Models/Perks/Perk.php @@ -1,13 +1,13 @@ getData(); + return PerkMapper::map($response->getData()); } /** @@ -110,11 +110,11 @@ public static function get(string $perkUuid, array $params = []): Perk * * @throws MaintenanceModeException|GuzzleException|PiggyRequestException */ - public static function update(string $perkUuid, array $body): array + public static function update(string $perkUuid, array $body): Perk { $response = ApiClient::put(self::resourceUri."/$perkUuid", $body); - return $response->getData(); + return PerkMapper::map($response->getData()); } /** diff --git a/src/Resources/OAuth/Tiers/PerksResource.php b/src/Resources/OAuth/Perks/PerksResource.php similarity index 68% rename from src/Resources/OAuth/Tiers/PerksResource.php rename to src/Resources/OAuth/Perks/PerksResource.php index 3aaeb30..642d567 100644 --- a/src/Resources/OAuth/Tiers/PerksResource.php +++ b/src/Resources/OAuth/Perks/PerksResource.php @@ -1,13 +1,13 @@ client->post($this->resourceUri, [ 'label' => $label, @@ -42,7 +42,9 @@ public function create(string $label, string $name, string $dataType): array 'dataType' => $dataType, ]); - return $response->getData(); + $mapper = new PerkMapper(); + + return $mapper->map($response->getData()); } /** @@ -62,14 +64,26 @@ public function get(string $perkUuid, array $params = []): Perk /** * @throws PiggyRequestException */ - public function update(string $perkUuid, string $label, string $name, string $dataType): array + public function update(string $perkUuid, string $label): Perk { $response = $this->client->put("$this->resourceUri/$perkUuid", [ 'label' => $label, - 'name' => $name, - 'dataType' => $dataType, ]); + $mapper = new PerkMapper(); + + return $mapper->map($response->getData()); + } + + /** + * @param mixed[] $params + * + * @throws PiggyRequestException + */ + public function d(string $perkUuid, array $params = []): array + { + $response = $this->client->destroy("$this->resourceUri/$perkUuid", $params); + return $response->getData(); } } diff --git a/src/StaticMappers/Tiers/PerkMapper.php b/src/StaticMappers/Perks/PerkMapper.php similarity index 67% rename from src/StaticMappers/Tiers/PerkMapper.php rename to src/StaticMappers/Perks/PerkMapper.php index 14223a5..e64a9d2 100644 --- a/src/StaticMappers/Tiers/PerkMapper.php +++ b/src/StaticMappers/Perks/PerkMapper.php @@ -1,9 +1,8 @@ Date: Mon, 15 Jul 2024 10:44:10 +0200 Subject: [PATCH 03/11] fix wrong property --- src/StaticMappers/Perks/PerkMapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StaticMappers/Perks/PerkMapper.php b/src/StaticMappers/Perks/PerkMapper.php index e64a9d2..9514b7d 100644 --- a/src/StaticMappers/Perks/PerkMapper.php +++ b/src/StaticMappers/Perks/PerkMapper.php @@ -12,7 +12,7 @@ public static function map($data): Perk $data->uuid, $data->label, $data->name, - $data->dataType + $data->data_type ); } } From c962ced1a3ec10bccbb66b3521c482ad3736ea29 Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Mon, 15 Jul 2024 14:46:57 +0200 Subject: [PATCH 04/11] wip --- src/Http/Traits/SetsOAuthResources.php | 7 +++ src/Mappers/Perks/PerkMapper.php | 19 ++++++ src/Mappers/Perks/PerksMapper.php | 25 ++++++++ src/Resources/OAuth/Perks/PerksResource.php | 6 +- src/StaticMappers/Perks/PerkMapper.php | 3 +- tests/OAuth/Perks/PerksResourceTest.php | 69 +++++++++++++++++++++ 6 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 src/Mappers/Perks/PerkMapper.php create mode 100644 src/Mappers/Perks/PerksMapper.php create mode 100644 tests/OAuth/Perks/PerksResourceTest.php diff --git a/src/Http/Traits/SetsOAuthResources.php b/src/Http/Traits/SetsOAuthResources.php index 0f15ab2..62a94a7 100644 --- a/src/Http/Traits/SetsOAuthResources.php +++ b/src/Http/Traits/SetsOAuthResources.php @@ -24,6 +24,7 @@ use Piggy\Api\Resources\OAuth\Loyalty\Rewards\RewardAttributesResource; use Piggy\Api\Resources\OAuth\Loyalty\Rewards\RewardsResource; use Piggy\Api\Resources\OAuth\Loyalty\Tokens\LoyaltyTokensResource; +use Piggy\Api\Resources\OAuth\Perks\PerksResource; use Piggy\Api\Resources\OAuth\PortalSessions\PortalSessionsResource; use Piggy\Api\Resources\OAuth\PrepaidTransactionsResource; use Piggy\Api\Resources\OAuth\Shops\ShopsResource; @@ -161,6 +162,11 @@ trait SetsOAuthResources */ public $tier; + /** + * @var PerksResource + */ + public $perk; + /** * @var PortalSessionsResource */ @@ -218,6 +224,7 @@ protected function setResources(BaseClient $client): void $this->voucher = new VouchersResource($client); $this->brandkit = new BrandkitResource($client); $this->tier = new TiersResource($client); + $this->perk = new PerksResource($client); $this->portalSessions = new PortalSessionsResource($client); $this->forms = new FormsResource($client); $this->loyaltyTransactionAttributes = new LoyaltyTransactionAttributesResource($client); diff --git a/src/Mappers/Perks/PerkMapper.php b/src/Mappers/Perks/PerkMapper.php new file mode 100644 index 0000000..458d2ea --- /dev/null +++ b/src/Mappers/Perks/PerkMapper.php @@ -0,0 +1,19 @@ +uuid, + $data->label, + $data->name, + $data->data_type + ); + } +} diff --git a/src/Mappers/Perks/PerksMapper.php b/src/Mappers/Perks/PerksMapper.php new file mode 100644 index 0000000..2c17bf8 --- /dev/null +++ b/src/Mappers/Perks/PerksMapper.php @@ -0,0 +1,25 @@ +map($item); + } + + return $perks; + } +} diff --git a/src/Resources/OAuth/Perks/PerksResource.php b/src/Resources/OAuth/Perks/PerksResource.php index 642d567..7edb244 100644 --- a/src/Resources/OAuth/Perks/PerksResource.php +++ b/src/Resources/OAuth/Perks/PerksResource.php @@ -6,8 +6,8 @@ use Piggy\Api\Models\Perks\Perk; use Piggy\Api\Models\Tiers\Tier; use Piggy\Api\Resources\BaseResource; -use Piggy\Api\StaticMappers\Perks\PerkMapper; -use Piggy\Api\StaticMappers\Perks\PerksMapper; +use Piggy\Api\Mappers\Perks\PerkMapper; +use Piggy\Api\Mappers\Perks\PerksMapper; class PerksResource extends BaseResource { @@ -18,7 +18,7 @@ class PerksResource extends BaseResource /** * @param mixed[] $params - * @return Tier[] + * @return Perk[] * * @throws PiggyRequestException */ diff --git a/src/StaticMappers/Perks/PerkMapper.php b/src/StaticMappers/Perks/PerkMapper.php index 9514b7d..d836013 100644 --- a/src/StaticMappers/Perks/PerkMapper.php +++ b/src/StaticMappers/Perks/PerkMapper.php @@ -3,10 +3,11 @@ namespace Piggy\Api\StaticMappers\Perks; use Piggy\Api\Models\Perks\Perk; +use stdClass; class PerkMapper { - public static function map($data): Perk + public static function map(stdClass $data): Perk { return new Perk( $data->uuid, diff --git a/tests/OAuth/Perks/PerksResourceTest.php b/tests/OAuth/Perks/PerksResourceTest.php new file mode 100644 index 0000000..01dd533 --- /dev/null +++ b/tests/OAuth/Perks/PerksResourceTest.php @@ -0,0 +1,69 @@ +addExpectedResponse([ + [ + 'uuid' => 'first-uuid', + 'label' => 'Some perk', + 'name' => 'some_perk', + 'data_type' => 'single_select' + ], + [ + 'uuid' => 'second-uuid', + 'label' => 'Some second perk', + 'name' => 'some_second_perk', + 'data_type' => 'boolean' + ], + ]); + + $perks = $this->mockedClient->perk->list(); + + $this->assertEquals('first-uuid', $perks[0]->getUuid()); + + $this->assertEquals('second-uuid', $perks[1]->getUuid()); + } + + /** + * @test + * + * @throws PiggyRequestException + */ + public function it_gets_a_perk(): void + { + $this->addExpectedResponse([ + 'uuid' => 'some-uuid', + 'label' => 'Some perk', + 'name' => 'some_perk', + 'data_type' => 'single_select', + 'options' => [ + [ + 'label' => 'Option 1', + 'value' => 'option_1', + 'default' => true, + ], + [ + 'label' => 'Option 2', + 'value' => 'option_2', + 'default' => false, + ] + ], + ]); + + $perk = $this->mockedClient->perk->get('first-uuid'); + + $this->assertEquals('some-uuid', $perk->getUuid()); + } +} From 71dd7be8ce6358c45458b4a1a51f80c435ed0f1f Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Mon, 15 Jul 2024 14:56:16 +0200 Subject: [PATCH 05/11] wip --- tests/OAuth/Perks/PerksResourceTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/OAuth/Perks/PerksResourceTest.php b/tests/OAuth/Perks/PerksResourceTest.php index 01dd533..2a552d7 100644 --- a/tests/OAuth/Perks/PerksResourceTest.php +++ b/tests/OAuth/Perks/PerksResourceTest.php @@ -32,8 +32,15 @@ public function it_returns_a_list_with_perks(): void $perks = $this->mockedClient->perk->list(); $this->assertEquals('first-uuid', $perks[0]->getUuid()); + $this->assertEquals('Some perk', $perks[0]->getLabel()); + $this->assertEquals('some_perk', $perks[0]->getName()); + $this->assertEquals('single_select', $perks[0]->getDataType()); $this->assertEquals('second-uuid', $perks[1]->getUuid()); + $this->assertEquals('Some second perk', $perks[1]->getLabel()); + $this->assertEquals('some_second_perk', $perks[1]->getName()); + $this->assertEquals('boolean', $perks[1]->getDataType()); + } /** @@ -65,5 +72,8 @@ public function it_gets_a_perk(): void $perk = $this->mockedClient->perk->get('first-uuid'); $this->assertEquals('some-uuid', $perk->getUuid()); + $this->assertEquals('Some perk', $perk->getLabel()); + $this->assertEquals('some_perk', $perk->getName()); + $this->assertEquals('single_select', $perk->getDataType()); } } From 217afaf3fb0185a66b32327c243ec18ad468cd5b Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Tue, 16 Jul 2024 11:09:51 +0200 Subject: [PATCH 06/11] wip --- src/Mappers/Perks/PerkMapper.php | 3 ++- src/Models/Perks/Perk.php | 14 +++++++++++++- src/Resources/OAuth/Perks/PerksResource.php | 5 +++-- src/StaticMappers/Perks/PerkMapper.php | 3 ++- src/StaticMappers/Perks/PerksMapper.php | 1 - tests/OAuth/Perks/PerksResourceTest.php | 11 +++++++---- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Mappers/Perks/PerkMapper.php b/src/Mappers/Perks/PerkMapper.php index 458d2ea..c033f44 100644 --- a/src/Mappers/Perks/PerkMapper.php +++ b/src/Mappers/Perks/PerkMapper.php @@ -13,7 +13,8 @@ public function map(stdClass $data): Perk $data->uuid, $data->label, $data->name, - $data->data_type + $data->data_type, + $data->options ?? [] ); } } diff --git a/src/Models/Perks/Perk.php b/src/Models/Perks/Perk.php index 60930c4..9dfc0dc 100644 --- a/src/Models/Perks/Perk.php +++ b/src/Models/Perks/Perk.php @@ -31,6 +31,11 @@ class Perk */ protected $dataType; + /** + * @var array + */ + protected $options = []; + /** * @var string */ @@ -40,12 +45,14 @@ public function __construct( string $uuid, string $label, string $name, - string $dataType + string $dataType, + array $options ) { $this->uuid = $uuid; $this->label = $label; $this->name = $name; $this->dataType = $dataType; + $this->options = $options; } public function getUuid(): ?string @@ -68,6 +75,11 @@ public function getDataType(): string return $this->dataType; } + public function getOptions(): array + { + return $this->options; + } + /** * @param mixed[] $params * @return Perk[] diff --git a/src/Resources/OAuth/Perks/PerksResource.php b/src/Resources/OAuth/Perks/PerksResource.php index 7edb244..bf1bfce 100644 --- a/src/Resources/OAuth/Perks/PerksResource.php +++ b/src/Resources/OAuth/Perks/PerksResource.php @@ -34,12 +34,13 @@ public function list(array $params = []): array /** * @throws PiggyRequestException */ - public function create(string $label, string $name, string $dataType): Perk + public function create(string $label, string $name, string $dataType, array $options): Perk { $response = $this->client->post($this->resourceUri, [ 'label' => $label, 'name' => $name, 'dataType' => $dataType, + 'options' => $options, ]); $mapper = new PerkMapper(); @@ -80,7 +81,7 @@ public function update(string $perkUuid, string $label): Perk * * @throws PiggyRequestException */ - public function d(string $perkUuid, array $params = []): array + public function delete(string $perkUuid, array $params = []): array { $response = $this->client->destroy("$this->resourceUri/$perkUuid", $params); diff --git a/src/StaticMappers/Perks/PerkMapper.php b/src/StaticMappers/Perks/PerkMapper.php index d836013..3797a10 100644 --- a/src/StaticMappers/Perks/PerkMapper.php +++ b/src/StaticMappers/Perks/PerkMapper.php @@ -13,7 +13,8 @@ public static function map(stdClass $data): Perk $data->uuid, $data->label, $data->name, - $data->data_type + $data->data_type, + $data->options ?? [] ); } } diff --git a/src/StaticMappers/Perks/PerksMapper.php b/src/StaticMappers/Perks/PerksMapper.php index 77ae461..153efeb 100644 --- a/src/StaticMappers/Perks/PerksMapper.php +++ b/src/StaticMappers/Perks/PerksMapper.php @@ -7,7 +7,6 @@ class PerksMapper public static function map($data): array { $perks = []; - foreach ($data as $item) { $perks[] = PerkMapper::map($item); } diff --git a/tests/OAuth/Perks/PerksResourceTest.php b/tests/OAuth/Perks/PerksResourceTest.php index 2a552d7..77d1356 100644 --- a/tests/OAuth/Perks/PerksResourceTest.php +++ b/tests/OAuth/Perks/PerksResourceTest.php @@ -19,13 +19,15 @@ public function it_returns_a_list_with_perks(): void 'uuid' => 'first-uuid', 'label' => 'Some perk', 'name' => 'some_perk', - 'data_type' => 'single_select' + 'data_type' => 'single_select', + 'options' => [], ], [ 'uuid' => 'second-uuid', 'label' => 'Some second perk', 'name' => 'some_second_perk', - 'data_type' => 'boolean' + 'data_type' => 'boolean', + 'options' => [], ], ]); @@ -35,12 +37,13 @@ public function it_returns_a_list_with_perks(): void $this->assertEquals('Some perk', $perks[0]->getLabel()); $this->assertEquals('some_perk', $perks[0]->getName()); $this->assertEquals('single_select', $perks[0]->getDataType()); + $this->assertEquals([], $perks[0]->getOptions()); $this->assertEquals('second-uuid', $perks[1]->getUuid()); $this->assertEquals('Some second perk', $perks[1]->getLabel()); $this->assertEquals('some_second_perk', $perks[1]->getName()); $this->assertEquals('boolean', $perks[1]->getDataType()); - + $this->assertEquals([], $perks[1]->getOptions()); } /** @@ -69,7 +72,7 @@ public function it_gets_a_perk(): void ], ]); - $perk = $this->mockedClient->perk->get('first-uuid'); + $perk = $this->mockedClient->perk->get('some-uuid'); $this->assertEquals('some-uuid', $perk->getUuid()); $this->assertEquals('Some perk', $perk->getLabel()); From 82a33d3f26debe392cee36bfe099a11d40970abf Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Tue, 16 Jul 2024 11:31:47 +0200 Subject: [PATCH 07/11] wip --- src/Models/Perks/Perk.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Models/Perks/Perk.php b/src/Models/Perks/Perk.php index 9dfc0dc..6cac6ac 100644 --- a/src/Models/Perks/Perk.php +++ b/src/Models/Perks/Perk.php @@ -6,6 +6,7 @@ use Piggy\Api\ApiClient; use Piggy\Api\Exceptions\MaintenanceModeException; use Piggy\Api\Exceptions\PiggyRequestException; +use Piggy\Api\Http\Responses\Response; use Piggy\Api\StaticMappers\Perks\PerkMapper; use Piggy\Api\StaticMappers\Perks\PerksMapper; @@ -134,10 +135,8 @@ public static function update(string $perkUuid, array $body): Perk * * @throws MaintenanceModeException|GuzzleException|PiggyRequestException */ - public static function delete(string $perkUuid, array $params = []): array + public static function delete(string $perkUuid, array $params = []): Response { - $response = ApiClient::delete(self::resourceUri."/$perkUuid", $params); - - return $response->getData(); + return ApiClient::delete(self::resourceUri."/$perkUuid", $params); } } From ecc63003a640dcb2675794cc6190db793242e49d Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Tue, 16 Jul 2024 15:10:01 +0200 Subject: [PATCH 08/11] add register resource class --- src/Resources/OAuth/Perks/PerksResource.php | 1 - .../Register/Perks/PerksResource.php | 89 +++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/Resources/Register/Perks/PerksResource.php diff --git a/src/Resources/OAuth/Perks/PerksResource.php b/src/Resources/OAuth/Perks/PerksResource.php index bf1bfce..05458d0 100644 --- a/src/Resources/OAuth/Perks/PerksResource.php +++ b/src/Resources/OAuth/Perks/PerksResource.php @@ -4,7 +4,6 @@ use Piggy\Api\Exceptions\PiggyRequestException; use Piggy\Api\Models\Perks\Perk; -use Piggy\Api\Models\Tiers\Tier; use Piggy\Api\Resources\BaseResource; use Piggy\Api\Mappers\Perks\PerkMapper; use Piggy\Api\Mappers\Perks\PerksMapper; diff --git a/src/Resources/Register/Perks/PerksResource.php b/src/Resources/Register/Perks/PerksResource.php new file mode 100644 index 0000000..68b6b43 --- /dev/null +++ b/src/Resources/Register/Perks/PerksResource.php @@ -0,0 +1,89 @@ +client->get($this->resourceUri, $params); + + $mapper = new PerksMapper(); + + return $mapper->map((array) $response->getData()); + } + + /** + * @throws PiggyRequestException + */ + public function create(string $label, string $name, string $dataType, array $options): Perk + { + $response = $this->client->post($this->resourceUri, [ + 'label' => $label, + 'name' => $name, + 'dataType' => $dataType, + 'options' => $options, + ]); + + $mapper = new PerkMapper(); + + return $mapper->map($response->getData()); + } + + /** + * @param mixed[] $params + * + * @throws PiggyRequestException + */ + public function get(string $perkUuid, array $params = []): Perk + { + $response = $this->client->get("$this->resourceUri/$perkUuid", $params); + + $mapper = new PerkMapper(); + + return $mapper->map($response->getData()); + } + + /** + * @throws PiggyRequestException + */ + public function update(string $perkUuid, string $label): Perk + { + $response = $this->client->put("$this->resourceUri/$perkUuid", [ + 'label' => $label, + ]); + + $mapper = new PerkMapper(); + + return $mapper->map($response->getData()); + } + + /** + * @param mixed[] $params + * + * @throws PiggyRequestException + */ + public function delete(string $perkUuid, array $params = []): array + { + $response = $this->client->destroy("$this->resourceUri/$perkUuid", $params); + + return $response->getData(); + } +} From a6e0cb3fa615424523450f04209c6e70446fef34 Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Tue, 16 Jul 2024 15:15:14 +0200 Subject: [PATCH 09/11] fix phpstan errors --- src/Models/Perks/Perk.php | 8 +++++++- src/Resources/OAuth/Perks/PerksResource.php | 5 ++++- src/Resources/Register/Perks/PerksResource.php | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Models/Perks/Perk.php b/src/Models/Perks/Perk.php index 6cac6ac..ced8edc 100644 --- a/src/Models/Perks/Perk.php +++ b/src/Models/Perks/Perk.php @@ -33,7 +33,7 @@ class Perk protected $dataType; /** - * @var array + * @var mixed[] array */ protected $options = []; @@ -42,6 +42,9 @@ class Perk */ const resourceUri = '/api/v3/oauth/clients/perks'; + /** + * @param mixed[] $options + */ public function __construct( string $uuid, string $label, @@ -76,6 +79,9 @@ public function getDataType(): string return $this->dataType; } + /** + * @return mixed[] + */ public function getOptions(): array { return $this->options; diff --git a/src/Resources/OAuth/Perks/PerksResource.php b/src/Resources/OAuth/Perks/PerksResource.php index 05458d0..00b7641 100644 --- a/src/Resources/OAuth/Perks/PerksResource.php +++ b/src/Resources/OAuth/Perks/PerksResource.php @@ -31,6 +31,8 @@ public function list(array $params = []): array } /** + * @param mixed[] $options + * * @throws PiggyRequestException */ public function create(string $label, string $name, string $dataType, array $options): Perk @@ -77,10 +79,11 @@ public function update(string $perkUuid, string $label): Perk /** * @param mixed[] $params + * @return null * * @throws PiggyRequestException */ - public function delete(string $perkUuid, array $params = []): array + public function delete(string $perkUuid, array $params = []) { $response = $this->client->destroy("$this->resourceUri/$perkUuid", $params); diff --git a/src/Resources/Register/Perks/PerksResource.php b/src/Resources/Register/Perks/PerksResource.php index 68b6b43..3d7f6b6 100644 --- a/src/Resources/Register/Perks/PerksResource.php +++ b/src/Resources/Register/Perks/PerksResource.php @@ -31,6 +31,8 @@ public function list(array $params = []): array } /** + * @param mixed[] $options + * * @throws PiggyRequestException */ public function create(string $label, string $name, string $dataType, array $options): Perk @@ -77,10 +79,11 @@ public function update(string $perkUuid, string $label): Perk /** * @param mixed[] $params + * @return null * * @throws PiggyRequestException */ - public function delete(string $perkUuid, array $params = []): array + public function delete(string $perkUuid, array $params = []) { $response = $this->client->destroy("$this->resourceUri/$perkUuid", $params); From 201e233551fb300e48d8de42118952146e70e440 Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Tue, 16 Jul 2024 15:19:14 +0200 Subject: [PATCH 10/11] wip --- src/Models/Perks/Perk.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Perks/Perk.php b/src/Models/Perks/Perk.php index ced8edc..ba0bf89 100644 --- a/src/Models/Perks/Perk.php +++ b/src/Models/Perks/Perk.php @@ -33,7 +33,7 @@ class Perk protected $dataType; /** - * @var mixed[] array + * @var mixed[] */ protected $options = []; From b3bbb87fe951be8186ced518e160c4c4b8351453 Mon Sep 17 00:00:00 2001 From: Lars Wolters Date: Wed, 17 Jul 2024 10:24:41 +0200 Subject: [PATCH 11/11] fix comments --- README.md | 1 - src/Models/Perks/Perk.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d11dfc2..847d8fb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -ggi # Piggy PHP SDK # With [Piggy's](https://www.piggy.eu/) all-in-one platform you can strengthen loyalty and automate every step. From reward programs, to branded giftcards and smart email marketing - Piggy takes care of it all. diff --git a/src/Models/Perks/Perk.php b/src/Models/Perks/Perk.php index ba0bf89..1c956be 100644 --- a/src/Models/Perks/Perk.php +++ b/src/Models/Perks/Perk.php @@ -59,7 +59,7 @@ public function __construct( $this->options = $options; } - public function getUuid(): ?string + public function getUuid(): string { return $this->uuid; } @@ -69,7 +69,7 @@ public function getName(): string return $this->name; } - public function getLabel(): ?string + public function getLabel(): string { return $this->label; }