tychovbh/laravel-bluebillywig

A BlueBillyWig bridge for Laravel 5

v1.3 2019-07-05 12:24 UTC

This package is auto-updated.

Last update: 2024-11-06 00:07:29 UTC


README

Latest Version on Packagist Software License Total Downloads

Laravel Blue Billywig is created by, and is maintained by Tycho, and is a Laravel/Lumen package to connect with Blue Billywig API. Feel free to check out the change log, releases, license, and contribution guidelines

Install

Laravel Blue Billywig requires PHP 7.1 or 7.2. This particular version supports Laravel 5.5 - 5.7 only and Lumen.

To get the latest version, simply require the project using Composer.

$ composer require tychovbh/laravel-bluebillywig

Once installed, if you are not using automatic package discovery, then you need to register the Tychovbh\Bluebillywig\BluebillywigServiceProvider service provider in your config/app.php.

In Lumen add de Service Provider in bootstrap/app.php:

$app->register(\Tychovbh\Bluebillywig\BluebillywigServiceProvider::class);

Configuration

Laravel Blue Billywig requires publication configuration.

To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish --tag=laravel-bluebillywig

This will create a config/bluebillywig.php file in your app that you can modify to set your configuration. Also, make sure you check for changes to the original config file in this package between releases.

In lumen you have to create the configuration file manually since vendor:publish is not available. Create the file config/bluebillywig.php and copy paste the example file.

There are two config options:

Default publication Name

This option ('default') is where you may specify which of the publications below you wish to use as your default publication for all work. Of course, you may use many connections at once using the $bluebillywig->publication('my_publication') method. The default value for this setting is 'public'.

Bluebillywig Publications

This option ('publications') is where each of the publications are setup for your application. Example configuration has been included, but you may add as many publications as you would like.

Usage

Bluebillywig

This is the class of most interest. This will send authenticated requests to Blue Billywig API. Go to their documentation for all available endpoints.

Real Examples

Instantiate Bluebillywig class:

use Tychovbh\Bluebillywig\Bluebillywig;

// Use class injection
Route::get('/bluebillywig', function(Bluebillywig $bluebillywig) {
    $response = $bluebillywig->retrieve('/sapi/publication')
    return response()->json($response)
});

// Or use Laravel helper app()
Route::get('/bluebillywig', function() {
    $bluebillywig = app('bluebillywig');
    $response = $bluebillywig->retrieve('/sapi/publication')
    return response()->json($response)
});

Available Bluebillywig methods:

// The examples below use the default publication. 
$response = $bluebillywig->retrieve('/sapi/mediaclip')
$response = $bluebillywig->retrieve('/sapi/mediaclip/' . $id)
$response = $bluebillywig->create('/sapi/mediaclip', $formData)
$response = $bluebillywig->update('/sapi/mediaclip/{id}', $id, $formData)
$response = $bluebillywig->delete('/sapi/mediaclip', $id)

// in this example we request data from my_publication. 
// my_publication key should be added to publications in the confiugration file. 
$response = $bluebillywig->publication('my_publication')->retrieve('/sapi/playlist')

// You can use other API endpoints like /json/mediaclip:
$response = $bluebillywig>retrieve('/json/mediaclip')

You can send parameters with some of the requests:

// Request with GET parameter 'limit=10'
$response = $bluebillywig->retrieve('/sapi/mediaclip', [
    'limit' => 10
])

// Create resource
$response = $bluebillywig->create('/sapi/mediaclip', [
    'title' => 'my fantastic new title',
])

// Update resource
$response = $bluebillywig->update('/sapi/mediaclip/{id}', $id, [
    'title' => 'my fantastic new title',
])

You will need to handle Exceptions from Bluebillywig yourself:

use Tychovbh\Bluebillywig\Exceptions\ConfigurationException;

try {
    $bluebillywig = app('bluebillywig');
    $bluebillywig->retrieve('/sapi/mediaclip')
} catch(\ConfigurationException $exception) {
    echo $exception->getMessage();
} catch(\GuzzleException $exception) {
    echo $exception->getMessage();
} catch(\Exception $exception) {
    echo $exception->getMessage();
}

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

For testing tests/feature/* copy tests/.env.example to tests/.env and fill in your Blue Billywig testing account credentials.

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email info@bespokeweb.nl instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.