Class: HumureClient

Inherits:
Object
  • Object
show all
Defined in:
lib/humure-client.rb,
lib/humure-client/api.rb,
lib/humure-client/client.rb,
lib/humure-client/version.rb

Constant Summary collapse

VERSION =
"0.4.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HumureClient

Initialize a new humure client

Parameters:

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

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
# File 'lib/humure-client/client.rb', line 9

def initialize(options={})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end

  raise ArgumentError.new("Option :token missing") if token.nil?

  @url ||= "http://localhost:3000"
  @sensor ||= "fake"
end

Instance Attribute Details

#sensorObject

Returns the value of attribute sensor.



3
4
5
# File 'lib/humure-client/client.rb', line 3

def sensor
  @sensor
end

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/humure-client/client.rb', line 3

def token
  @token
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/humure-client/client.rb', line 3

def url
  @url
end

Instance Method Details

#change_lamp_color(red, green, blue) ⇒ Object



26
27
28
# File 'lib/humure-client/api.rb', line 26

def change_lamp_color(red, green, blue)
  put_request("lamp/color/#{red}/#{green}/#{blue}")
end

#humidityObject



6
7
8
# File 'lib/humure-client/api.rb', line 6

def humidity
  get_request("humidity")
end

#lampObject



14
15
16
# File 'lib/humure-client/api.rb', line 14

def lamp
  get_request("lamp")
end

#switch_lamp_offObject



22
23
24
# File 'lib/humure-client/api.rb', line 22

def switch_lamp_off
  put_request("lamp/off")
end

#switch_lamp_onObject



18
19
20
# File 'lib/humure-client/api.rb', line 18

def switch_lamp_on
  put_request("lamp/on")
end

#temperatureObject



10
11
12
# File 'lib/humure-client/api.rb', line 10

def temperature
  get_request("temperature")
end