Module: Sense::Timeline

Included in:
Client
Defined in:
lib/hello_sense/timeline.rb

Instance Method Summary collapse

Instance Method Details

#create_timeline_event(date, type, timestamp, data) ⇒ Object



73
74
75
# File 'lib/hello_sense/timeline.rb', line 73

def create_timeline_event(date, type, timestamp, data)
  put("/v2/timeline/#{date}/events/#{type}/#{timestamp}", data)
end

#remove_timeline_event(date, type, timestamp) ⇒ Object



81
82
83
# File 'lib/hello_sense/timeline.rb', line 81

def remove_timeline_event(date, type, timestamp)
  delete("/v2/timeline/#{date}/events/#{type}/#{timestamp}")
end

#timeline(date) ⇒ Hash

Known event_types:

  • FELL_ASLEEP

  • GENERIC_MOTION

  • GENERIC_SOUND

  • GOT_IN_BED

  • GOT_OUT_OF_BED

  • IN_BED

  • WOKE_UP

Known sleep_states:

  • AWAKE

  • LIGHT

  • MEDIUM

  • SOUND

Known metrics names:

  • fell_asleep

  • sound_sleep

  • time_to_sleep

  • times_awake

  • total_sleep

  • woke_up

  • humidity

  • light

  • particulates

  • sound

  • temperature

Examples:

{
  "score" => 69,
  "score_condition" => "WARNING",
  "message" => "You were asleep for **9.0 hours**, and sleeping soundly for 6.5 hours.",
  "date" => "2017-01-01",
  "sleep_periods" => [
    "NIGHT"
  ],
  "events" => [{
    "timestamp" => 1483340220000,
    "timezone_offset" => -28800000,
    "duration_millis" => 60000,
    "message" => "You went to bed.",
    "sleep_depth" => 0,
    "sleep_state" => "AWAKE",
    "event_type" => "GOT_IN_BED",
    "sleep_period" => "NIGHT",
    "valid_actions" => [
      "ADJUST_TIME",
      "VERIFY",
      "INCORRECT"
    ]
  }],
  "metrics" => [{
    "name" => "total_sleep",
    "value" => 537,
    "unit" => "MINUTES",
    "condition" => "IDEAL"
  }],
  "locked_down" => false
}

Parameters:

  • date (String)

    a date in ‘yyyy-MM-dd’ format

Returns:

  • (Hash)


69
70
71
# File 'lib/hello_sense/timeline.rb', line 69

def timeline(date)
  get("/v2/timeline/#{date}")
end

#update_timeline_event(date, type, timestamp, data) ⇒ Object



77
78
79
# File 'lib/hello_sense/timeline.rb', line 77

def update_timeline_event(date, type, timestamp, data)
  patch("/v2/timeline/#{date}/events/#{type}/#{timestamp}", data)
end