Method: FitbitAPI::Client#activity_time_series

Defined in:
lib/fitbit_api/activities.rb

#activity_time_series(resource, opts = {}) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fitbit_api/activities.rb', line 86

def activity_time_series(resource, opts = {})
  start_date = opts[:start_date]
  end_date   = opts[:end_date] || Date.today
  period     = opts[:period]

  unless ACTIVITY_RESOURCES.include?(resource)
    raise FitbitAPI::InvalidArgumentError,
          "Invalid resource: \"#{resource}\". Please provide one of the following: #{ACTIVITY_RESOURCES}."
  end

  raise FitbitAPI::InvalidArgumentError, 'A start_date or period is required.' if [start_date, period].none?

  if period && !PERIODS.include?(period)
    raise FitbitAPI::InvalidArgumentError,
          "Invalid period: \"#{period}\". Please provide one of the following: #{PERIODS}."
  end

  path = if period
           "user/#{user_id}/activities/#{resource}/date/#{format_date(end_date)}/#{period}.json"
         else
           "user/#{user_id}/activities/#{resource}/date/#{format_date(start_date)}/#{format_date(end_date)}.json"
         end
  result = get(path)

  strip_root_key(result)
end