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 +4 -4
- data/README.md +9 -0
- data/lib/humure-client/api.rb +29 -5
- data/lib/humure-client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f53494bebc1398f8675d50642e9520e87998625
|
|
4
|
+
data.tar.gz: 50b72fcd3fa75a1bb68d4a4aabadee4a22a7123a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ff792c836f14df38c7be41a52abb90846d72e47c5b028437b8c5a9182cf30afebc075b752979b651835f65ad94438888e8820adaaabbefd74eece2176b64475
|
|
7
|
+
data.tar.gz: 6123161312f48af3aa6f4850c54870d20c8f445b606cebc918a8ef9a131a5124041a087f38081dc62c7542f29ed4981f7e97909bc79499d5452fcf914147b2dd
|
data/README.md
CHANGED
data/lib/humure-client/api.rb
CHANGED
|
@@ -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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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
|