Sha256: 92be4fb8ccea4f4fd31898982a4eb7ad1141e53111e0696dea9a202f111b4bd4

Contents?: true

Size: 913 Bytes

Versions: 4

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

require 'oura/utils/api'

module Oura
  module Apis
    # SleepPeriod is a nearly continuous, longish period of time spent lying down in bed.
    module SleepPeriod
      include ::Oura::Utils::Api

      REQUEST_PATH = '/v1/sleep'

      # @param [Date] start_date
      # @param [Date] end_date
      # @example response body
      # {
      #   "sleep": [{"summary_date": "2016-10-11", ...}, {"summary_date": "2016-10-12", ...}, ...]
      # }
      # @return [Oura::Model::SleepPeriod]
      def sleep_period(start_date:, end_date: Time.current.to_date)
        sdate, edate = [start_date, end_date].map { |date| transform_date(date) }
        response_body = get(REQUEST_PATH, params: { start: sdate, end: edate }).body
        symbolized_json = JSON.parse(response_body).deep_symbolize_keys

        ::Oura::Model::SleepPeriod.new(symbolized_json)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
oura-0.1.8 lib/oura/apis/sleep_period.rb
oura-0.1.7 lib/oura/apis/sleep_period.rb
oura-0.1.6 lib/oura/apis/sleep_period.rb
oura-0.1.5 lib/oura/apis/sleep_period.rb