Skip to content

Commit

Permalink
upgrade saloon to v3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrelaud committed Nov 3, 2024
1 parent 9458cf3 commit dcdcb59
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 92 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"minimum-stability": "stable",
"require": {
"php": "^8.2",
"saloonphp/saloon": "^1.7"
"saloonphp/saloon": "^3.10"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
Expand Down
32 changes: 20 additions & 12 deletions src/Carbone.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
use Carboneio\SDK\Requests\StatusRequest;

/** Saloon Class */
use Sammyjo20\Saloon\Http\SaloonConnector;
use Sammyjo20\Saloon\Traits\Plugins\AcceptsJson;
use Sammyjo20\Saloon\Http\Auth\TokenAuthenticator;
use Sammyjo20\Saloon\Http\SaloonResponse;
use Sammyjo20\Saloon\Interfaces\AuthenticatorInterface;
use Saloon\Http\Connector;
use Saloon\Traits\Plugins\AcceptsJson;
use Saloon\Http\Auth\TokenAuthenticator;
use Saloon\Http\Response;
use Saloon\Contracts\Authenticator;

class Carbone extends SaloonConnector
class Carbone extends Connector
{
use AcceptsJson;

Expand Down Expand Up @@ -50,7 +50,7 @@ class Carbone extends SaloonConnector
*
* @return string
*/
public function defineBaseUrl(): string
public function resolveBaseUrl(): string
{
return $this->apiBaseUrl;
}
Expand All @@ -65,7 +65,7 @@ public function __construct(private string $token, string $baseUrl = null)
}
}

public function defaultAuth(): ?AuthenticatorInterface
public function defaultAuth(): ?Authenticator
{
return new TokenAuthenticator($this->token);
}
Expand All @@ -83,8 +83,6 @@ public function defaultHeaders(): array
];
}



/**
* Define any default config.
*
Expand All @@ -97,13 +95,23 @@ public function defaultConfig(): array
];
}

public function templates(): TemplatesCollection
{
return new TemplatesCollection($this);
}

public function renders(): RendersCollection
{
return new RendersCollection($this);
}

public function getToken(): string
{
return $this->token;
}

public function getStatus(): SaloonResponse
public function getStatus(): Response
{
return $this->request(new StatusRequest())->send();
return $this->send(new StatusRequest());
}
}
8 changes: 4 additions & 4 deletions src/Exceptions/CarboneSdkRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace Carboneio\SDK\Exceptions;

use Sammyjo20\Saloon\Http\SaloonResponse;
use Sammyjo20\Saloon\Exceptions\SaloonRequestException;
use Saloon\Http\Response;
use Saloon\Exceptions\Request\RequestException;

class CarboneSdkRequestException extends SaloonRequestException
class CarboneSdkRequestException extends RequestException
{
/**
* Retrieve the response.
*
* @return SaloonResponse
*/
public function getResponse(): SaloonResponse
public function getResponse(): Response
{
return $this->getSaloonResponse();
}
Expand Down
14 changes: 8 additions & 6 deletions src/Requests/Reports/DownloadReportRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
namespace Carboneio\SDK\Requests\Reports;

/** Saloon Class */
use Sammyjo20\Saloon\Constants\Saloon;
use Sammyjo20\Saloon\Traits\Plugins\HasJsonBody;
use Sammyjo20\Saloon\Http\SaloonRequest;
use Saloon\Constants\Saloon;
use Saloon\Contracts\Body\HasBody;
use Saloon\Traits\Body\HasJsonBody;
use Saloon\Http\Request;
use Saloon\Enums\Method;

