PHP code example of talanoff / laravel-wubook

1. Go to this page and download the library: Download talanoff/laravel-wubook library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

talanoff / laravel-wubook example snippets


 'providers' => [
    // OTHER PROVIDERS
    'Talanoff\LaravelWubook\WuBookServiceProvider::class'
 ],
 

 'aliases' => [
    // OTHER ALIASES
    'WuBook' => Talanoff\LaravelWubook\Facades\WuBook::class
 ],
 

[
    'username' => 'your-user',              
    'password' => 'your-password',          
    'provider_key' => 'your-provider-key', 
    'lcode' => 'your-lcode',
]

Cache::get('wubook.token')     // ex. '9869117656.9552'

// An error occurred
return [
    'has_error' => true,
    'data' => 'A human readeable error message'
]

// Success
return [
    'has_error' => false,
    'data' => [ /* THE XML/RPC FUNCTION RESPONSE */ ]
]

acquire_token()             
// returns a string (ex. '9869117656.9552'), throws an exception otherwise

release_token($token)       
// returns a boolean if the token is successfully released, throws an exception otherwise

is_token_valid($token, $request_new = false)        
// - if the token is valid returns an integer representing the total operations made with the token
// - if `request_new` is set to `true` and the token is not valid the method `aquire_token()` is called
// - false otherwise

provider_info($token = null)
// returns an array with the provider infos

use Talanoff\LaravelWuBook\Facades\WuBook;
// you can alias this in config/app.php if you like

// Retrieve the token
$token = WuBook::auth()->acquire_token()        // (ex. '9869117656.9552')

WuBook::rooms()->fetch_rooms(1)                 // See http://tdocs.wubook.net/wired/rooms.html#fetching-existing-rooms
// this example is simple, and there are far more methods available
// The result will be an associative array with this structure

[
    0 => [
        id => 123,
        name => 'room',
        shortname => 'ro',
        occupancy => 2,
        men => 2,
        children => 0,
        subroom => 0,
        // ...
    ],
    1 => [
        // ...
    ],
]

use Talanoff\LaravelWuBook\WuBookManager;
use Illuminate\Support\Facades\App; // you probably have this aliased already

class RoomManager
{
    protected $wubook;

    public function __construct(WuBookManager $wubook)
    {
        $this->wubook = $wubook;
    }

    public function fetch_rooms($ancillary = 0)
    {
        $this->wubook->fetch_rooms($ancillary);
    }
}

App::make('RoomManager')->fetch_rooms(1);