Home

Awesome

PHP GSM API

A simple PHP5 Object Oriented wrapper for GlobalSportsMedia (GSM) XML API.

See http://client.globalsportsmedia.com/documentation

Features

Requirements

Install

Through composer, simply run :

$ 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 :

<?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):

If you wish to cache the requests you will have to specifiy the cache directory through setCacheDir()