Class: Miles::Endpoint

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/miles/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 80) ⇒ Endpoint

Returns a new instance of Endpoint.



10
11
12
13
14
15
# File 'lib/miles/endpoint.rb', line 10

def initialize(host, port=80)
	@host = host
	@port = port
	@base_uri = "#{host}#{port != 80 ? ':' + @port.to_s : ''}"
	self.class.base_uri @base_uri
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri.



8
9
10
# File 'lib/miles/endpoint.rb', line 8

def base_uri
  @base_uri
end

#hostObject (readonly)

Returns the value of attribute host.



8
9
10
# File 'lib/miles/endpoint.rb', line 8

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



8
9
10
# File 'lib/miles/endpoint.rb', line 8

def port
  @port
end

Instance Method Details

#dewpointObject



53
54
55
56
# File 'lib/miles/endpoint.rb', line 53

def dewpoint
	response = self.class.get("/sensor/climate/dewpoint")
	return JSON.parse(response.body)
end

#get_pin(pinnum) ⇒ Object



18
19
20
21
22
# File 'lib/miles/endpoint.rb', line 18

def get_pin(pinnum)
	response = self.class.get("/pin/#{pinnum}")
	pin = JSON.parse(response.body)
	return pin
end

#humidityObject



48
49
50
51
# File 'lib/miles/endpoint.rb', line 48

def humidity
	response = self.class.get("/sensor/climate/humidity")
	return JSON.parse(response.body)
end

#set_pin_high(pinnum) ⇒ Object



33
34
35
36
# File 'lib/miles/endpoint.rb', line 33

def set_pin_high(pinnum)
	response = self.class.post("/pin/#{pinnum}")
	return JSON.parse(response.body)
end

#set_pin_low(pinnum) ⇒ Object



38
39
40
41
# File 'lib/miles/endpoint.rb', line 38

def set_pin_low(pinnum)
	response = self.class.delete("/pin/#{pinnum}")
	return JSON.parse(response.body)
end

#set_pin_mode(pinnum, mode) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/miles/endpoint.rb', line 24

def set_pin_mode(pinnum, mode)
	if not mode == :input and not mode == :output
		raise Exception
	end

	response = self.class.get("/pin/#{pinnum}/mode/#{mode.to_s}")
	return JSON.parse(response.body)
end

#temperatureObject



43
44
45
46
# File 'lib/miles/endpoint.rb', line 43

def temperature
	response = self.class.get("/sensor/climate/temperature")
	return JSON.parse(response.body)
end