Class: Ambient::Client
- Inherits:
-
Object
- Object
- Ambient::Client
- Defined in:
- lib/ambient/client.rb
Instance Method Summary collapse
- #device_data(device_mac_address, end_date: nil, limit: 288) ⇒ Object
- #devices ⇒ Object
-
#initialize(client_config) ⇒ Client
constructor
Creates a new Ambient Client.
Constructor Details
#initialize(client_config) ⇒ Client
Creates a new Ambient Client
17 18 19 |
# File 'lib/ambient/client.rb', line 17 def initialize(client_config) @config = client_config end |
Instance Method Details
#device_data(device_mac_address, end_date: nil, limit: 288) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ambient/client.rb', line 43 def device_data(device_mac_address, end_date: nil, limit: 288) path = "devices/#{device_mac_address}" params = {endDate: end_date, limit: } begin response = _get(path, @config, params: ) rescue StandardError => se raise Ambient::ClientError, "Error while getting device data from the Ambient API #{se.class.name}: #{se.}" end unless response.is_a? Net::HTTPOK raise Ambient::ClientError, "The response from the Ambient API was not what was expected, got #{response.class.name} instead of Net::HTTPOK" end JSON.parse(response.body) end |
#devices ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ambient/client.rb', line 21 def devices path = "devices" begin response = _get(path, @config) rescue StandardError => se raise Ambient::ClientError, "Error while getting the list of devices from the Ambient API (#{se.class.name}): #{se.}" end unless response.is_a? Net::HTTPOK raise Ambient::ClientError, "The response from the Ambient API was not what was expected, got #{response.class.name} instead of Net::HTTPOK" end response_data = JSON.parse(response.body) array_of_devices = [] response_data.each do |device_data| array_of_devices << Ambient::Device.from_hash(device_data) end array_of_devices end |