Class: Tradfri::Client
- Inherits:
-
Struct
- Object
- Struct
- Tradfri::Client
- Defined in:
- lib/tradfri/client.rb
Constant Summary collapse
- METHOD_GET =
'get'
- METHOD_PUT =
'put'
Instance Attribute Summary collapse
-
#coap_client_path ⇒ Object
Returns the value of attribute coap_client_path.
Instance Method Summary collapse
- #connect_to(host, port, key) ⇒ Object
- #discover_gateways(keys) ⇒ Object
- #get(key, uri) ⇒ Object
- #put(key, uri, payload) ⇒ Object
Instance Attribute Details
#coap_client_path ⇒ Object
Returns the value of attribute coap_client_path
7 8 9 |
# File 'lib/tradfri/client.rb', line 7 def coap_client_path @coap_client_path end |
Instance Method Details
#connect_to(host, port, key) ⇒ Object
17 18 19 |
# File 'lib/tradfri/client.rb', line 17 def connect_to(host, port, key) Gateway.new(self, host, port, key) end |
#discover_gateways(keys) ⇒ Object
11 12 13 14 15 |
# File 'lib/tradfri/client.rb', line 11 def discover_gateways(keys) Service.discover.map do |service| connect_to service.host, service.port, keys[service.mac_address] end end |
#get(key, uri) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tradfri/client.rb', line 21 def get(key, uri) Tempfile.open do |file| args = '-k', key, '-m', METHOD_GET, '-o', file.path, uri.to_s Open3.capture3(coap_client_path, *args) file.read end end |
#put(key, uri, payload) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/tradfri/client.rb', line 35 def put(key, uri, payload) args = '-k', key, '-m', METHOD_PUT, '-e', payload, uri.to_s Open3.capture3(coap_client_path, *args) end |