Skip to content

Commit 5a4a126

Browse files
committed
WIP
1 parent 96005c8 commit 5a4a126

File tree

10 files changed

+58
-66
lines changed

10 files changed

+58
-66
lines changed

src/Dto/Tickets/AllTicketsDTO.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace CodebarAg\Zendesk\Dto\Tickets;
44

5-
use Illuminate\Support\Collection;
65
use Saloon\Http\Response;
76
use Spatie\LaravelData\Data;
87

@@ -20,7 +19,7 @@ public static function fromResponse(Response $response): self
2019
{
2120
$data = $response->json();
2221

23-
return new static(
22+
return new self(
2423
tickets: collect($data['tickets'])->map(function (array $ticket) {
2524
return SingleTicketDTO::fromArray($ticket);
2625
})->toArray(),

src/Dto/Tickets/Attachments/AttachmentDTO.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace CodebarAg\Zendesk\Dto\Tickets\Attachments;
44

55
use CodebarAg\Zendesk\Enums\MalwareScanResult;
6-
use Illuminate\Support\Carbon;
7-
use Saloon\Http\Response;
86
use Spatie\LaravelData\Data;
97

108
final class AttachmentDTO extends Data
@@ -37,7 +35,7 @@ public static function fromArray(array $data): self
3735
}
3836
}
3937

40-
return new static(
38+
return new self(
4139
content_type: $data['content_type'] ?? null,
4240
content_url: $data['content_url'] ?? null,
4341
deleted: $data['deleted'] ?? null,

src/Dto/Tickets/Attachments/ThumbnailDTO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626

2727
public static function fromArray(array $data): self
2828
{
29-
return new static(
29+
return new self(
3030
content_type: $data['content_type'] ?? null,
3131
content_url: $data['content_url'] ?? null,
3232
deleted: $data['deleted'] ?? null,

src/Dto/Tickets/Attachments/UploadDTO.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace CodebarAg\Zendesk\Dto\Tickets\Attachments;
44

5-
use CodebarAg\Zendesk\Enums\MalwareScanResult;
65
use Illuminate\Support\Carbon;
76
use Saloon\Http\Response;
87
use Spatie\LaravelData\Data;
@@ -34,7 +33,7 @@ public static function fromArray(array $data): self
3433
}
3534
}
3635

37-
return new static(
36+
return new self(
3837
token: $data['token'] ?? null,
3938
expires_at: Carbon::parse($data['expires_at'] ?? null),
4039
attachments: $attachments,

src/Dto/Tickets/Comments/CommentDTO.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace CodebarAg\Zendesk\Dto\Tickets\Comments;
44

5-
use CodebarAg\Zendesk\Dto\Tickets\Attachments\AttachmentDTO;
6-
use CodebarAg\Zendesk\Dto\Tickets\SingleTicketDTO;
75
use Illuminate\Support\Carbon;
86
use Spatie\LaravelData\Data;
97

@@ -28,7 +26,7 @@ public function __construct(
2826

2927
public static function fromArray(array $data): self
3028
{
31-
return new static(
29+
return new self(
3230
attachments: $data['attachments'] ?? null,
3331
audit_id: $data['audit_id'] ?? null,
3432
author_id: $data['author_id'] ?? null,

src/Dto/Tickets/CountTicketsDTO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static function fromResponse(Response $response): self
1818
{
1919
$data = $response->json()['count'];
2020

21-
return new static(
21+
return new self(
2222
value: $data['value'],
2323
refreshed_at: Carbon::parse($data['refreshed_at']),
2424
);

src/Dto/Tickets/SingleTicketDTO.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Illuminate\Support\Carbon;
99
use Saloon\Http\Response;
1010
use Spatie\LaravelData\Data;
11-
use function Pest\Laravel\instance;
1211

1312
final class SingleTicketDTO extends Data
1413
{
@@ -82,19 +81,19 @@ public static function fromArray(array $data): self
8281
$comment = CommentDTO::fromArray($comment);
8382
}
8483

85-
$priority = array_key_exists('priority', $data) ? $data['priority'] : null;
84+
$priority = array_key_exists('priority', $data) ? $data['priority'] : null;
8685

8786
if ($priority && ! $priority instanceof TicketPriority) {
8887
$priority = TicketPriority::tryFrom($priority);
8988
}
9089

91-
$type = array_key_exists('type', $data) ? $data['type'] : null;
90+
$type = array_key_exists('type', $data) ? $data['type'] : null;
9291

9392
if ($type && ! $type instanceof TicketType) {
9493
$type = TicketType::tryFrom($type);
9594
}
9695

97-
return new static(
96+
return new self(
9897
allow_attachments: $data['allow_attachments'] ?? null,
9998
allow_channelback: $data['allow_channelback'] ?? null,
10099
assignee_email: $data['assignee_email'] ?? null,

src/Requests/CreateAttachmentRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace CodebarAg\Zendesk\Requests;
44

5-
use CodebarAg\Zendesk\Dto\Tickets\Attachments\AttachmentDTO;
65
use CodebarAg\Zendesk\Dto\Tickets\Attachments\UploadDTO;
76
use Saloon\Contracts\Body\HasBody;
87
use Saloon\Contracts\Response;
@@ -25,7 +24,8 @@ public function __construct(
2524
protected string $fileName,
2625
protected string $mimeType,
2726
protected mixed $stream,
28-
) { }
27+
) {
28+
}
2929

3030
protected function defaultHeaders(): array
3131
{

src/Requests/CreateSingleTicketRequest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace CodebarAg\Zendesk\Requests;
44

5-
use CodebarAg\Zendesk\Dto\Tickets\CreateTicketDTO;
65
use CodebarAg\Zendesk\Dto\Tickets\SingleTicketDTO;
76
use Saloon\Contracts\Body\HasBody;
87
use Saloon\Contracts\Response;

src/ZendeskConnector.php

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,51 @@
88

99
class ZendeskConnector extends Connector
1010
{
11-
public function resolveBaseUrl(): string
12-
{
13-
if (!config('zendesk.subdomain')) {
14-
throw new \Exception('No subdomain provided.', 500);
15-
}
16-
17-
return 'https://' . config('zendesk.subdomain') . '.zendesk.com/api/v2';
18-
}
19-
20-
protected function defaultHeaders(): array
21-
{
22-
return [
23-
'Content-Type' => 'application/json',
24-
'Accept' => 'application/json',
25-
];
26-
}
27-
28-
protected function defaultAuth(): ?Authenticator
29-
{
30-
if (!config('zendesk.auth.method')) {
31-
throw new \Exception('No authentication method provided.', 500);
32-
}
33-
34-
if (!config('zendesk.auth.email_address')) {
35-
throw new \Exception('No email address provided.', 500);
36-
}
37-
38-
if (config('zendesk.auth.method') === 'basic' && !config('zendesk.auth.password')) {
39-
throw new \Exception('No password provided for basic authentication.', 500);
40-
}
41-
42-
if (config('zendesk.auth.method') === 'basic' && !config('zendesk.auth.password')) {
43-
throw new \Exception('No password provided for basic authentication.', 500);
44-
}
45-
46-
if (config('zendesk.auth.method') === 'token' && !config('zendesk.auth.api_token')) {
47-
throw new \Exception('No API token provided for token authentication.', 500);
48-
}
49-
50-
$authenticationString = match (config('zendesk.auth.method')) {
51-
'basic' => $authenticationString = config('zendesk.auth.email_address') . ':' . config('zendesk.auth.password'),
52-
'token' => $authenticationString = config('zendesk.auth.email_address') . '/token:' . config('zendesk.auth.api_token'),
53-
default => throw new \Exception('Invalid authentication method provided.', 500),
54-
};
55-
56-
return new TokenAuthenticator(base64_encode($authenticationString), 'Basic');
57-
}
11+
public function resolveBaseUrl(): string
12+
{
13+
if (! config('zendesk.subdomain')) {
14+
throw new \Exception('No subdomain provided.', 500);
15+
}
16+
17+
return 'https://'.config('zendesk.subdomain').'.zendesk.com/api/v2';
18+
}
19+
20+
protected function defaultHeaders(): array
21+
{
22+
return [
23+
'Content-Type' => 'application/json',
24+
'Accept' => 'application/json',
25+
];
26+
}
27+
28+
protected function defaultAuth(): ?Authenticator
29+
{
30+
if (! config('zendesk.auth.method')) {
31+
throw new \Exception('No authentication method provided.', 500);
32+
}
33+
34+
if (! config('zendesk.auth.email_address')) {
35+
throw new \Exception('No email address provided.', 500);
36+
}
37+
38+
if (config('zendesk.auth.method') === 'basic' && ! config('zendesk.auth.password')) {
39+
throw new \Exception('No password provided for basic authentication.', 500);
40+
}
41+
42+
if (config('zendesk.auth.method') === 'basic' && ! config('zendesk.auth.password')) {
43+
throw new \Exception('No password provided for basic authentication.', 500);
44+
}
45+
46+
if (config('zendesk.auth.method') === 'token' && ! config('zendesk.auth.api_token')) {
47+
throw new \Exception('No API token provided for token authentication.', 500);
48+
}
49+
50+
$authenticationString = match (config('zendesk.auth.method')) {
51+
'basic' => $authenticationString = config('zendesk.auth.email_address').':'.config('zendesk.auth.password'),
52+
'token' => $authenticationString = config('zendesk.auth.email_address').'/token:'.config('zendesk.auth.api_token'),
53+
default => throw new \Exception('Invalid authentication method provided.', 500),
54+
};
55+
56+
return new TokenAuthenticator(base64_encode($authenticationString), 'Basic');
57+
}
5858
}

0 commit comments

Comments
 (0)