Class: FitbitClient::Client
- Inherits:
-
Object
- Object
- FitbitClient::Client
- Includes:
- Resources
- Defined in:
- lib/fitbit_client/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#refresh_token_callback ⇒ Object
writeonly
Sets the attribute refresh_token_callback.
Instance Method Summary collapse
-
#initialize(access_token, refresh_token, options = {}) ⇒ Client
constructor
A new instance of Client.
-
#refresh_token! ⇒ Object
Force a refresh token.
-
#refresh_token_callback!(oauth2_token) ⇒ Object
When a new refresh token is received this method will be called with the OAuth2::AccessToken instance as argument.
Methods included from Resources::Subscription
#add_subscription, #delete_subscription, #list_of_subscriptions
Methods included from Resources::Sleep
#delete_sleep_log, #log_sleep, #sleep_goals, #sleep_logs_by_date, #sleep_logs_by_date_range, #sleep_logs_list, #sleep_time_series, #update_sleep_goals
Methods included from Resources::Devices
Methods included from Resources::BodyAndWeight
#body_fat_logs, #body_goals, #body_time_series, #delete_body_fat_log, #delete_weight_log, #log_body_fat, #log_weight, #update_body_fat_goal, #update_body_weight_goal, #weight_logs
Methods included from Resources::Activity
#activity_time_series, #activity_type, #add_favorite_activity, #browse_activity_types, #daily_activity_summary, #delete_favorite_activity, #favorite_activities, #lifetime_stats, #recent_activity_types
Methods included from Resources::Common
#path_user_version, #period_or_date_param, #skip_user_options!, #time_series_path
Methods included from Network::Request
#delete, #delete_json, #get, #get_json, #post, #post_json, #successful_delete?, #successful_post?
Methods included from Util
empty_str?, iso_date, iso_time, iso_time_with_seconds
Constructor Details
#initialize(access_token, refresh_token, options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 |
# File 'lib/fitbit_client/client.rb', line 12 def initialize(access_token, refresh_token, = {}) @access_token = access_token @refresh_token = refresh_token @client_id = .fetch(:client_id, FitbitClient.client_id) @client_secret = .fetch(:client_secret, FitbitClient.client_secret) raise ArgumentError, 'FitbitClient::Client cannot operate without a client_id and client_secret values' if empty_str?(@client_id) || empty_str?(@client_secret) end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
10 11 12 |
# File 'lib/fitbit_client/client.rb', line 10 def access_token @access_token end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
10 11 12 |
# File 'lib/fitbit_client/client.rb', line 10 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
10 11 12 |
# File 'lib/fitbit_client/client.rb', line 10 def client_secret @client_secret end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
10 11 12 |
# File 'lib/fitbit_client/client.rb', line 10 def refresh_token @refresh_token end |
#refresh_token_callback=(value) ⇒ Object (writeonly)
Sets the attribute refresh_token_callback
9 10 11 |
# File 'lib/fitbit_client/client.rb', line 9 def refresh_token_callback=(value) @refresh_token_callback = value end |
Instance Method Details
#refresh_token! ⇒ Object
Force a refresh token
21 22 23 |
# File 'lib/fitbit_client/client.rb', line 21 def refresh_token! oauth2_refresh_token! end |
#refresh_token_callback!(oauth2_token) ⇒ Object
When a new refresh token is received this method will be called with the OAuth2::AccessToken instance as argument
27 28 29 30 31 |
# File 'lib/fitbit_client/client.rb', line 27 def refresh_token_callback!(oauth2_token) @access_token = oauth2_token.token @refresh_token = oauth2_token.refresh_token @refresh_token_callback&.call(oauth2_token) end |