Skip to content

Commit

Permalink
Merge pull request #1 from Print-one/ticket/2269570838-update-api-ver…
Browse files Browse the repository at this point in the history
…sion-v2
  • Loading branch information
PaulRill00 authored Jun 10, 2024
2 parents 8b1960f + 890277d commit 5635182
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 196 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,27 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.0, 8.1]
laravel: [8.*, 9.*]
php: [8.1, 8.2, 8.3]
laravel: [9.*, 10.*, 11.*]
stability: [prefer-stable]
include:
- laravel: 8.*
testbench: 6.*
- laravel: 9.*
testbench: 7.*
phpunit: ^9.5.10
illuminate_contracts: ^9.0
- laravel: 10.*
testbench: 8.*
phpunit: ^9.6
illuminate_contracts: ^10.0
- laravel: 11.*
testbench: 9.*
phpunit: ^10.5
illuminate_contracts: ^11.0
exclude:
- php: 8.1
laravel: 11.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -42,7 +52,7 @@ jobs:
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "phpunit/phpunit:${{ matrix.phpunit }}" "illuminate/contracts:${{ matrix.illuminate_contracts }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: List Installed Dependencies
Expand Down
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "print-one/print-one-laravel",
"description": "This is my package print-one",
"keywords": [
"nexibi",
"laravel",
"print.one",
"printing",
Expand All @@ -28,19 +27,21 @@
{
"name": "Print.one Development",
"email": "dev@print.one",
"role": "Developer"
"role": "Developer"
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-iconv": "*",
"guzzlehttp/guzzle": "^7.5",
"illuminate/contracts": "^8.0|^9.0",
"illuminate/contracts": "^9.0",
"laravel/framework": "9.*",
"orchestra/testbench": "7.*",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-package-tools": "^1.12.0|^1.13.6"
},
"require-dev": {
"laravel/pint": "^1.0",
"orchestra/testbench": "^6.0|^7.0",
"phpunit/phpunit": "^9.5"
"laravel/pint": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 6 additions & 5 deletions src/Contracts/PrintOneApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
use Illuminate\Support\Collection;
use Nexibi\PrintOne\DTO\Address;
use Nexibi\PrintOne\DTO\Order;
use Nexibi\PrintOne\DTO\Postcard;
use Nexibi\PrintOne\DTO\Template;
use Nexibi\PrintOne\Enums\Finish;

interface PrintOneApi
{
public function templates(int $page, int $size): Collection;
public function templates(int $page, int $limit): Collection;

public function order(
Postcard $postcard,
array $mergeVariables,
string $templateId,
Finish $finish,
Address $recipient,
Address $sender,
Address $recipient
array $mergeVariables = []
): Order;

public function preview(Template $template, int $retryTimes = 5): string;
Expand Down
11 changes: 11 additions & 0 deletions src/DTO/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ public function __construct(
//
}

public static function fromArray(array $data): self
{
return new Address(
name: $data['name'],
address: $data['address'],
postalCode: $data['postalCode'],
city: $data['city'],
country: $data['country']
);
}

public function toArray(): array
{
return [
Expand Down
10 changes: 8 additions & 2 deletions src/DTO/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use Carbon\Carbon;
use Illuminate\Contracts\Support\Arrayable;
use Nexibi\PrintOne\Enums\Finish;

class Order implements Arrayable
{
public function __construct(
public string $id,
public string $status,
public string $templateId,
public ?Finish $finish,
public Carbon $createdAt,
public bool $isBillable,
) {
Expand All @@ -21,19 +24,22 @@ public static function fromArray(array $data): self
return new Order(
id: $data['id'],
status: $data['status'],
templateId: $data['templateId'],
finish: Finish::tryFrom($data['finish']),
createdAt: Carbon::parse($data['createdAt']),
isBillable: $data['isBillable']
);
}


public function toArray(): array
{
return [
'id' => $this->id,
'status' => $this->status,
'templateId' => $this->templateId,
'finish' => $this->finish,
'createdAt' => $this->createdAt->toDateTimeString(),
'isBillable' => $this->isBillable
'isBillable' => $this->isBillable,
];
}
}
32 changes: 0 additions & 32 deletions src/DTO/Postcard.php

This file was deleted.

7 changes: 5 additions & 2 deletions src/DTO/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Nexibi\PrintOne\DTO;

use Carbon\Carbon;
use Nexibi\PrintOne\Enums\Format;

class Template
{
public function __construct(
public string $id,
public string $name,
public string $format,
public ?Format $format,
public int $version,
public Carbon $updatedAt
) {
Expand All @@ -18,10 +19,12 @@ public function __construct(

public static function fromArray(array $array): self
{
$format = (is_string($array['format'])) ? Format::tryFrom($array['format']) : $array['format'];

return new self(
id: $array['id'],
name: $array['name'],
format: $array['format'],
format: $format,
version: (int) $array['version'],
updatedAt: Carbon::parse($array['updatedAt'], 'UTC'),
);
Expand Down
9 changes: 9 additions & 0 deletions src/Enums/Finish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Nexibi\PrintOne\Enums;

enum Finish: string
{
case GLOSSY = 'GLOSSY';
case MATTE = 'MATTE';
}
16 changes: 4 additions & 12 deletions src/Enums/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,9 @@

namespace Nexibi\PrintOne\Enums;

class Format
enum Format: string
{
public const SQ15 = 'POSTCARD_SQ15';

public const A5 = 'POSTCARD_A5';

public const A6 = 'POSTCARD_A6';

public const ECO_SQ15 = 'ECOCARD_SQ15';

public const ECO_A5 = 'ECOCARD_A5';

public const ECO_A6 = 'ECOCARD_A6';
case SQ15 = 'POSTCARD_SQ15';
case A5 = 'POSTCARD_A5';
case A6 = 'POSTCARD_A6';
}
20 changes: 11 additions & 9 deletions src/Facades/Fake.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Nexibi\PrintOne\Contracts\PrintOneApi;
use Nexibi\PrintOne\DTO\Address;
use Nexibi\PrintOne\DTO\Order;
use Nexibi\PrintOne\DTO\Postcard;
use Nexibi\PrintOne\DTO\Template;
use Nexibi\PrintOne\Enums\Finish;
use PHPUnit\Framework\Assert;

class Fake implements PrintOneApi
Expand All @@ -27,33 +27,35 @@ public function __construct(array $templates = [])
$this->templates = collect($templates);
}

public function templates(int $page, int $size): Collection
public function templates(int $page, int $limit): Collection
{
return $this->templates;
}

public function order(Postcard $postcard, array $mergeVariables, Address $sender, Address $recipient): Order
public function order(string $templateId, Finish $finish, Address $recipient, Address $sender, array $mergeVariables = []): Order
{
$this->orders->push(['postcard' => $postcard, 'from' => $sender, 'to' => $recipient]);
$this->orders->push(['templateId' => $templateId, 'finish' => $finish, 'from' => $sender, 'to' => $recipient]);

return new Order(
id: Str::uuid(), status: 'status', createdAt: now(), isBillable: false
id: Str::uuid(), status: 'status', templateId: $templateId, finish: $finish, createdAt: now(), isBillable: false
);
}

public function preview(Template $template, int $timeout = 30): string
public function preview(Template $template, int $retryTimes = 30): string
{
$this->viewed->push($template);

return '';
}

public function assertOrdered(Postcard $postcard, Address $from, Address $to): void
public function assertOrdered(string $templateId, Finish $finish, Address $from, Address $to): void
{
$order = $this->orders->where('postcard', $postcard)->where('from', $from)->where('to', $to)->first();
$order = $this->orders->where('templateId', $templateId)
->where('finish', $finish)
->where('from', $from)->where('to', $to)->first();
Assert::assertNotNull(
$order,
"Failed asserting postcard with front: '{$postcard->front}' and back: '{$postcard->back}' was ordered from {$from->name} to {$to->name}"
"Failed asserting postcard with template ID: '{$templateId}' and finish: '{$finish->value}' was ordered from {$from->name} to {$to->name}"
);
}

Expand Down
1 change: 1 addition & 0 deletions src/Facades/PrintOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* @see \Nexibi\PrintOne\PrintOne
*
* @mixin \Nexibi\PrintOne\PrintOne
*/
class PrintOne extends Facade
Expand Down
Loading

0 comments on commit 5635182

Please sign in to comment.