Skip to content

Commit

Permalink
Merge pull request #21 from palpalani/feature/meta-api
Browse files Browse the repository at this point in the history
Meta api
  • Loading branch information
palpalani authored Apr 23, 2024
2 parents 803cb4a + 01cf582 commit 23f1ee5
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 @@ -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

Check failure on line 40 in src/Requests/Store/GetStoreFeaturesRequest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L10.* - prefer-lowest - ubuntu-latest

Could not check compatibility between Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest::createDtoFromResponse(Saloon\Contracts\Response $response): Palpalani\BayRewards\Objects\Store and Saloon\Http\Request::createDtoFromResponse(Saloon\Http\Response $response): mixed, because class Saloon\Contracts\Response is not available

Check failure on line 40 in src/Requests/Store/GetStoreFeaturesRequest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L10.* - prefer-stable - ubuntu-latest

Could not check compatibility between Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest::createDtoFromResponse(Saloon\Contracts\Response $response): Palpalani\BayRewards\Objects\Store and Saloon\Http\Request::createDtoFromResponse(Saloon\Http\Response $response): mixed, because class Saloon\Contracts\Response is not available

Check failure on line 40 in src/Requests/Store/GetStoreFeaturesRequest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-stable - ubuntu-latest

Could not check compatibility between Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest::createDtoFromResponse(Saloon\Contracts\Response $response): Palpalani\BayRewards\Objects\Store and Saloon\Http\Request::createDtoFromResponse(Saloon\Http\Response $response): mixed, because class Saloon\Contracts\Response is not available

Check failure on line 40 in src/Requests/Store/GetStoreFeaturesRequest.php

View workflow job for this annotation

GitHub Actions / P8.3 - L11.* - prefer-lowest - ubuntu-latest

Could not check compatibility between Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest::createDtoFromResponse(Saloon\Contracts\Response $response): Palpalani\BayRewards\Objects\Store and Saloon\Http\Request::createDtoFromResponse(Saloon\Http\Response $response): mixed, because class Saloon\Contracts\Response is not available

Check failure on line 40 in src/Requests/Store/GetStoreFeaturesRequest.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $response (Saloon\Contracts\Response) of method Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest::createDtoFromResponse() is not contravariant with parameter #1 $response (Saloon\Http\Response) of method Saloon\Http\Request::createDtoFromResponse().

Check failure on line 40 in src/Requests/Store/GetStoreFeaturesRequest.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter $response of method Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest::createDtoFromResponse() has invalid type Saloon\Contracts\Response.

Check failure on line 40 in src/Requests/Store/GetStoreFeaturesRequest.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $response (Saloon\Contracts\Response) of method Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest::createDtoFromResponse() is not contravariant with parameter #1 $response (Saloon\Http\Response) of method Saloon\Http\Request::createDtoFromResponse().

Check failure on line 40 in src/Requests/Store/GetStoreFeaturesRequest.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter $response of method Palpalani\BayRewards\Requests\Store\GetStoreFeaturesRequest::createDtoFromResponse() has invalid type Saloon\Contracts\Response.
{
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 23f1ee5

Please sign in to comment.