PHP GSM API
A simple PHP5 Object Oriented wrapper for GlobalSportsMedia (GSM) XML API., (*1)
See http://client.globalsportsmedia.com/documentation, (*2)
Features
- Follows PSR-0 conventions and coding standard: autoload friendly
- API entry points implementation state :
- OK soccer
- OK am_football
- OK aus_football
- OK baseball
- OK basketball
- OK cricket
- OK golf
- OK handball
- OK hockey
- OK motorsports
- OK rugby
- OK tennis
- OK volleyball
Requirements
- PHP >= 5.4 with cURL extension,
Install
Through composer, simply run :, (*3)
$ php composer.phar require kbsali/gsm-api:1.*
Basic usage of php-gsm-api client
All the methods return a SimpleXmlElement object or throw an Exception in case of error.
Following the basic workflow documented in globalsportsmedia.com for working with Soccer data :, (*4)
<?php
// This file is generated by Composer
require_once 'vendor/autoload.php';
$client = new GlobalSportsMedia\Client('http://webpull.globalsportsmedia.com', 'USERNAME', 'PASSWORD');
$client
->cacheOn() // for live method (like get_matches_live_updates) you might want to disable caching
->setCacheDir(__DIR__.'/cache') // path where xml responess will be cached
;
try {
$seasons = $client->api('soccer')->get_seasons(['authorized' => 'yes']);
foreach ($seasons->competition as $competition) {
foreach ($competition->season as $season) {
$matches = $client->api('soccer')
->cacheOncePerDay() // cache, but only once a day!
->get_matches(
(int) $season['season_id'],
'season',
['detailed' => 'yes', 'start_date' => date('Y-m-d H:00:00')]
)
;
// process matches...
}
}
} catch(\Exception $e) {
die($e->getMessage());
}
You can control if you want to cache the requests to the API (get_seasons() is not likely to change everyday):, (*5)
-
cacheOff() to never cache the request
-
cacheOn() to cache the request undefinitely (ie. until to clean the cache)
-
cacheOncePerDay() to cache requests for the current day
If you wish to cache the requests you will have to specifiy the cache directory through setCacheDir(), (*6)