Created BokioClient #2
No files matched your search
+2
-2
@@ -64,10 +64,10 @@
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Mattitja\\BokioApiLaravel\\BokioApiLaravelServiceProvider"
|
||||
"Mattitja\\BokioApiLaravel\\BokioServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"BokioApiLaravel": "Mattitja\\BokioApiLaravel\\Facades\\BokioApiLaravel"
|
||||
"Bokio": "Mattitja\\BokioApiLaravel\\Facades\\Bokio"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
|
||||
// config for Mattitja/BokioApiLaravel
|
||||
return [
|
||||
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
// config for Mattitja/Bokio
|
||||
return [
|
||||
'token' => env('BOKIO_TOKEN'),
|
||||
'company_id' => env('BOKIO_COMPANY_ID'),
|
||||
];
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
namespace Mattitja\BokioApiLaravel;
|
||||
|
||||
class BokioApiLaravel {}
|
||||
class Bokio {}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Mattitja\BokioApiLaravel;
|
||||
|
||||
use Spatie\LaravelPackageTools\Package;
|
||||
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
||||
|
||||
class BokioApiLaravelServiceProvider extends PackageServiceProvider
|
||||
{
|
||||
public function configurePackage(Package $package): void
|
||||
{
|
||||
/*
|
||||
* This class is a Package Service Provider
|
||||
*
|
||||
* More info: https://github.com/spatie/laravel-package-tools
|
||||
*/
|
||||
$package
|
||||
->name('bokio-api-laravel')
|
||||
->hasConfigFile();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Mattitja\BokioApiLaravel;
|
||||
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class BokioClient
|
||||
{
|
||||
public PendingRequest $request;
|
||||
|
||||
public function __construct(
|
||||
private string $accessToken,
|
||||
private string $companyId,
|
||||
private string $baseUrl
|
||||
) {
|
||||
$this->request = Http::acceptJson()
|
||||
->asJson()
|
||||
->withToken($this->accessToken)
|
||||
->baseUrl("{$this->baseUrl}/companies/{$this->companyId}");
|
||||
}
|
||||
|
||||
public function get(string $endpoint, array $query = []): object
|
||||
{
|
||||
return $this->request
|
||||
->get($endpoint, $query)
|
||||
->throw()
|
||||
->object();
|
||||
}
|
||||
|
||||
public function post(string $endpoint, array $data = []): object
|
||||
{
|
||||
return $this->request
|
||||
->post($endpoint, $data)
|
||||
->throw()
|
||||
->object();
|
||||
}
|
||||
|
||||
public function put(string $endpoint, array $data = []): object
|
||||
{
|
||||
return $this->request
|
||||
->put($endpoint, $data)
|
||||
->throw()
|
||||
->object();
|
||||
}
|
||||
|
||||
public function delete(string $endpoint): bool
|
||||
{
|
||||
return $this->request
|
||||
->delete($endpoint)
|
||||
->throw()
|
||||
->ok();
|
||||
}
|
||||
|
||||
public function contents(string $endpoint, array $query = []): string
|
||||
{
|
||||
return $this->request
|
||||
->get($endpoint, $query)
|
||||
->throw()
|
||||
->body();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Mattitja\BokioApiLaravel;
|
||||
|
||||
use Spatie\LaravelPackageTools\Package;
|
||||
use Spatie\LaravelPackageTools\PackageServiceProvider;
|
||||
|
||||
class BokioServiceProvider extends PackageServiceProvider
|
||||
{
|
||||
public function configurePackage(Package $package): void
|
||||
{
|
||||
$package
|
||||
->name('bokio-api-laravel')
|
||||
->hasConfigFile();
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
parent::register();
|
||||
|
||||
$this->app->singleton(BokioClient::class, function () {
|
||||
return new BokioClient(
|
||||
config('bokio.token'),
|
||||
config('bokio.company_id'),
|
||||
config('bokio.base_url', 'https://api.bokio.se'),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@ namespace Mattitja\BokioApiLaravel\Facades;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* @see \Mattitja\BokioApiLaravel\BokioApiLaravel
|
||||
* @see \Mattitja\BokioApiLaravel\Bokio
|
||||
*/
|
||||
class BokioApiLaravel extends Facade
|
||||
class Bokio extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor(): string
|
||||
{
|
||||
return \Mattitja\BokioApiLaravel\BokioApiLaravel::class;
|
||||
return \Mattitja\BokioApiLaravel\Bokio::class;
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -3,7 +3,7 @@
|
||||
namespace Mattitja\BokioApiLaravel\Tests;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Mattitja\BokioApiLaravel\BokioApiLaravelServiceProvider;
|
||||
use Mattitja\BokioApiLaravel\BokioServiceProvider;
|
||||
use Orchestra\Testbench\TestCase as Orchestra;
|
||||
|
||||
class TestCase extends Orchestra
|
||||
@@ -13,14 +13,14 @@ class TestCase extends Orchestra
|
||||
parent::setUp();
|
||||
|
||||
Factory::guessFactoryNamesUsing(
|
||||
fn (string $modelName) => 'Mattitja\\BokioApiLaravel\\Database\\Factories\\'.class_basename($modelName).'Factory'
|
||||
fn (string $modelName) => 'Mattitja\\Bokio\\Database\\Factories\\'.class_basename($modelName).'Factory'
|
||||
);
|
||||
}
|
||||
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [
|
||||
BokioApiLaravelServiceProvider::class,
|
||||
BokioServiceProvider::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user