Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Talking to the rest api

Basel Farah edited this page May 14, 2013 · 2 revisions

Xively::Client

Make sure you have a Xively account

  1. Signup for free on xively.com
  2. Create an api key on Xively

Create a Feed

The xively-rb library makes it easy to convert Ruby objects into Xively ones.

feed = Xively::Feed.new # initialize a new Feed object
feed.title = "My Xively Feed"
feed.datastreams = [Xively::Datastream.new(:id => 'test')] # Let's give it one datastream with id 'test'

Let's create the feed on Xively

client = Xively::Client.new(YOUR_API_KEY)
response = client.post('/v2/feeds.json', :body => feed.to_json)
puts response.headers['location'] # Will give us the location of the Xively feed including the ID
=> "http://api.xively.com/v2/feeds/SOMEID"

Create a Datapoint

The datapoint creation endpoint takes an array of datapoints

datapoint = Xively::Datapoint.new(:at => Time.now, :value => "25")
client.post('/v2/feeds/504/datastreams/temperature/datapoints', :body => {:datapoints => [datapoint]}.to_json)