Skip to content

Commit d61a26f

Browse files
committed
Added event resource
1 parent cef93cb commit d61a26f

File tree

15 files changed

+369
-298
lines changed

15 files changed

+369
-298
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Set up PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: 8.3
23+
24+
- name: Install dependencies
25+
run: composer install --prefer-dist --no-progress --no-suggest
26+
27+
- name: Run PHPUnit
28+
run: vendor/bin/phpunit
29+
30+
- name: Run PHPStan
31+
run: vendor/bin/phpstan analyze -l 6 src

composer.json

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "airlst/sdk-php",
33
"description": "This package is a SDK for handling AirLST Core API calls",
44
"type": "library",
5-
"minimum-stability": "dev",
5+
"minimum-stability": "stable",
66
"authors": [
77
{
88
"name": "Jantinn Erezo",
@@ -12,13 +12,12 @@
1212
],
1313
"require": {
1414
"guzzlehttp/guzzle": "^6.0|^7.0",
15-
"php": "^8.2"
15+
"php": "^8.3"
1616
},
1717
"require-dev": {
1818
"friendsofphp/php-cs-fixer": "^2.0|^3.14",
1919
"mockery/mockery": "^1.4",
20-
"nunomaduro/larastan": "^1.0|^2.4",
21-
"orchestra/testbench": "^6.0|^7.0|^8.0",
20+
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
2221
"phpunit/phpunit": "^8.0|^9.0|^10.0"
2322
},
2423
"autoload": {
@@ -35,16 +34,9 @@
3534
"test": "./vendor/bin/phpunit",
3635
"test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html .coverage",
3736
"fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --config=.php-cs-fixer.php",
38-
"phpstan": "./vendor/bin/phpstan analyse"
37+
"phpstan": "./vendor/bin/phpstan analyse src"
3938
},
4039
"config": {
4140
"sort-packages": true
42-
},
43-
"extra": {
44-
"laravel": {
45-
"providers": [
46-
"AirLST\\SdkPhp\\Laravel\\AirLSTSdkPhpServiceProvider"
47-
]
48-
}
4941
}
50-
}
42+
}

config/config.php

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

src/Client.php

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

src/CoreApi.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AirLST\SdkPhp;
6+
7+
use GuzzleHttp\Client;
8+
use GuzzleHttp\Exception\ClientException;
9+
use GuzzleHttp\HandlerStack;
10+
11+
class CoreApi
12+
{
13+
public string $baseURL = 'https://airlst.app';
14+
public string $apiKey;
15+
public string $locale = 'de-DE';
16+
public string $eventId;
17+
protected ?HandlerStack $handler = null;
18+
19+
public function setBaseURL(string $baseURL): self
20+
{
21+
$this->baseURL = $baseURL;
22+
23+
return $this;
24+
}
25+
26+
public function setApiKey(string $apiKey): self
27+
{
28+
$this->apiKey = $apiKey;
29+
30+
return $this;
31+
}
32+
33+
public function setLocale(string $locale): self
34+
{
35+
$this->locale = $locale;
36+
37+
return $this;
38+
}
39+
40+
public function setEventId(string $eventId): self
41+
{
42+
$this->eventId = $eventId;
43+
44+
return $this;
45+
}
46+
47+
/**
48+
* @return array<string, string>
49+
*/
50+
public function getRequestHeaders(): array
51+
{
52+
return [
53+
'content-type' => 'application/json',
54+
'accept' => 'application/json',
55+
'x-api-key' => $this->apiKey,
56+
'accept-language' => $this->locale,
57+
];
58+
}
59+
60+
public function setHandler(HandlerStack $handler): void
61+
{
62+
$this->handler = $handler;
63+
}
64+
65+
/**
66+
* @param string $uri
67+
* @param RequestMethod $method
68+
* @param array<mixed> $options
69+
* @return array<mixed>
70+
*/
71+
public function send(
72+
string $uri,
73+
RequestMethod $method = RequestMethod::GET,
74+
array $options = []
75+
): array
76+
{
77+
try {
78+
$client = new Client([
79+
'base_uri' => $this->baseURL,
80+
'headers' => $this->getRequestHeaders(),
81+
'handler' => $this->handler
82+
]);
83+
84+
$response = $client->request($method->value, "/api$uri", $options);
85+
86+
return json_decode((string) $response->getBody(), true);
87+
} catch (ClientException $exception) {
88+
throw new \RuntimeException(
89+
$exception->getResponse()->getBody()->getContents(),
90+
$exception->getCode(),
91+
$exception
92+
);
93+
}
94+
}
95+
}

src/Laravel/AirLSTSdkPhpServiceProvider.php

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

src/Resources/Event.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace AirLST\SdkPhp\Resources;
4+
5+
use AirLST\SdkPhp\CoreApi;
6+
7+
class Event extends CoreApi
8+
{
9+
/**
10+
* @return array<mixed>
11+
*/
12+
public function get(): array
13+
{
14+
return $this->send("/events/{$this->eventId}");
15+
}
16+
}

src/Resources/Guest.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,59 @@
44

55
namespace AirLST\SdkPhp\Resources;
66

7-
use AirLST\SdkPhp\Client;
7+
use AirLST\SdkPhp\CoreApi;
88
use AirLST\SdkPhp\RequestMethod;
99

10-
class Guest extends Resource
10+
class Guest extends CoreApi
1111
{
12-
public function __construct(protected Client $client)
13-
{
14-
}
15-
12+
/**
13+
* @return array{'data': array{'code': string}}
14+
*/
1615
public function validateCode(string $code): array
1716
{
18-
return $this->client->send("{$this->getEventURL()}/guests/validate-code", RequestMethod::POST, [
19-
'form_params' => ['code' => $code],
20-
]);
17+
return $this->send(
18+
uri: "{$this->getEventURL()}/guests/validate-code",
19+
method: RequestMethod::POST,
20+
options: ['form_params' => ['code' => $code]]
21+
);
2122
}
2223

24+
/**
25+
* @return array{'data': array<mixed>}
26+
*/
2327
public function get(string $code): array
2428
{
25-
return $this->client->send("{$this->getEventURL()}/guests/{$code}");
29+
return $this->send("{$this->getEventURL()}/guests/{$code}");
2630
}
2731

32+
/**
33+
* @param array<mixed> $data
34+
* @return array{'data': array<mixed>}
35+
*/
2836
public function create(array $data): array
2937
{
30-
return $this->client->send("{$this->getEventURL()}/guests", RequestMethod::POST, [
31-
'form_params' => $data
32-
]);
38+
return $this->send(
39+
uri: "{$this->getEventURL()}/guests",
40+
method: RequestMethod::POST,
41+
options: ['form_params' => $data]
42+
);
3343
}
3444

45+
/**
46+
* @param array<mixed> $data
47+
* @return array{'data': array<mixed>}
48+
*/
3549
public function update(string $code, array $data): array
3650
{
37-
return $this->client->send("{$this->getEventURL()}/guests/{$code}", RequestMethod::PUT, [
38-
'form_params' => $data
39-
]);
51+
return $this->send(
52+
uri: "{$this->getEventURL()}/guests/{$code}",
53+
method: RequestMethod::PUT,
54+
options: ['form_params' => $data]
55+
);
56+
}
57+
58+
public function getEventURL(): string
59+
{
60+
return "/events/{$this->eventId}";
4061
}
4162
}

src/Resources/Resource.php

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

0 commit comments

Comments
 (0)