Module: FitbitClient::Resources::Subscription
- Included in:
- FitbitClient::Resources
- Defined in:
- lib/fitbit_client/resources/subscription.rb
Overview
The Fitbit’s Subscriptions API allows third-party applications to be notified when Fitbit user data changes.
This allows apps to have a user’s latest data without having to implement a polling or scheduling system to retrieve user’s data.
Instance Method Summary collapse
-
#add_subscription(activity_type, subscription_id) ⇒ Object
You must add a subscription in your application so that users will get notifications and return a response in the format requested.
-
#delete_subscription(activity_type, subscription_id) ⇒ Object
Deletes a subscription for a user.
-
#list_of_subscriptions(activity_type) ⇒ Object
Get a list of a user’s subscriptions for your application in the format requested.
Instance Method Details
#add_subscription(activity_type, subscription_id) ⇒ Object
You must add a subscription in your application so that users will get notifications and return a response in the format requested.
The activity_type must be one of activities, body, foods, sleep if nil value is passed the activity, nutrition, profile, settings, sleep, weight scopes are required.
The subscription_id value provides a way to associate an update with a particular user stream in your application, you must generate this value.
21 22 23 |
# File 'lib/fitbit_client/resources/subscription.rb', line 21 def add_subscription(activity_type, subscription_id) post_json(path_user_version("#{subscription_path(activity_type)}/#{subscription_id}")) end |
#delete_subscription(activity_type, subscription_id) ⇒ Object
Deletes a subscription for a user. A successful request will return a 204 status code and empty response body.
returns true when succesfully deleted
29 30 31 32 |
# File 'lib/fitbit_client/resources/subscription.rb', line 29 def delete_subscription(activity_type, subscription_id) path = path_user_version("#{subscription_path(activity_type)}/#{subscription_id}") successful_delete?(delete(path)) end |
#list_of_subscriptions(activity_type) ⇒ Object
Get a list of a user’s subscriptions for your application in the format requested.
You can either fetch subscriptions for a specific collection or the entire list of subscriptions for the user.
For best practice, make sure that your application maintains this list on your side and use this endpoint only to periodically ensure data consistency.
43 44 45 |
# File 'lib/fitbit_client/resources/subscription.rb', line 43 def list_of_subscriptions(activity_type) get_json(path_user_version(subscription_path(activity_type))) end |