Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added event resource #1

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHPUnit
run: vendor/bin/phpunit

- name: Run PHPStan
run: vendor/bin/phpstan analyze -l 6 src
18 changes: 5 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "airlst/sdk-php",
"description": "This package is a SDK for handling AirLST Core API calls",
"type": "library",
"minimum-stability": "dev",
"minimum-stability": "stable",
"authors": [
{
"name": "Jantinn Erezo",
Expand All @@ -12,13 +12,12 @@
],
"require": {
"guzzlehttp/guzzle": "^6.0|^7.0",
"php": "^8.2"
"php": "^8.3"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0|^3.14",
"mockery/mockery": "^1.4",
"nunomaduro/larastan": "^1.0|^2.4",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
"phpunit/phpunit": "^8.0|^9.0|^10.0"
},
"autoload": {
Expand All @@ -35,16 +34,9 @@
"test": "./vendor/bin/phpunit",
"test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html .coverage",
"fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --config=.php-cs-fixer.php",
"phpstan": "./vendor/bin/phpstan analyse"
"phpstan": "./vendor/bin/phpstan analyse src"
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"AirLST\\SdkPhp\\Laravel\\AirLSTSdkPhpServiceProvider"
]
}
}
}
}
9 changes: 0 additions & 9 deletions config/config.php

This file was deleted.

57 changes: 0 additions & 57 deletions src/Client.php

This file was deleted.

95 changes: 95 additions & 0 deletions src/CoreApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

declare(strict_types=1);

namespace AirLST\SdkPhp;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\HandlerStack;

class CoreApi
{
public string $baseURL = 'https://airlst.app';
public string $apiKey;
public string $locale = 'de-DE';
public string $eventId;
protected ?HandlerStack $handler = null;

public function setBaseURL(string $baseURL): self
{
$this->baseURL = $baseURL;

return $this;
}

public function setApiKey(string $apiKey): self
{
$this->apiKey = $apiKey;

return $this;
}

public function setLocale(string $locale): self
{
$this->locale = $locale;

return $this;
}

public function setEventId(string $eventId): self
{
$this->eventId = $eventId;

return $this;
}

/**
* @return array<string, string>
*/
public function getRequestHeaders(): array
{
return [
'content-type' => 'application/json',
'accept' => 'application/json',
'x-api-key' => $this->apiKey,
'accept-language' => $this->locale,
];
}

public function setHandler(HandlerStack $handler): void
{
$this->handler = $handler;
}

/**
* @param string $uri
* @param RequestMethod $method
* @param array<mixed> $options
* @return array<mixed>
*/
public function send(
string $uri,
RequestMethod $method = RequestMethod::GET,
array $options = []
): array
{
try {
$client = new Client([
'base_uri' => $this->baseURL,
'headers' => $this->getRequestHeaders(),
'handler' => $this->handler
]);

$response = $client->request($method->value, "/api$uri", $options);

return json_decode((string) $response->getBody(), true);
} catch (ClientException $exception) {
throw new \RuntimeException(
$exception->getResponse()->getBody()->getContents(),
$exception->getCode(),
$exception
);
}
}
}
32 changes: 0 additions & 32 deletions src/Laravel/AirLSTSdkPhpServiceProvider.php

This file was deleted.

16 changes: 16 additions & 0 deletions src/Resources/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace AirLST\SdkPhp\Resources;

use AirLST\SdkPhp\CoreApi;

class Event extends CoreApi
{
/**
* @return array<mixed>
*/
public function get(): array
{
return $this->send("/events/{$this->eventId}");
}
}
53 changes: 37 additions & 16 deletions src/Resources/Guest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,59 @@

namespace AirLST\SdkPhp\Resources;

use AirLST\SdkPhp\Client;
use AirLST\SdkPhp\CoreApi;
use AirLST\SdkPhp\RequestMethod;

class Guest extends Resource
class Guest extends CoreApi
{
public function __construct(protected Client $client)
{
}

/**
* @return array{'data': array{'code': string}}
*/
public function validateCode(string $code): array
{
return $this->client->send("{$this->getEventURL()}/guests/validate-code", RequestMethod::POST, [
'form_params' => ['code' => $code],
]);
return $this->send(
uri: "{$this->getEventURL()}/guests/validate-code",
method: RequestMethod::POST,
options: ['form_params' => ['code' => $code]]
);
}

/**
* @return array{'data': array<mixed>}
*/
public function get(string $code): array
{
return $this->client->send("{$this->getEventURL()}/guests/{$code}");
return $this->send("{$this->getEventURL()}/guests/{$code}");
}

/**
* @param array<mixed> $data
* @return array{'data': array<mixed>}
*/
public function create(array $data): array
{
return $this->client->send("{$this->getEventURL()}/guests", RequestMethod::POST, [
'form_params' => $data
]);
return $this->send(
uri: "{$this->getEventURL()}/guests",
method: RequestMethod::POST,
options: ['form_params' => $data]
);
}

/**
* @param array<mixed> $data
* @return array{'data': array<mixed>}
*/
public function update(string $code, array $data): array
{
return $this->client->send("{$this->getEventURL()}/guests/{$code}", RequestMethod::PUT, [
'form_params' => $data
]);
return $this->send(
uri: "{$this->getEventURL()}/guests/{$code}",
method: RequestMethod::PUT,
options: ['form_params' => $data]
);
}

public function getEventURL(): string
{
return "/events/{$this->eventId}";
}
}
20 changes: 0 additions & 20 deletions src/Resources/Resource.php

This file was deleted.

Loading
Loading