Created
June 17, 2013 16:20
-
-
Save smulube/5798165 to your computer and use it in GitHub Desktop.
Upload data to Xively using Net::HTTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'json' | |
require 'time' | |
feed_id = YOUR_FEED_ID | |
api_key = "YOUR_API_KEY" | |
payload = { :version => "1.0.0", :datastreams => [ | |
{ :id => "Temperature", :at => Time.now.iso8601, :current_value => "17.2"} | |
]}.to_json | |
uri = URI.parse("https://api.xively.com/v2/feeds/#{feed_id}") | |
https = Net::HTTP.new(uri.host, uri.port) | |
https.use_ssl = true | |
https.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
request = Net::HTTP::Put.new(uri.request_uri) | |
request.body = payload | |
request.add_field("Content-Type", "application/json") | |
request.add_field("X-ApiKey", api_key) | |
# View debug output going over the wire | |
https.set_debug_output($stdout) | |
response = https.request(request) | |
puts response.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment