deboorn/xively-api

PHP API Client for Xively Api

v1.1.2 2015-10-18 16:29 UTC

This package is not auto-updated.

Last update: 2024-10-26 19:05:19 UTC


README

Xively-Api

  • PHP 5 Chainable API Implementation of Xively Api
  • License: Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)
  • These files are Not officially supported by Xively (LogMeIn).
  • Questions regarding this software should be directed to daniel.boorn@gmail.com.

How to Install

Install the deboorn/xively-api package

$ composer require deboorn/xively-api

Example of Usage

$xi = new \Xively\Api('your api key');

// view api resource triggers
var_dump($xi->paths);

// example - json get feeds
$r = $xi->feeds()->list()->get();
var_dump($r);

// example - xml get feeds
$xml = $xi->xml()->feeds()->list()->get();
var_dump($xml);

// example - csv get feeds
$csv = $xi->csv()->feeds()->list()->get();
var_dump($csv);

// example - with custom exception
try {
    $r = $xi->feeds()->list()->get();
} catch (\Xively\Exception $e) {
    die($e->getMessage());
}

// example - get feeds by criteria
$r = $xi->feeds()->read(array(
    'per_page' => 10,
    'page'     => 5,
    'tag'      => 'temperature',
))->get();
var_dump($r);

// example - same as above with iteration
$r = $xi->feeds()->read(array('per_page' => 10, 'page' => 5, 'tag' => 'temperature',))->get();
echo "<pre>Total Results: {$r->totalResults}\n\n";
foreach ($r->results as $row) {
    print_r($row);
}

// example - feed used in examples below

$r = $xi->feeds()->read(array('per_page' => 1))->get();
$feed = current($r->results);

// example - grab feed data by range
$r = $xi->feeds($feed->id)->range(array(
    'start'     => date('c', strtotime('-10 days')),
    'end'       => date('c', strtotime('-1 hour')),
    'time_unit' => 'hours',
))->get();
var_dump($r);

// example - grab feed's 1st data stream
$datastream = current($feed->datastreams);

// example - pull data from stream by range
$r = $xi->feeds($feed->id)->datastreams($datastream->id)->range(array(
    'start'     => date('c', strtotime('-10 days')),
    'end'       => date('c', strtotime('-1 hour')),
    'time_unit' => 'hours',
))->get();
var_dump($r);

// example - push data to stream
$r = $xi->feeds()->read(array(
    'user' => 'deboorn',
))->get();

//feeds(id)->datastreams(id)->update(body)
$feed = $r->results[1];
$dataStream = $feed->datastreams[0];
$r = $xi->feeds($feed->id)->datastreams($dataStream->id)->update(array(
    'version'     => '1.0.0',
    'datastreams' => array(
        array(
            'id'         => $dataStream->id,
            'datapoints' => array(
                array('at' => date('c'), 'value' => rand(1, 10)),
            ),
        ),
    ),
))->get();


// ... create your own chain ... see paths in json file for complete triggers