Created
July 28, 2012 20:37
-
-
Save pdarche/3194702 to your computer and use it in GitHub Desktop.
This is an example Sinatra code block that should get and print out the last day's worth of data from the Withings api. Unfortunately, the Time class returns Fixnums, which I'm having trouble incorporating into request string (I'm getting type errors).
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 'rest_client' | |
get '/withings' do | |
userid = 'id' | |
public_key = 'key' | |
now = Time.now.to_i | |
yestr = now - (24 * 60 * 60) | |
url = 'http://wbsapi.withings.net/measure?action=getmeas&userid=' + userid + '&publickey=' + public_key +'&startdate=' + yestr.to_s + '&enddate=' + now.to_s ' + &limit=1'; | |
data = RestClient.get(url) | |
data = JSON.parse(data.body) | |
data = data['body']['measuregrps'][0]['measures'][0]['value'] * 0.00220462 | |
puts data.round_to(2) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment