humure-client 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 165b1114b4113b0bf1084b547b6b191403ee1b3a
4
- data.tar.gz: 0a40111fbba37bbef09fac29b3a2663507d4fd57
3
+ metadata.gz: 3f53494bebc1398f8675d50642e9520e87998625
4
+ data.tar.gz: 50b72fcd3fa75a1bb68d4a4aabadee4a22a7123a
5
5
  SHA512:
6
- metadata.gz: 9d7f500a8f8125d183a784099da38cf19eb04f01fe6f1226aacf8040073648bf17b29407310b87583c7ae70154719bb8165d3d88dec1cfd4b2afd8c68835795a
7
- data.tar.gz: b4b92061642fbb25683331b52c7827da3966fd6dc16e7c16e3ee7a1dbc8b417e6431f075b27c88e957cc0b605985397d37eceb7630776fdccb92460d768793ed
6
+ metadata.gz: 2ff792c836f14df38c7be41a52abb90846d72e47c5b028437b8c5a9182cf30afebc075b752979b651835f65ad94438888e8820adaaabbefd74eece2176b64475
7
+ data.tar.gz: 6123161312f48af3aa6f4850c54870d20c8f445b606cebc918a8ef9a131a5124041a087f38081dc62c7542f29ed4981f7e97909bc79499d5452fcf914147b2dd
data/README.md CHANGED
@@ -28,6 +28,15 @@ thing.humidity
28
28
 
29
29
  thing.lamp
30
30
  # => "on"
31
+
32
+ thing.switch_lamp_on
33
+ # => "on"
34
+
35
+ thing.switch_lamp_off
36
+ # => "off"
37
+
38
+ thing.change_lamp_color(240, 65, 36)
39
+ # => [240, 65, 36]
31
40
  ```
32
41
 
33
42
  ## Development
@@ -15,17 +15,34 @@ class HumureClient
15
15
  get_request("lamp")
16
16
  end
17
17
 
18
+ def switch_lamp_on
19
+ put_request("lamp/on")
20
+ end
21
+
22
+ def switch_lamp_off
23
+ put_request("lamp/off")
24
+ end
25
+
26
+ def change_lamp_color(red, green, blue)
27
+ put_request("lamp/color/#{red}/#{green}/#{blue}")
28
+ end
29
+
18
30
  protected
19
31
 
20
32
  def get_request(path)
21
33
  resp = Net::HTTP.get_response(uri(path))
34
+ process_response(resp)
35
+ rescue SocketError
36
+ nil
37
+ end
22
38
 
23
- if resp.code != '200'
24
- return nil
25
- end
39
+ def put_request(path)
40
+ http = Net::HTTP.new(uri(path).host, uri(path).port)
41
+ request = Net::HTTP::Put.new(uri(path).path)
42
+ request.set_form_data({})
26
43
 
27
- v = JSON.parse(resp.body)
28
- return v["value"]
44
+ resp = http.request(request)
45
+ process_response(resp)
29
46
  rescue SocketError
30
47
  nil
31
48
  end
@@ -34,4 +51,11 @@ class HumureClient
34
51
  URI(url + "/api/" + path)
35
52
  end
36
53
 
54
+ def process_response(resp)
55
+ return nil if resp.code != '200'
56
+
57
+ v = JSON.parse(resp.body)
58
+ v["value"]
59
+ end
60
+
37
61
  end
@@ -1,3 +1,3 @@
1
1
  class HumureClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humure-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Gogolok