class DownloadReportRequest extends SaloonRequest
class DownloadReportRequest extends Request implements HasBody
{
use HasJsonBody;

protected ?string $method = Saloon::GET;
protected Method $method = Method::GET;

public function __construct(
private string $renderId,
) {
}

public function defineEndpoint(): string
public function resolveEndpoint(): string
{
return '/render/' . $this->renderId;
}
Expand Down
16 changes: 9 additions & 7 deletions src/Requests/Reports/RenderReportRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
namespace Carboneio\SDK\Requests\Reports;

/** Saloon */
use Sammyjo20\Saloon\Constants\Saloon;
use Sammyjo20\Saloon\Traits\Plugins\HasJsonBody;
use Sammyjo20\Saloon\Http\SaloonRequest;
use Saloon\Constants\Saloon;
use Saloon\Contracts\Body\HasBody;
use Saloon\Traits\Body\HasJsonBody;
use Saloon\Http\Request;
use Saloon\Enums\Method;

/** Carbone SDK Class */
use Carboneio\SDK\Responses\RenderReportResponse;

class RenderReportRequest extends SaloonRequest
class RenderReportRequest extends Request implements HasBody
{
use HasJsonBody;

protected ?string $method = Saloon::POST;
protected Method $method = Method::POST;

protected ?string $response = RenderReportResponse::class;

Expand All @@ -24,12 +26,12 @@ public function __construct(
) {
}

public function defineEndpoint(): string
public function resolveEndpoint(): string
{
return '/render/' . $this->templateId;
}

public function defaultData(): array
public function defaultBody(): array
{
return $this->data;
}
Expand Down
14 changes: 8 additions & 6 deletions src/Requests/StatusRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
namespace Carboneio\SDK\Requests;

/** Saloon Class */
use Sammyjo20\Saloon\Constants\Saloon;
use Sammyjo20\Saloon\Traits\Plugins\HasJsonBody;
use Sammyjo20\Saloon\Http\SaloonRequest;
use Saloon\Constants\Saloon;
use Saloon\Contracts\Body\HasBody;
use Saloon\Traits\Body\HasJsonBody;
use Saloon\Http\Request;
use Saloon\Enums\Method;

class StatusRequest extends SaloonRequest
class StatusRequest extends Request implements HasBody
{
use HasJsonBody;

protected ?string $method = Saloon::GET;
protected Method $method = Method::GET;

public function __construct() {
}

public function defineEndpoint(): string
public function resolveEndpoint(): string
{
return '/status';
}
Expand Down
14 changes: 8 additions & 6 deletions src/Requests/Templates/DeleteTemplateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
namespace Carboneio\SDK\Requests\Templates;

/** Saloon Class */
use Sammyjo20\Saloon\Constants\Saloon;
use Sammyjo20\Saloon\Traits\Plugins\HasJsonBody;
use Sammyjo20\Saloon\Http\SaloonRequest;
use Saloon\Constants\Saloon;
use Saloon\Contracts\Body\HasBody;
use Saloon\Traits\Body\HasJsonBody;
use Saloon\Http\Request;
use Saloon\Enums\Method;

class DeleteTemplateRequest extends SaloonRequest
class DeleteTemplateRequest extends Request implements HasBody
{
use HasJsonBody;

protected ?string $method = Saloon::DELETE;
protected Method $method = Method::DELETE;

public function __construct(
private string $templateId
) {
}

public function defineEndpoint(): string
public function resolveEndpoint(): string
{
return '/template/' . $this->templateId;
}
Expand Down
14 changes: 8 additions & 6 deletions src/Requests/Templates/DownloadTemplateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
namespace Carboneio\SDK\Requests\Templates;

/** Saloon Class */
use Sammyjo20\Saloon\Constants\Saloon;
use Sammyjo20\Saloon\Traits\Plugins\HasJsonBody;
use Sammyjo20\Saloon\Http\SaloonRequest;
use Saloon\Constants\Saloon;
use Saloon\Contracts\Body\HasBody;
use Saloon\Traits\Body\HasJsonBody;
use Saloon\Http\Request;
use Saloon\Enums\Method;

class DownloadTemplateRequest extends SaloonRequest
class DownloadTemplateRequest extends Request implements HasBody
{
use HasJsonBody;

protected ?string $method = Saloon::GET;
protected Method $method = Method::GET;

public function __construct(
private string $templateId
) {
}

public function defineEndpoint(): string
public function resolveEndpoint(): string
{
return '/template/' . $this->templateId;
}
Expand Down
16 changes: 9 additions & 7 deletions src/Requests/Templates/UploadTemplateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
namespace Carboneio\SDK\Requests\Templates;

/** Saloon Class */
use Sammyjo20\Saloon\Constants\Saloon;
use Sammyjo20\Saloon\Traits\Plugins\HasJsonBody;
use Sammyjo20\Saloon\Http\SaloonRequest;
use Saloon\Constants\Saloon;
use Saloon\Contracts\Body\HasBody;
use Saloon\Traits\Body\HasJsonBody;
use Saloon\Http\Request;
use Saloon\Enums\Method;

/** Carbone SDK Class */
use Carboneio\SDK\Responses\UploadTemplateResponse;

class UploadTemplateRequest extends SaloonRequest
class UploadTemplateRequest extends Request implements HasBody
{
use HasJsonBody;

protected ?string $method = Saloon::POST;
protected Method $method = Method::POST;

protected ?string $response = UploadTemplateResponse::class;

Expand All @@ -23,12 +25,12 @@ public function __construct(
) {
}

public function defineEndpoint(): string
public function resolveEndpoint(): string
{
return '/template';
}

public function defaultData(): array
public function defaultBody(): array
{
return [
'template' => $this->templateAsBase64,
Expand Down
23 changes: 13 additions & 10 deletions src/RequestsCollection/RendersCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Carboneio\SDK\RequestsCollection;

/** Saloon Abstracts */
use Sammyjo20\Saloon\Http\RequestCollection;

/** Requests */
use Carboneio\SDK\Requests\Reports\RenderReportRequest;
use Carboneio\SDK\Requests\Reports\DownloadReportRequest;
Expand All @@ -13,20 +10,26 @@
use Carboneio\SDK\Responses\CarboneSdkResponse;
use Carboneio\SDK\Responses\RenderReportResponse;

class RendersCollection extends RequestCollection
use Saloon\Repositories\RequestCollection;
use Saloon\Http\Connector;

class RendersCollection
{
protected Connector $connector;

public function __construct(Connector $connector)
{
$this->connector = $connector;
}

public function render(string $templateId, array $data): RenderReportResponse
{
return (new RenderReportRequest($templateId, $data))
->setConnector($this->connector)
->send();
return $this->connector->send(new RenderReportRequest($templateId, $data));
}

public function download(string $renderId): CarboneSdkResponse
{
return (new DownloadReportRequest($renderId))
->setConnector($this->connector)
->send();
return $this->connector->send(new DownloadReportRequest($renderId));
}
}

Loading

0 comments on commit dcdcb59

Please sign in to comment.