2017 © Pedro Peláez
 

library php-watson-api-bridge

A simple PHP Wrapper around IBM Watson API

image

findbrok/php-watson-api-bridge

A simple PHP Wrapper around IBM Watson API

  • Tuesday, June 6, 2017
  • by percymamedy
  • Repository
  • 2 Watchers
  • 28 Stars
  • 6,669 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 12 Versions
  • 9 % Grown

The README.md

, (*1)

PHP IBM Watson API Bridge

Latest Stable Version Latest Unstable Version Build Status StyleCI License Total Downloads , (*2)

Introduction

PHP IBM Watson API Bridge, provides a simple and easy to use wrapper around the IBM Watson API. The library makes it easier for us to develop PHP apps that use the IBM Watson API., (*3)

License

PHP IBM Watson API Bridge is open-sourced software licensed under the MIT license, (*4)

Installation

$ composer require findbrok/php-watson-api-bridge

Usage

Before using the package checkout Watson API Explorer, to get a sense of what you can and cannot do with Watson, (*5)

require 'vendor/autoload.php'

use FindBrok\WatsonBridge\Bridge;

// Create a new bridge Object.
$bridge = new Bridge('username', 'password', 'baseUrl');

// Simple get request.
$queryParams = ['foo' => 'bar'];
$response = $bridge->get('uri', $queryParams);

// Simple post request.
$dataToPost = ['foo' => 'bar'];
$response = $bridge->post('uri', $dataToPost, 'json');

The Package uses Guzzle to perform requests, all your responses will be instances of GuzzleHttp\Psr7\Response, (*6)


Integration with Laravel 5

As of version 1.1.x, PHP Watson API bridge adds a new Service Provider which integrates easily with Laravel 5., (*7)

If you are using Laravel >= 5.5, you can skip service registration and aliases registration thanks to Laravel auto package discovery feature., (*8)

First add the ServiceProvider to your app.php file:, (*9)

'providers' => [
   ....
   FindBrok\WatsonBridge\WatsonBridgeServiceProvider::class,
]

You can also add the following aliases to you app.php file:, (*10)

'aliases' => [
    ...
    'Bridge'      => FindBrok\WatsonBridge\Facades\Bridge::class,
    'BridgeStack' => FindBrok\WatsonBridge\Facades\BridgeStack::class,
    'Carpenter'   => FindBrok\WatsonBridge\Facades\Carpenter::class,
]

Now publish the config file:, (*11)

$ php artisan vendor:publish --tag=watson-api-bridge

You will now have a config file watson-bridge.php in your config directory. You may define in this config file your credentials, auth method to use, Watson Services and so on., (*12)

Services

The Laravel Integration gives you 3 service classes that are bound to the IoC. - FindBrok\WatsonBridge\Bridge (The actual Bridge class for making requests to Watson) - FindBrok\WatsonBridge\Support\Carpenter (Which can construct Bridge instances using your credentials and service URL) - FindBrok\WatsonBridge\Support\BridgeStack (Essentially a store where you can keep all Bridges you constructed and retrieve them back.), (*13)

Bridge

Bridge class will help you make requests to Watson API using the get, post, put, patch methods:, (*14)

$response = $bridge->get('uri', $queryParams);

Carpenter

The Carpenter class can build any type of Bridge for you. Use the constructBridge method passing in the desired parameters like credentials name, service to use and auth method and so on and the Carpenter will., (*15)

$carpenter = app()->make(Carpenter::class);

$bridge = $carpenter->constructBridge('default', 'personality_insights');

Remember that your credentials names, services and auth methods are all defined in the watson-bridge.php config file., (*16)

BridgeStack

The BridgeStack is a great place to keep all your Bridges so that you can retrieve them anytime in your app. Use the mountBridge method to construct and keep any type of Bridge in the Stack., (*17)

$stack = app()->make(BridgeStack::class);

$stack->mountBridge('myPIBridge', 'default', 'personality_insights');
$stack->mountBridge('myTABridge', 'default', 'tradeoff_analytics');

// Now use the Bridges stored in the Stack.
$response = $stack->conjure('myPIBridge')->post('/v3/profile', $dataToPost);

The BridgeStack is essentially a Laravel Collection, thus you have access to all Collection methods., (*18)

Facades

If you are using Laravel version less than 5.4 you have access to 3 Facades for the 3 services Bridge, Carpenter and BridgeStack. Since Laravel 5.4 added automatic Facades you won't be needing those classes., (*19)

  • FindBrok\WatsonBridge\Facades\Bridge
  • FindBrok\WatsonBridge\Facades\BridgeStack
  • FindBrok\WatsonBridge\Facades\Carpenter

Remember that if you are resolving the Bridge directly from the IoC and not constructing it with the Carpenter class a default Bridge will be resolved for you using the default credentials and auth methods from your watson-bridge config., (*20)

Credits

Big Thanks to all developers who worked hard to create something amazing!, (*21)

Creator

Percy Mamedy, (*22)

Twitter: @PercyMamedy br/ GitHub: percymamedy, (*23)

The Versions

06/06 2017

1.1.x-dev

1.1.9999999.9999999-dev

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

06/06 2017

dev-master

9999999-dev

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

06/06 2017

v1.1.2

1.1.2.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

06/05 2017

v1.1.1

1.1.1.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

12/02 2017

v1.1.0

1.1.0.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

21/01 2017

1.0.x-dev

1.0.9999999.9999999-dev

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

21/01 2017

v1.0.06

1.0.06.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

02/09 2016

v1.0.05

1.0.05.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

12/07 2016

v1.0.04

1.0.04.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

06/06 2016

v1.0.03

1.0.03.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

03/06 2016

v1.0.02

1.0.02.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge

24/05 2016

v1.0.01

1.0.01.0

A simple PHP Wrapper around IBM Watson API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Percy Mamedy

api php ibm watson bridge