Class: Activite::Client
- Inherits:
-
Object
- Object
- Activite::Client
- Includes:
- HTTP::OAuthClient
- Defined in:
- lib/activite/client.rb
Constant Summary
Constants included from HTTP::OAuthClient
HTTP::OAuthClient::DEFAULT_OPTIONS
Instance Attribute Summary collapse
-
#user_agent ⇒ String
Return the User-Agent string.
Attributes included from HTTP::OAuthClient
#consumer_key, #consumer_secret, #secret, #token
Instance Method Summary collapse
-
#activities(user_id, options = {}) ⇒ Array<Activite::Activity>
Get a list of activity measures for the specified user.
-
#body_measurements(user_id, options = {}) ⇒ Array<Activite::MeasurementGroup>
Get a list of body measurements taken by Withings devices.
-
#create_notification(user_id, options = {}) ⇒ Activite::Response
Register a webhook / notification with the Withings API.
-
#get_notification(user_id, options = {}) ⇒ Activite::Notification
Get information about a specific webhook / notification.
-
#initialize(options = {}) {|_self| ... } ⇒ Activite::Client
constructor
Initializes a new Client object used to communicate with the Withings API.
-
#list_notifications(user_id, options = {}) ⇒ Array<Activite::Notification>
Return a list of registered webhooks / notifications.
-
#revoke_notification(user_id, options = {}) ⇒ Activite::Response
Revoke previously subscribed webhook / notification.
-
#sleep_series(user_id, options = {}) ⇒ Array<Activite::Sleep>
Get details about a user’s sleep.
-
#sleep_summary(user_id, options = {}) ⇒ Array<Activite::SleepSummary>
Get a summary of a user’s night.
Methods included from HTTP::OAuthClient
#access_token, #authorize_url, #connected?, #existing_access_token, #request_token
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Activite::Client
Initializes a new Client object used to communicate with the Withings API.
An authenticated Client can be created with an access token and access token secret if the user has previously authorized access to their Withings account and you’ve stored their access credentials. An unauthenticated Client can be created that will allow you to initiate the OAuth authorization flow, directing the user to Withings to authorize access to their account.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/activite/client.rb', line 50 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? unless @token.nil? || @secret.nil? @access_token = existing_access_token(@token, @secret) end end |
Instance Attribute Details
Instance Method Details
#activities(user_id, options = {}) ⇒ Array<Activite::Activity>
Get a list of activity measures for the specified user
75 76 77 78 79 80 |
# File 'lib/activite/client.rb', line 75 def activities(user_id, = {}) perform_request(:get, '/v2/measure', Activite::Activity, 'activities', { action: 'getactivity', userid: user_id }.merge()) end |
#body_measurements(user_id, options = {}) ⇒ Array<Activite::MeasurementGroup>
Get a list of body measurements taken by Withings devices
88 89 90 91 92 93 |
# File 'lib/activite/client.rb', line 88 def body_measurements(user_id, = {}) perform_request(:get, '/measure', Activite::MeasurementGroup, 'measuregrps', { action: 'getmeas', userid: user_id }.merge()) end |
#create_notification(user_id, options = {}) ⇒ Activite::Response
Register a webhook / notification with the Withings API. This allows you to be notified when new data is available for a user.
133 134 135 136 137 |
# File 'lib/activite/client.rb', line 133 def create_notification(user_id, = {}) perform_request(:post, '/notify', Activite::Response, nil, { action: 'subscribe' }.merge()) end |
#get_notification(user_id, options = {}) ⇒ Activite::Notification
Get information about a specific webhook / notification.
145 146 147 148 149 |
# File 'lib/activite/client.rb', line 145 def get_notification(user_id, = {}) perform_request(:get, '/notify', Activite::Notification, nil, { action: 'get' }.merge()) end |
#list_notifications(user_id, options = {}) ⇒ Array<Activite::Notification>
Return a list of registered webhooks / notifications.
157 158 159 160 161 |
# File 'lib/activite/client.rb', line 157 def list_notifications(user_id, = {}) perform_request(:get, '/notify', Activite::Notification, 'profiles', { action: 'list' }.merge()) end |
#revoke_notification(user_id, options = {}) ⇒ Activite::Response
Revoke previously subscribed webhook / notification.
169 170 171 172 173 |
# File 'lib/activite/client.rb', line 169 def revoke_notification(user_id, = {}) perform_request(:get, '/notify', Activite::Response, nil, { action: 'revoke' }.merge()) end |
#sleep_series(user_id, options = {}) ⇒ Array<Activite::Sleep>
Get details about a user’s sleep
101 102 103 104 105 106 |
# File 'lib/activite/client.rb', line 101 def sleep_series(user_id, = {}) perform_request(:get, '/v2/sleep', Activite::SleepSeries, 'series', { action: 'get', userid: user_id }.merge()) end |
#sleep_summary(user_id, options = {}) ⇒ Array<Activite::SleepSummary>
Get a summary of a user’s night. Includes the total time they slept, how long it took them to fall asleep, how long it took them to fall asleep, etc.
NOTE: user_id isn’t actually used in this API call (so I assume it is derived from the OAuth credentials) but I was uncomfortable introducing this inconsistency into this gem.
120 121 122 123 124 |
# File 'lib/activite/client.rb', line 120 def sleep_summary(user_id, = {}) perform_request(:get, '/v2/sleep', Activite::SleepSummary, 'series', { action: 'getsummary' }.merge()) end |