Class: NatureRemo::Client

Inherits:
Object
  • Object
show all
Includes:
Endpoints
Defined in:
lib/nature_remo/client.rb

Overview

Client to send requests to Nature Remo cloud API

Constant Summary collapse

BASE_URL =
'https://api.nature.global/'
API_VERSION =
'1'

Instance Method Summary collapse

Methods included from Endpoints::Users

#update_user_me, #user_me

Methods included from Endpoints::Signals

#create_signal, #delete_signal, #send_signal, #signals, #update_signal, #update_signal_orders

Methods included from Endpoints::Devices

#delete_device, #devices, #update_device, #update_device_humidity_offset, #update_device_temperature_offset

Methods included from Endpoints::Appliances

#appliances, #create_appliance, #delete_appliance, #update_aircon_settings, #update_appliance, #update_appliance_orders, #update_light_state, #update_tv_state

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nature_remo/client.rb', line 13

def initialize(access_token)
  raise ArgumentError, 'argument access_token must not be nil' if access_token.nil?

  @client = Faraday.new(url: "#{BASE_URL}#{API_VERSION}/") do |conn|
    conn.request :json
    conn.response :json, content_type: /\bjson$/, parser_options: { symbolize_names: true }
    conn.adapter Faraday.default_adapter
    conn.use RaiseError
  end
  @client.headers['Authorization'] = "Bearer #{access_token}"
end