Skip to content

gkawka/geckoboard-dataset-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geckoboard DataSet API

Library provides client for Geckoboard DataSet API by REST requests

SensioLabsInsight Scrutinizer Code Quality Code Coverage

Branches

  • 0.1.x PHP 5.6 support and guzzle 5.*
  • 0.2.x PHP 7.1+ support and guzzle ^5.3.2

How to use

DataSet definition + data row

Create DataSet definition:

<?php

namespace Preview;

use Kwk\Geckoboard\Dataset\DatasetBuilder;
use Kwk\Geckoboard\Dataset\DataSetInterface;
use Kwk\Geckoboard\Dataset\Type\DateType;
use Kwk\Geckoboard\Dataset\Type\NumberType;

class TestDataset implements DataSetInterface
{
    /**
     * {@inheritDoc}
     */
    public function getName()
    {
        return 'test';
    }

    /**
     * {@inheritDoc}
     */
    public function getDefinition()
    {
        return (new DatasetBuilder())
            ->addField('date_field_id', new DateType('Date'))
            ->addField('number_field_id', new NumberType('Number'))
            ->build();
    }
}

Create implementation of DataRowInterface:

<?php

namespace Preview;

use Kwk\Geckoboard\Dataset\DataSetRowInterface;

class TestDatarow implements DataSetRowInterface
{
    /**
     * {@inheritDoc}
     */
    public function getData()
    {
        return [
            'date_field_id' => '2016-12-31',
            'number_field_id' => 1021,
        ];
    }
}

Client usage

Create client:

$httpClient = new \Guzzle\Http\Client('https://api.geckoboard.com');
$client = new \Kwk\Geckoboard\Dataset\Client($httpClient, 'YOUR_API_KEY');

Create DataSet at Geckoboard:

$client->create(new \Preview\TestDataset());

Append row:

With class:

<?php

namespace Preview\Dataset;

use Kwk\Geckoboard\Dataset\DataSetRowInterface;

class TestDatarow implements DataSetRowInterface
{
    /**
     * {@inheritDoc}
     */
    public function getData()
    {
        return [
            'param1' => 'val1',
            'param2' => 'val2',
        ];
    }
}

Appending is just one liner:

$client->append(new \Preview\TestDataset(), [new \Preview\TestDatarow()]);