Last active
August 29, 2015 14:10
-
-
Save matti/d93c3e6735da1e70ffe2 to your computer and use it in GitHub Desktop.
beddit api starter
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 "httparty" | |
ENDPOINT = "https://cloudapi.beddit.com" | |
login_options = { | |
"grant_type" => "password", | |
"username" => "TODO", | |
"password" => "TODO" | |
} | |
login_response = HTTParty.post "#{ENDPOINT}/api/v1/auth/authorize", { | |
body: login_options | |
} | |
user_token = login_response.parsed_response["access_token"] | |
puts "UserToken: #{user_token}" | |
access_token_info_response = HTTParty.get "#{ENDPOINT}/api/v1/auth/token_info", { | |
headers: { | |
"Authorization" => "UserToken #{user_token}" | |
} | |
} | |
user_id = access_token_info_response.parsed_response["user"] | |
puts "User id: #{access_token_info_response.parsed_response["user"]}" | |
user_info_response = HTTParty.get "#{ENDPOINT}/api/v1/user/#{user_id}", { | |
headers: { | |
"Authorization" => "UserToken #{user_token}" | |
} | |
} | |
puts "User sex: #{user_info_response.parsed_response["sex"]}" | |
sleep_response = HTTParty.get "#{ENDPOINT}/api/v1/user/#{user_id}/sleep", { | |
headers: { | |
"Authorization" => "UserToken #{user_token}" | |
} | |
} | |
for sleep in sleep_response.parsed_response do | |
puts "#{sleep["date"]}: #{sleep["time_value_tracks"]["snoring_episodes"]["items"].count} snores" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment