Skip to content

Commit bb0a995

Browse files
committed
WIP
1 parent a7d92be commit bb0a995

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+732
-1027
lines changed

README.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ We provide DTOs for the following:
127127
#### Create a ticket
128128

129129
```php
130-
use CodebarAg\Bexio\Requests\CreateSingleTicketRequest;
131-
use CodebarAg\Bexio\DTOs\SingleTicketDTO;
132-
use CodebarAg\Bexio\DTOs\CommentDTO;
133-
use CodebarAg\Bexio\Enums\TicketPriority;
130+
use CodebarAg\Bexio\DTOs\CommentDTO;use CodebarAg\Bexio\DTOs\SingleTicketDTO;use CodebarAg\Bexio\Enums\TicketPriority;use CodebarAg\Bexio\Requests\BKUP\CreateSingleTicketRequest;
134131
...
135132

136133
$ticketResponse = $connector->send(
@@ -161,10 +158,10 @@ $ticket = $ticketResponse->dto();
161158
#### List all tickets
162159

163160
```php
164-
use CodebarAg\Bexio\Requests\AllTicketsRequest;
161+
use CodebarAg\Bexio\Requests\Contacts\FetchAListOfContacts;
165162
...
166163

167-
$listTicketResponse = $connector->send(new AllTicketsRequest());
164+
$listTicketResponse = $connector->send(new FetchAListOfContacts());
168165
$listTicketResponse->dto();
169166
````
170167

@@ -193,9 +190,7 @@ $showTicketResponse->dto();
193190
#### Upload an attachment
194191

195192
```php
196-
use CodebarAg\Bexio\Requests\CreateAttachmentRequest;
197-
use CodebarAg\Bexio\Requests\CreateSingleTicketRequest;
198-
use Illuminate\Support\Facades\Storage;
193+
use CodebarAg\Bexio\Requests\BKUP\CreateSingleTicketRequest;use CodebarAg\Bexio\Requests\CreateAttachmentRequest;use Illuminate\Support\Facades\Storage;
199194

200195
$uploadResponse = $connector->send(
201196
new CreateAttachmentRequest(

composer.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@
7474
"laravel": {
7575
"providers": [
7676
"CodebarAg\\Bexio\\BexioServiceProvider"
77-
],
78-
"aliases": {
79-
"Bexio": "CodebarAg\\Bexio\\Facades\\Bexio"
80-
}
77+
]
8178
}
8279
},
8380
"minimum-stability": "dev",

config/bexio.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return [
4+
'auth' => [
5+
'token' => env('BEXIO_API_TOKEN'),
6+
],
7+
];

config/zendesk.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Bexio.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/BexioConnector.php

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ class BexioConnector extends Connector
1010
{
1111
public function resolveBaseUrl(): string
1212
{
13-
if (! config('bexio.subdomain')) {
14-
throw new \Exception('No subdomain provided.', 500);
15-
}
16-
17-
return 'https://'.config('bexio.subdomain').'.bexio.com/api/v2';
13+
return 'https://api.bexio.com/2.0';
1814
}
1915

2016
protected function defaultHeaders(): array
@@ -27,37 +23,6 @@ protected function defaultHeaders(): array
2723

2824
protected function defaultAuth(): ?Authenticator
2925
{
30-
$authenticationString = $this->setAuth();
31-
32-
return new TokenAuthenticator(base64_encode($authenticationString), 'Basic');
33-
}
34-
35-
public function setAuth(): string
36-
{
37-
if (! config('bexio.auth.method')) {
38-
throw new \Exception('No authentication method provided.', 500);
39-
}
40-
41-
if (! config('bexio.auth.email_address')) {
42-
throw new \Exception('No email address provided.', 500);
43-
}
44-
45-
if (config('bexio.auth.method') === 'basic' && ! config('bexio.auth.password')) {
46-
throw new \Exception('No password provided for basic authentication.', 500);
47-
}
48-
49-
if (config('bexio.auth.method') === 'basic' && ! config('bexio.auth.password')) {
50-
throw new \Exception('No password provided for basic authentication.', 500);
51-
}
52-
53-
if (config('bexio.auth.method') === 'token' && ! config('bexio.auth.api_token')) {
54-
throw new \Exception('No API token provided for token authentication.', 500);
55-
}
56-
57-
return match (config('bexio.auth.method')) {
58-
'basic' => config('bexio.auth.email_address').':'.config('bexio.auth.password'),
59-
'token' => config('bexio.auth.email_address').'/token:'.config('bexio.auth.api_token'),
60-
default => throw new \Exception('Invalid authentication method provided.', 500),
61-
};
26+
return new TokenAuthenticator(config('bexio.auth.token'), 'Bearer');
6227
}
6328
}

src/BexioServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public function configurePackage(Package $package): void
1111
{
1212
$package
1313
->name('laravel-bexio')
14-
->hasConfigFile();
14+
->hasConfigFile('bexio');
1515
}
1616
}

src/Dto/ContactDTO.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto;
4+
5+
use Exception;
6+
use Illuminate\Support\Arr;
7+
use Saloon\Http\Response;
8+
use Spatie\LaravelData\Data;
9+
10+
class ContactDTO extends Data
11+
{
12+
public function __construct(
13+
public int $user_id, //ref to user
14+
public int $owner_id,
15+
public int $id,
16+
public int $nr,
17+
public int $contact_type_id,
18+
public string $name_1,
19+
public ?string $name_2,
20+
public ?int $salutation_id, //ref to salutation
21+
public ?int $salutation_form_id,
22+
public ?int $title_id, //ref to title
23+
public ?string $birthday,
24+
public ?string $address,
25+
public ?string $postcode,
26+
public ?string $city,
27+
public ?int $country_id, //ref to country
28+
public ?string $mail,
29+
public ?string $mail_second,
30+
public ?string $phone_fixed,
31+
public ?string $phone_fixed_second,
32+
public ?string $phone_mobile,
33+
public ?string $fax,
34+
public ?string $url,
35+
public ?string $skype_name,
36+
public ?string $remarks,
37+
public ?int $language_id, //ref to language
38+
public bool $is_lead,
39+
public ?string $contact_group_ids,
40+
public ?string $contact_branch_ids,
41+
public ?string $updated_at,
42+
) {
43+
}
44+
45+
public static function fromResponse(Response $response): self
46+
{
47+
if ($response->failed()) {
48+
throw new \Exception('Failed to get all tickets', $response->status());
49+
}
50+
51+
$data = $response->json();
52+
53+
return self::fromArray($data);
54+
}
55+
56+
public static function fromArray(array $data): self
57+
{
58+
if (! $data) {
59+
throw new Exception('Unable to create DTO. Data missing from response.');
60+
}
61+
62+
return new self(
63+
id: Arr::get($data, 'id'),
64+
nr: Arr::get($data, 'nr'),
65+
contact_type_id: Arr::get($data, 'contact_type_id'),
66+
name_1: Arr::get($data, 'name_1'),
67+
name_2: Arr::get($data, 'name_2'),
68+
salutation_id: Arr::get($data, 'salutation_id'),
69+
salutation_form_id: Arr::get($data, 'salutation_form_id'),
70+
title_id: Arr::get($data, 'title_id'),
71+
birthday: Arr::get($data, 'birthday'),
72+
address: Arr::get($data, 'address'),
73+
postcode: Arr::get($data, 'postcode'),
74+
city: Arr::get($data, 'city'),
75+
country_id: Arr::get($data, 'country_id'),
76+
mail: Arr::get($data, 'mail'),
77+
mail_second: Arr::get($data, 'mail_second'),
78+
phone_fixed: Arr::get($data, 'phone_fixed'),
79+
phone_fixed_second: Arr::get($data, 'phone_fixed_second'),
80+
phone_mobile: Arr::get($data, 'phone_mobile'),
81+
fax: Arr::get($data, 'fax'),
82+
url: Arr::get($data, 'url'),
83+
skype_name: Arr::get($data, 'skype_name'),
84+
remarks: Arr::get($data, 'remarks'),
85+
language_id: Arr::get($data, 'language_id'),
86+
is_lead: Arr::get($data, 'is_lead'),
87+
contact_group_ids: Arr::get($data, 'contact_group_ids'),
88+
contact_branch_ids: Arr::get($data, 'contact_branch_ids'),
89+
user_id: Arr::get($data, 'user_id'),
90+
owner_id: Arr::get($data, 'owner_id'),
91+
updated_at: Arr::get($data, 'updated_At'),
92+
);
93+
}
94+
}

src/Dto/CreateEditContactDTO.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace CodebarAg\Bexio\Dto;
4+
5+
use Carbon\Carbon;
6+
use Exception;
7+
use Illuminate\Support\Arr;
8+
use Saloon\Http\Response;
9+
use Spatie\LaravelData\Data;
10+
11+
class CreateEditContactDTO extends Data
12+
{
13+
public function __construct(
14+
public int $user_id, //ref to user
15+
public int $owner_id,
16+
public int $contact_type_id,
17+
public string $name_1,
18+
public ?string $name_2 = null,
19+
public ?int $salutation_id = null, //ref to salutation
20+
public ?int $salutation_form = null,
21+
public ?int $titel_id = null, //ref to title
22+
public ?Carbon $birthday = null,
23+
public ?string $address = null,
24+
public ?string $postcode = null,
25+
public ?string $city = null,
26+
public ?int $country_id = null, //ref to country
27+
public ?string $mail = null,
28+
public ?string $mail_second = null,
29+
public ?string $phone_fixed = null,
30+
public ?string $phone_fixed_second = null,
31+
public ?string $phone_mobile = null,
32+
public ?string $fax = null,
33+
public ?string $url = null,
34+
public ?string $skype_name = null,
35+
public ?string $remarks = null,
36+
public ?int $language_id = null, //ref to language
37+
public ?string $contact_group_ids = null,
38+
public ?string $contact_branch_ids = null,
39+
) {
40+
}
41+
42+
public static function fromResponse(Response $response): self
43+
{
44+
if ($response->failed()) {
45+
throw new \Exception('Failed to get all tickets', $response->status());
46+
}
47+
48+
$data = $response->json();
49+
50+
return self::fromArray($data);
51+
}
52+
53+
public static function fromArray(array $data): self
54+
{
55+
if (! $data) {
56+
throw new Exception('Unable to create DTO. Data missing from response.');
57+
}
58+
59+
return new self(
60+
user_id: Arr::get($data, 'user_id'),
61+
owner_id: Arr::get($data, 'owner_id'),
62+
contact_type_id: Arr::get($data, 'contact_type_id'),
63+
name_1: Arr::get($data, 'name_1'),
64+
name_2: Arr::get($data, 'name_2'),
65+
salutation_id: Arr::get($data, 'salutation_id'),
66+
salutation_form: Arr::get($data, 'salutation_form'),
67+
titel_id: Arr::get($data, 'title_id'),
68+
birthday: Arr::get($data, 'birthday'),
69+
address: Arr::get($data, 'address'),
70+
postcode: Arr::get($data, 'postcode'),
71+
city: Arr::get($data, 'city'),
72+
country_id: Arr::get($data, 'country_id'),
73+
mail: Arr::get($data, 'mail'),
74+
mail_second: Arr::get($data, 'mail_second'),
75+
phone_fixed: Arr::get($data, 'phone_fixed'),
76+
phone_fixed_second: Arr::get($data, 'phone_fixed_second'),
77+
phone_mobile: Arr::get($data, 'phone_mobile'),
78+
fax: Arr::get($data, 'fax'),
79+
url: Arr::get($data, 'url'),
80+
skype_name: Arr::get($data, 'skype_name'),
81+
remarks: Arr::get($data, 'remarks'),
82+
language_id: Arr::get($data, 'language_id'),
83+
contact_group_ids: Arr::get($data, 'contact_group_ids'),
84+
contact_branch_ids: Arr::get($data, 'contact_branch_ids'),
85+
);
86+
}
87+
}

src/Dto/Tickets/AllTicketsDTO.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)