Giter Club home page Giter Club logo

xively-php's Introduction

Xively PHP

  • 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.
  • Questions regarding this software should be directed to [email protected].

How to Install

Install the xively/xively-php package

$ composer require xively/xively-php

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' => 'username',
))->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

xively-php's People

Contributors

deboorn avatar frasermac avatar gberkowitzlmi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xively-php's Issues

Add Composer support

Hi.

Could you add composer to your project? It'll allow use your repo as dependency in projects, which use composer. Now composer one of most popular tool for dependency management in PHP.

Thanks.

Exception in api.php

Hi,
I tested this api and i have a problem with permissions.
I have included my Api Key in api.php, I have given all permissions in the server for all files... but doesn't work.
For example, when i try to do this in index.php:
$r = $xi->feeds()->list()->get();
var_dump($r);
die();

I have this error:
PHP Fatal error: Uncaught exception 'Xively\Exception' with message '{"title":"Forbidden","errors":"You do not have the necessary permissions to access this resource"}' in ...api.php:182

What permissions do you mean?
Thanks,
Regards!
José

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.