Class: Sense::Client

Inherits:
Object
  • Object
show all
Includes:
Account, Alarms, Alerts, App, Devices, Expansions, Firmware, Insights, Notifications, Questions, Sensors, Session, Sharing, SleepSounds, Speech, Stats, Store, Support, Timeline, Trends
Defined in:
lib/hello_sense/client.rb

Constant Summary collapse

API_HOST =
'https://api.hello.is'.freeze

Constants included from Account

Account::EMAIL_PATTERN, Account::MIN_PASSWORD_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Trends

#trends

Methods included from Timeline

#create_timeline_event, #remove_timeline_event, #timeline, #update_timeline_event

Methods included from Support

#support_topics

Methods included from Store

#send_feedback

Methods included from Stats

#unread_stats, #update_stats

Methods included from Speech

#onboarding_speech

Methods included from SleepSounds

#play_sound, #sound_durations, #sounds, #sounds_combined_state, #sounds_status, #stop_sounds

Methods included from Sharing

#share_insight

Methods included from Session

#authorize_with_password!, #destroy_token

Methods included from Sensors

#sensors, #sensors_historical, #update_sensors

Methods included from Questions

#questions, #skip_question, #update_questions

Methods included from Notifications

#create_notification, #notifications, #update_notifications

Methods included from Insights

#insight, #insights

Methods included from Firmware

#firmware_update_status, #request_firmware_update

Methods included from Expansions

#expansion, #expansion_configurations, #expansions, #update_expansion, #update_expansion_configurations

Methods included from Devices

#devices, #devices_info, #remove_device, #remove_pill, #remove_sense, #swap_device, #update_voice, #voice

Methods included from App

#check_for_update

Methods included from Alerts

#alerts

Methods included from Alarms

#alarm_sounds, #alarms, #update_alarm

Methods included from Account

#account, #create_account, #current_timezone, #delete_profile_picture, #preferences, #update_account, #update_email, #update_password, #update_photo, #update_preferences, #update_timezone

Constructor Details

#initialize(options = {}) ⇒ Client

XXX

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :access_token (String)
  • :client_id (String)
  • :client_secret (String)
  • :password (String)
  • :username (String)


41
42
43
44
45
46
47
48
49
50
# File 'lib/hello_sense/client.rb', line 41

def initialize(options = {})
  @access_token = options[:access_token]
  @client_id = options[:client_id]
  @client_secret = options[:client_secret]
  @password = options[:password]
  @username = options[:username]

  @access_token = authorize_with_password! if @access_token.nil?
  puts "** Using #{@access_token} as Sense access token"
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



31
32
33
# File 'lib/hello_sense/client.rb', line 31

def access_token
  @access_token
end

Instance Method Details

#delete(path) ⇒ Object

XXX

Parameters:

  • path (String)

    relative path to use for the request



55
56
57
58
# File 'lib/hello_sense/client.rb', line 55

def delete(path)
  response = connection.delete(path, headers)
  data_or_error(response)
end

#get(path) ⇒ Object

XXX

Parameters:

  • path (String)

    relative path to use for the request



63
64
65
66
# File 'lib/hello_sense/client.rb', line 63

def get(path)
  response = connection.get(path, headers)
  data_or_error(response)
end

#patch(path, data) ⇒ Object

XXX

Parameters:

  • path (String)

    relative path to use for the request

  • data (Hash)

    data to send



72
73
74
75
76
# File 'lib/hello_sense/client.rb', line 72

def patch(path, data)
  # XXX may need +set_form_data+
  response = connection.patch(path, data, headers)
  data_or_error(response)
end

#post(path, data) ⇒ Object

XXX

Parameters:

  • path (String)

    relative path to use for the request

  • data (Hash)

    data to send



82
83
84
85
86
87
# File 'lib/hello_sense/client.rb', line 82

def post(path, data)
  request = Net::HTTP::Post.new(path, headers)
  request.set_form_data(data)
  response = connection.request(request)
  data_or_error(response)
end

#put(path, data) ⇒ Object

Parameters:

  • path (String)

    relative path to use for the request

  • data (Hash)

    data to send



91
92
93
94
95
96
# File 'lib/hello_sense/client.rb', line 91

def put(path, data)
  request = Net::HTTP::Put.new(path, headers)
  request.set_form_data(data)
  response = connection.request(request)
  data_or_error(response)
end