requestlab/estat

Estat server-to-server interactions with Estat REST API v2

0.2 2016-02-24 13:29 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:12:53 UTC


README

Build Status

The RequestLab Estat library provides a way to use the Mediametrie Estat API. It's inspired by the Wid'op Google Analytics library

Documentation

Installation

To install the RequestLab Estat library, you will need Composer. It's a PHP 5.3+ dependency manager which allows you to declare the dependent libraries your project needs and it will install & autoload them for you.

Set up Composer

Composer comes with a simple phar file. To easily access it from anywhere on your system, you can execute:

$ curl -s https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

Define dependencies

Create a composer.json file at the root directory of your project and simply require the requestlab/estat package:

{
    "require": {
        "requestlab/estat": "*"
    }
}

Install dependencies

Now, you have define your dependencies, you can install them:

$ composer install

Composer will automatically download your dependencies & create an autoload file in the vendor directory.

Autoload

So easy, you just have to require the generated autoload file and you are already ready to play:

<?php

require __DIR__.'/vendor/autoload.php';

use RequestLab\Estat;

// ...
?>

The RequestLab Estat library follows the PSR-0 Standard. If you prefer install it manually, it can be autoload by any convenient autoloader.

Usage

Query

First, in order to request the Estat Query service, simply create a request and configure it according to your needs:

<?php

use RequestLab\Estat\Query;

$query = new Query();

$query->setStartDate(new \DateTime('-1 Day'));
$query->setEndDate(new \DateTime('-1 Day'));

$query->setSerial(254054201858);
$query->setIndicator('WEB_4NIVEAUX_NIVEAU4');

?>

Client

A client allows you to request the service with your login and password.

<?php

use RequestLab\Estat\Client;

$client = new Client();
$client->setLogin('Login');
$client->setPassword('Password');

?>

Service

<?php

use RequestLab\Estat\Service;

$service = new Service($client);
$client->query($query);

?>

Response

The response is a RequestLab\Estat\Response object which wraps all available informations:

<?php

$data    = $response->getData();
$totals  = $response->getTotals();

?>

Testing

The library is fully unit tested by PHPUnit. To execute the test suite, check the travis configuration.

Contribute

The library is open source, propose a PR!

License

The RequestLab Estat library is under the MIT license. For the full copyright and license information, please read the LICENSE file that was distributed with this source code.