-
Notifications
You must be signed in to change notification settings - Fork 6
Talking to the REST API
levent edited this page Mar 12, 2013
·
5 revisions
- Signup for free on cosm.com
- Create an api key on Cosm
The cosm-rb library makes it easy to convert Ruby objects into Cosm ones.
feed = Cosm::Feed.new # initialize a new Feed object
feed.title = "My Cosm Feed"
feed.datastreams = [Cosm::Datastream.new(:id => 'test')] # Let's give it one datastream with id 'test'
Let's create the feed on Cosm
client = Cosm::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 Cosm feed including the ID
=> "http://api.cosm.com/v2/feeds/SOMEID"
The datapoint creation endpoint takes an array of datapoints
datapoint = Cosm::Datapoint.new(:at => Time.now, :value => "25")
client.post('/v2/feeds/504/datastreams/temperature/datapoints', :body => {:datapoints => [datapoint]}.to_json)