Sha256: fe729df76b5d43c1a2756a08c78c7d1228bb142d9101315243c79ddfc5441220

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module FitbitAPI
  class Client
    # Returns the cardio fitness score data for a given date or date range.
    # If both a date and a date range are given, the date range takes precedence.
    #
    #   cardio_score_summary(date: Date.parse('2021-04-16'))
    #   cardio_score_summary(start_date: Date.parse('2021-05-18'), end_date: Date.parse('2021-05-24'))
    #
    # @param params [Hash] The request parameters
    #
    # @option params :date [Date] The target date
    # @option params :start_date [Date] The start of the date range
    # @option params :end_date [Date] The end of the date range

    def cardio_score_summary(opts={})
      date       = opts[:date] || Date.today
      start_date = opts[:start_date]
      end_date   = opts[:end_date]

      if start_date && !end_date
        end_date = Date.today
      end

      unless date || start_date
        raise FitbitAPI::InvalidArgumentError, 'A date or start_date and end_date are required.'
      end

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

      # remove root key from response
      result.values[0]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fitbit_api-0.14.2 lib/fitbit_api/cardio_score.rb
fitbit_api-0.14.1 lib/fitbit_api/cardio_score.rb