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

Meta api #21

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Palpalani\BayRewards\Resources\CreateActivityResource;
use Palpalani\BayRewards\Resources\CustomerResource;
use Palpalani\BayRewards\Resources\PointsResource;
use Palpalani\BayRewards\Resources\StoreFeatureResource;
use Palpalani\BayRewards\Resources\StoreResource;
use Saloon\Http\Connector;

Expand Down Expand Up @@ -52,4 +53,9 @@ public function allCustomers(): CustomerResource
{
return new CustomerResource($this);
}

public function getStoreFeatures(): StoreFeatureResource
{
return new StoreFeatureResource($this);
}
}
44 changes: 44 additions & 0 deletions src/Requests/Store/GetStoreFeaturesRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Palpalani\BayRewards\Requests\Store;

use Palpalani\BayRewards\Objects\Store;
use Palpalani\BayRewards\Responses\Store\GetStoreFeaturesResponse;
use Saloon\Contracts\Response;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Traits\Plugins\AlwaysThrowOnErrors;

final class GetStoreFeaturesRequest extends Request
{
use AlwaysThrowOnErrors;

protected Method $method = Method::POST;

public function __construct(protected string $access_token)
{

}

/**
* {@inheritDoc}
*/
public function resolveEndpoint(): string
{
return '/account/initial';
}

protected function defaultHeaders(): array
{
return [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Store-Access-Token' => $this->access_token,
];
}

public function createDtoFromResponse(Response $response): Store
{
return GetStoreFeaturesResponse::make($response);
}
}
17 changes: 17 additions & 0 deletions src/Resources/StoreFeatureResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Palpalani\BayRewards\Resources;

use Palpalani\BayRewards\Objects\ActionData;
use Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest;

final class StoreFeatureResource extends Resource
{
/**
* @return mixed|ActionData
*/
public function post(string $access_token, array $data): mixed
{
return $this->connector->send(new GetStoreFeaturesRequest($access_token, $data))->dto();
}
}
20 changes: 20 additions & 0 deletions src/Responses/Store/GetStoreFeaturesResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Palpalani\BayRewards\Responses\Store;

use Palpalani\BayRewards\Objects\Store;
use Saloon\Contracts\Response;

/**
* @phpstan-import-type StoreData from Store
*/
final class GetStoreFeaturesResponse
{
public static function make(Response $response): Store
{
/** @var StoreData $data */
$data = $response->json();

return new Store(...$data);
}
}
Loading