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

Minor refactoring and improvement #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"extra": {
"laravel": {
"providers": [
"AirLST\\CoreSdk\\ServiceProvider"
"AirLST\\CoreSdk\\AirLSTCoreServiceProvider"
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions config/airlst-sdk.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
return [
'api' => [
'base_uri' => env('AIRLST_CORE_SDK_API_BASE_URI', 'https://v1.api.airlst.com/api'),
'debug' => boolval(env('AIRLST_CORE_SDK_API_DEBUG', false)),
'debug' => (bool) env('AIRLST_CORE_SDK_API_DEBUG', false),
'auth_token' => env('AIRLST_CORE_SDK_API_AUTH_TOKEN'),
],
'webhooks' => [
'secret' => env('AIRLST_CORE_SDK_WEBHOOK_SECRET')
]
],
];
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
# AirLST Laravel SDK Package

## Installation

```php
composer require airlst/core-sdk
```

## Publish the config

```php
php artisan vendor:publish --vendor="AirLST\CoreSdk\AirLSTServiceProvider" --tag="config"
```

## Usage

### Example of general retrieve and work of a worker (using guestlists for this example)

```php
use AirLST\Core\Facades\AirLSTCoreApi;
use AirLST\CoreSdk\Facades\AirLSTCoreApi;

$apiWorker = AirLSTCoreApi::guestlist();

Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php → src/AirLSTServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @author Michael Thaller <[email protected]>
*/
class ServiceProvider extends \Illuminate\Support\ServiceProvider
class AirLSTServiceProvider extends \Illuminate\Support\ServiceProvider
{

/**
Expand Down
28 changes: 15 additions & 13 deletions src/Api/WorkerCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ class WorkerCreator
*/
public function __call($name, $arguments)
{
if (Arr::has($this->availableWorkers, $name)) {
$className = Arr::get($this->availableWorkers, $name);

/** @var ApiWorker $newInstance */
$newInstance = new $className(...$arguments);

if($token = config('airlst-sdk.api.auth_token')) {
$newInstance->setAuthorizationToken($token);
}

return $newInstance;
throw_unless(
! Arr::has($this->availableWorkers, $name),
WorkerNotFoundException::class,
"No worker for key $name was found"
);

$className = Arr::get($this->availableWorkers, $name);

/** @var ApiWorker $newInstance */
$newInstance = new $className(...$arguments);

if($token = config('airlst-sdk.api.auth_token')) {
$newInstance->setAuthorizationToken($token);
}

throw new WorkerNotFoundException('No worker for key "' . $name . '" was found');
return $newInstance;
}
}