Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Upgrade to Saloon v2 (#18)
Browse files Browse the repository at this point in the history
Upgrade saloon to v2
  • Loading branch information
SamuelMwangiW authored Jan 30, 2024
1 parent 78a07d7 commit 4cc6767
Show file tree
Hide file tree
Showing 77 changed files with 787 additions and 778 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1,8.2]
php: [8.1,8.2,8.3]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
Expand All @@ -32,7 +32,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
coverage: pcov

- name: Setup problem matchers
run: |
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"illuminate/contracts": "^10.0",
"sammyjo20/saloon-laravel": "^1.5",
"saloonphp/laravel-plugin": "^2.0",
"spatie/laravel-package-tools": "^1.14.0"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- ./vendor/larastan/larastan/extension.neon

parameters:

Expand Down
12 changes: 7 additions & 5 deletions src/Domain/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@

use SamuelMwangiW\Linode\DTO\AccountDTO;
use SamuelMwangiW\Linode\Factory\AccountFactory;
use SamuelMwangiW\Linode\Saloon\AuthenticatedConnector;
use SamuelMwangiW\Linode\Saloon\Requests\Account\GetRequest;

class Account
{
/**
* @return AccountDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public static function details(): AccountDTO
{
$response = GetRequest::make()
->send()
$request = GetRequest::make();

$response = AuthenticatedConnector::make()
->send($request)
->throw();

return AccountFactory::make($response->json());
Expand Down
12 changes: 7 additions & 5 deletions src/Domain/Billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
use Illuminate\Support\Collection;
use SamuelMwangiW\Linode\DTO\PlanDTO;
use SamuelMwangiW\Linode\Factory\PlanFactory;
use SamuelMwangiW\Linode\Saloon\BaseConnector;
use SamuelMwangiW\Linode\Saloon\Requests\Billing\PlansListRequest;

class Billing
{
/**
* @return Collection<PlanDTO>
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function plans(): Collection
{
return PlansListRequest::make()
->send()
$request = PlansListRequest::make();

return BaseConnector::make()
->send($request)
->throw()
->collect('data')
->map(fn (array $plan) => PlanFactory::make($plan));
Expand Down
59 changes: 32 additions & 27 deletions src/Domain/Firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace SamuelMwangiW\Linode\Domain;

use Illuminate\Support\Collection;
use Sammyjo20\Saloon\Http\SaloonResponse;
use Saloon\Contracts\Response;
use SamuelMwangiW\Linode\DTO\FirewallDTO;
use SamuelMwangiW\Linode\Factory\FirewallFactory;
use SamuelMwangiW\Linode\Saloon\AuthenticatedConnector;
use SamuelMwangiW\Linode\Saloon\Requests\Firewall\CreateRequest;
use SamuelMwangiW\Linode\Saloon\Requests\Firewall\DeleteRequest;
use SamuelMwangiW\Linode\Saloon\Requests\Firewall\ListRequest;
Expand All @@ -25,15 +26,16 @@ public function rules(): FirewallRule

/**
* @return Collection<FirewallDTO>
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function list(): Collection
{
return ListRequest::make()
->send()
$request = ListRequest::make();

return AuthenticatedConnector::make()
->send($request)
->throw()
->collect('data')
->map(fn (array $firewall) => FirewallFactory::make($firewall));
Expand All @@ -42,49 +44,52 @@ public function list(): Collection
/**
* @param $firewallId
* @return FirewallDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function show($firewallId): FirewallDTO
{
$request = ShowRequest::make($firewallId);

return FirewallFactory::make(
data: ShowRequest::make($firewallId)
->send()
data: AuthenticatedConnector::make()
->send($request)
->throw()
->json()
);
}

/**
* @param $data
* @return void
* @throws \GuzzleHttp\Exception\GuzzleException
* @param array $data
* @return Collection
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function create($data)
public function create(array $data): Collection
{
CreateRequest::make($data)
->send()
$request = CreateRequest::make($data);

return AuthenticatedConnector::make()
->send($request)
->throw()
->collect()->dd();
->collect();
}

/**
* @param $firewallId
* @return SaloonResponse
* @throws \GuzzleHttp\Exception\GuzzleException
* @return Response
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function destroy($firewallId): SaloonResponse
public function destroy($firewallId): Response
{
return DeleteRequest::make($firewallId)
->send()
$request = DeleteRequest::make($firewallId);

return AuthenticatedConnector::make()
->send($request)
->throw();
}
}
12 changes: 7 additions & 5 deletions src/Domain/FirewallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@

use SamuelMwangiW\Linode\DTO\FirewallRulesDTO;
use SamuelMwangiW\Linode\Factory\FirewallRulesFactory;
use SamuelMwangiW\Linode\Saloon\AuthenticatedConnector;
use SamuelMwangiW\Linode\Saloon\Requests\Firewall\Rules\ListRequest;

class FirewallRule
{
/**
* @param $firewallId
* @return FirewallRulesDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function show($firewallId): FirewallRulesDTO
{
$connector = AuthenticatedConnector::make();
$request = ListRequest::make($firewallId);

return FirewallRulesFactory::make(
data: ListRequest::make($firewallId)
->send()
data: $connector->send($request)
->throw()
->json()
);
Expand Down
34 changes: 19 additions & 15 deletions src/Domain/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Collection;
use SamuelMwangiW\Linode\DTO\ImageDTO;
use SamuelMwangiW\Linode\Factory\ImageFactory;
use SamuelMwangiW\Linode\Saloon\AuthenticatedConnector;
use SamuelMwangiW\Linode\Saloon\Requests\Images\CreateRequest;
use SamuelMwangiW\Linode\Saloon\Requests\Images\ListRequest;
use SamuelMwangiW\Linode\Saloon\Requests\Images\ShowRequest;
Expand All @@ -15,15 +16,16 @@ class Image
{
/**
* @return Collection<ImageDTO>
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function list(): Collection
{
return ListRequest::make()
->send()
$request = ListRequest::make();
$connector = AuthenticatedConnector::make();

return $connector->send($request)
->throw()
->collect('data')
->map(fn (array $image) => ImageFactory::make($image));
Expand All @@ -32,15 +34,16 @@ public function list(): Collection
/**
* @param array $data
* @return ImageDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function create(array $data): ImageDTO
{
$image = CreateRequest::make($data)
->send()
$request = CreateRequest::make($data);
$connector = AuthenticatedConnector::make();

$image = $connector->send($request)
->throw()
->json();

Expand All @@ -50,15 +53,16 @@ public function create(array $data): ImageDTO
/**
* @param string $id
* @return ImageDTO
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \ReflectionException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonException
* @throws \Sammyjo20\Saloon\Exceptions\SaloonRequestException
* @throws \Saloon\Exceptions\InvalidResponseClassException
* @throws \Saloon\Exceptions\PendingRequestException
*/
public function show(string $id): ImageDTO
{
$image = ShowRequest::make($id)
->send()
$request = ShowRequest::make($id);
$connector = AuthenticatedConnector::make();

$image = $connector->send($request)
->throw()
->json();

Expand Down
Loading

0 comments on commit 4cc6767

Please sign in to comment.