Skip to content

Commit

Permalink
added api to fetch store features
Browse files Browse the repository at this point in the history
  • Loading branch information
cvinoth-kumar committed Mar 4, 2024
1 parent d96fb37 commit 3f14b68
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Palpalani\BayRewards\Resources\CustomerResource;
use Palpalani\BayRewards\Resources\PointsResource;
use Palpalani\BayRewards\Resources\StoreResource;
use Palpalani\BayRewards\Resources\StoreFeatureResource;
use Saloon\Http\Connector;

final class Factory extends 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);
}
}

0 comments on commit 3f14b68

Please sign in to comment.