Class: NatureRemoApi::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Endpoints::Signal

#send_signal, #signals

Methods included from Endpoints::Appliance

#appliances

Methods included from Endpoints::Device

#devices, #update_device

Methods included from Endpoints::User

#update_user_me, #user_me

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(options = {})
  NatureRemoApi::Config::ATTRIBUTES.each do |key|
    send("#{key}=", options.fetch(key, NatureRemoApi.config.send(key)))
  end
  @access_token ||= NatureRemoApi.config.access_token
  @client = Faraday.new(url: endpoint) do |conn|
    conn.request :json
    conn.response :mashify
    conn.response :json, :content_type => /\bjson$/
    conn.adapter Faraday.default_adapter
  end
  @client.headers['Authorization'] = "Bearer #{access_token}"
end

Instance Attribute Details

#access_tokenObject

TODO: NatureRemoApi::Config::ATTRIBUTESを下記に設定できるようにする



11
12
13
# File 'lib/nature_remo_api/client.rb', line 11

def access_token
  @access_token
end

#clientObject

TODO: NatureRemoApi::Config::ATTRIBUTESを下記に設定できるようにする



11
12
13
# File 'lib/nature_remo_api/client.rb', line 11

def client
  @client
end

#default_max_retriesObject

TODO: NatureRemoApi::Config::ATTRIBUTESを下記に設定できるようにする



11
12
13
# File 'lib/nature_remo_api/client.rb', line 11

def default_max_retries
  @default_max_retries
end

#endpointObject

TODO: NatureRemoApi::Config::ATTRIBUTESを下記に設定できるようにする



11
12
13
# File 'lib/nature_remo_api/client.rb', line 11

def endpoint
  @endpoint
end

Class Method Details

.configObject



39
40
41
# File 'lib/nature_remo_api/client.rb', line 39

def config
  Config
end

.configureObject



35
36
37
# File 'lib/nature_remo_api/client.rb', line 35

def configure
  block_given? ? yield(Config) : Config
end