Module: Renstar::APIClient

Includes:
Control, Query, Settings
Included in:
Thermostat
Defined in:
lib/renstar/api_client.rb,
lib/renstar/api_client/query.rb,
lib/renstar/api_client/control.rb,
lib/renstar/api_client/settings.rb,
lib/renstar/api_client/api_object.rb,
lib/renstar/api_client/api_objects/info.rb,
lib/renstar/api_client/api_objects/alert.rb,
lib/renstar/api_client/api_objects/sensor.rb,
lib/renstar/api_client/api_objects/runtime.rb

Overview

The actual client that handles getting, posting, and parsing API responses

Defined Under Namespace

Modules: Control, Query, Settings Classes: APIObject, Alert, Info, Runtime, Sensor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Settings

#settings

Methods included from Control

#control

Methods included from Query

#alerts, #info, #runtimes, #sensors

Class Method Details

.key_to_description(type, key) ⇒ Object



34
35
36
# File 'lib/renstar/api_client.rb', line 34

def self.key_to_description(type, key)
  @api_ref.dig(type, key, 'description') || key
end

.value_to_formatted(type, key, value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/renstar/api_client.rb', line 38

def self.value_to_formatted(type, key, value)
  case @api_ref.dig(type, key, 'values')
  when 'raw'
    value
  when 'epoch'
    Time.at(value)
  else
    @api_ref.dig(type, key, 'values', value.to_s) || value
  end
end

Instance Method Details

#get(endpoint) ⇒ Object



16
17
18
19
20
# File 'lib/renstar/api_client.rb', line 16

def get(endpoint)
  uri = URI(location + endpoint)
  response = Net::HTTP.get(uri)
  JSON.parse(response)
end

#post(endpoint, options = {}) ⇒ Object



22
23
24
25
26
# File 'lib/renstar/api_client.rb', line 22

def post(endpoint, options = {})
  uri = URI(location + endpoint)
  response = Net::HTTP.post_form(uri, options)
  JSON.parse(response.body)
end