mrgla55 / tabapi
An API Wrapper for the TAB Studio
Requires
- php: >=5.6
- guzzlehttp/guzzle: 6.*
This package is auto-updated.
Last update: 2024-12-29 06:07:47 UTC
README
TAB Studio REST API Client for Laravel 5
TAB REST API client for Laravel.
While this package is built for Laravel, it has been decoupled so that it can be extended into any framework or vanilla PHP application. Currently the only support is for Laravel 4, 5 and Lumen.
Installation
Tabapi can be installed through composer. Open your composer.json
file and add the following to the require
key:
"mrgla55/tabapi": "0.*"
Next run composer update
from the command line to install the package.
Laravel Installation
Add the service provider and alias to your config/app.php
file:
mrgla55\Tabapi\Providers\Laravel\TabapiServiceProvider::class 'Tabapi' => mrgla55\Tabapi\Providers\Laravel\Facades\Tabapi::class
For Laravel 4, add
mrgla55\Tabapi\Providers\Laravel4\TabapiServiceProvider
inapp/config/app.php
. Alias will remain the same.
Lumen Installation
class_alias('mrgla55\Tabapi\Providers\Laravel\Facades\Tabapi', 'Tabapi'); $app->register(mrgla55\Tabapi\Providers\Lumen\TabapiServiceProvider::class); $app->configure('Tabapi'); $app->withFacades();
Then you'll utilize the Lumen service provider by registering it in the bootstrap/app.php
file.
Configuration
You will need a configuration file to add your credentials. Publish a config file using the artisan
command:
php artisan vendor:publish
You can find the config file in: config/tabapi.php
For Lumen, you should copy the config file from
src/config/config.php
and add it to aTabapi.php
configuration file under a config directory in the root of your application.
For Laravel 4, run
php artisan config:publish mrgla55/Tabapi
. It will be found inapp/config/mrgla55/Tabapi/config.php
Getting Started
Setting up a TAB Studio Account
- Go to https://studio.tab.com.au/
- You will need to have a valid TAB account number
- Click register and complete the form. Registration approval normally takes 2-3 days.
- Log in to TAB Studio
- Click "Settings" from the top right menu
- Note your Client Id and Client Secret and put them into your .env file as TAB_CLIENT_ID and TAB_CLIENT_SECRET, or update your tabapi config file.
Setup
Creating routes
Test API flow
Route::get('/versions', function() { return Tabapi::versions(); });
API Requests
All resources are requested dynamically using method overloading.
First, determine which resources you have access to by calling:
Tabapi::resources();
Result:
Array ( [account:authenticate] => https://webapi.tab.com.au/v1/account-service/tab/authenticate [account:balance] => https://webapi.tab.com.au/v1/account-service/tab/accounts/{accountNumber}/balance ... )
Next, call resources by referring to the specified key. Replace the colon ':' with and underscore '_'. Embedded parameters in the base url are replaced with arguments. Any left over arguments are added to the query string.
For instance:
Tabapi::lookup_countries_allowed();
or
Tabapi::info_sports(['jurisdiction' => 'nsw']);
Custom Apex endpoints
For nested links or to call direct, you can use the custom() method for consuming them.
Tabapi::custom('/myEndpoint');
Additional options and parameters can be passed in like this:
Tabapi::custom('https://api.beta.tab.com.au/v1/tab-info-service/racing/dates/2018-11-06/meetings/R/Racing%20-%20Futures/races/Melbourne%20Cup%20(All%20In)', [ 'parameters' => ['jurisdiction' => 'VIC', 'fixedOdds' => 'true'] ]);
Read Creating REST APIs using Apex REST for more information.
For more information about Guzzle responses and event listeners, refer to their documentation.