Class: Howami::Fitbit
- Inherits:
-
Object
- Object
- Howami::Fitbit
- Includes:
- Methadone::CLILogging
- Defined in:
- lib/howami/fitbit.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #fat_str ⇒ Object
-
#initialize ⇒ Fitbit
constructor
A new instance of Fitbit.
- #retrieve_values! ⇒ Object
- #sleep_str ⇒ Object
- #steps ⇒ Object
- #steps_str ⇒ Object
-
#weight_lbl_value_187_workaround ⇒ Object
this method breaks the fitgem gem in ruby 1.8.7, so we just work around it and dont offer any i18n support for default units in 1.8.7, just assume AMERICA FUCK YEAH.
- #weight_str ⇒ Object
Constructor Details
#initialize ⇒ Fitbit
Returns a new instance of Fitbit.
9 10 11 12 |
# File 'lib/howami/fitbit.rb', line 9 def initialize @client = Authentication.authenticated_client retrieve_values! end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/howami/fitbit.rb', line 7 def client @client end |
Instance Method Details
#fat_str ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/howami/fitbit.rb', line 37 def fat_str if @fats.last return "#{@fats.last['fat']} %" else return "* No body fat data recorded in past 7 days." end end |
#retrieve_values! ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/howami/fitbit.rb', line 14 def retrieve_values! @weights = @client.data_by_time_range('/body/log/weight', {:base_date => Date.today.to_s, :period => '1w'})['weight'] @fats = @client.data_by_time_range('/body/log/fat', {:base_date => Date.today.to_s, :period => '1w'})['fat'] @sleeps = @client.sleep_on_date('today') @activities = @client.activities_on_date('today') @weight_lbl = weight_lbl_value_187_workaround end |
#sleep_str ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/howami/fitbit.rb', line 45 def sleep_str return "no sleep data." if @sleeps['sleep'].count == 0 sleep_total_min = @sleeps['summary']['totalMinutesAsleep'].to_i sleep_hours = sleep_total_min / 60 sleep_remainder_min = sleep_total_min % 60 return "#{sleep_hours} hours, #{sleep_remainder_min} min." end |
#steps ⇒ Object
54 55 56 |
# File 'lib/howami/fitbit.rb', line 54 def steps @activities['summary']['steps'] end |
#steps_str ⇒ Object
58 59 60 |
# File 'lib/howami/fitbit.rb', line 58 def steps_str "#{self.steps} steps" end |
#weight_lbl_value_187_workaround ⇒ Object
this method breaks the fitgem gem in ruby 1.8.7, so we just work around it and dont offer any i18n support for default units in 1.8.7, just assume AMERICA FUCK YEAH
24 25 26 27 |
# File 'lib/howami/fitbit.rb', line 24 def weight_lbl_value_187_workaround return "pounds" if RUBY_VERSION =~ /^1\.8/ @client.label_for_measurement(:weight) end |
#weight_str ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/howami/fitbit.rb', line 29 def weight_str if @weights.last return "#{@weights.last['weight']} #{@weight_lbl}" else return "* No weight data recorded in past 7 days." end end |