maxwkf / barsbank
Package Supporting Barsbank API
v1.01
2022-07-19 10:46 UTC
Requires
- guzzlehttp/guzzle: 7.4.5
Requires (Dev)
- orchestra/testbench: ^7.0
README
This barsbank API allows you to operate API of https://dynamic.barsbank.com/api-docs. (Make Booking not implemented yet)
Installation
Composer
You should have installed composer and install from the following command.
composer require maxwkf/barsbank
Running with laravel
Copy and add key to config file and add your API key to it.
Run the following command. It will copy a config file to your /config folder
> php artisan vendor:publish --provider="Maxwkf\Barsbank\BarsbankServiceProvider" --tag="config"
Update the key attribute in the config file.
return [ 'key' => 'your-own-key' ];
How to use
PHP without framework
$apiKey = "your-api-key"; $parkId = 2; // your park id $apiClient = new \Maxwkf\Barsbank\ApiClient(apiKey: $apiKey, parkId: $parkId); $apiClient ->setDateFrom('2022-12-01') ->setDateTo('2022-12-31') ->setNumberAdults(2) ->getAvailability() ;
Laravel
- Add the API key to your config file
- Create your own Lodge Class interface such that you can wire up other API Client later on.
// /app/Services/Lodge.php namespace App\Services; interface Lodge { public function getAvailabilities(); public function getValidStays(); public function getParkAccommodation(); public function getTourValidStays(); public function getExtras(); }
- Register Lodge class in AppServiceProvider.php and instantiate it with our API Client
app()->bind(Lodge::class, function () { $apiClient = (new \Maxwkf\Barsbank\ApiClient( apiKey: config('barsbank.key'), parkId: 2, )); return new BarsbankLodge($apiClient); });
- Create your own class to implement the Lodge Class and inject the ApiClient to this class
namespace App\Services; use Maxwkf\Barsbank\ApiClient; class BarsbankLodge implements Lodge { public function __construct(protected ApiClient $client) { } public function getAvailabilities() { $this->client ->setNumberAdults(1) ->setDateFrom('2022-09-26') ->setDateTo('2022-09-30') ; return $this->client->getAvailabilities(); } public function getValidStays() { // your own implementation } // implement for other functions }
- Create your own controller and use the LodgeController directly from the web.php
// /routes/web.php Route::get('/testBarsbankApi', LodgeController::class);
// /app/Http/Controllers/LodgeController.php namespace App\Http\Controllers; use App\Services\Lodge; use Illuminate\Http\Request; class LodgeController extends Controller { public function __invoke(Lodge $lodge) {// validate // $result = $lodge->getAvailabilities(); dd($lodge->getAvailabilities()); } }