BritishGasHive 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/britishgashive.rb +113 -97
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d02517ee8080365dc6b6576019d7bd46985de016
|
4
|
+
data.tar.gz: 7aeb927e0e30dfc1b5879cbf780623a5104fb8bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd1a1ce188b7541a88e1e4664b4a081bace1a2a005c015c7bf5d6c58434ccf59492c051189aab49bcaad3bbd9fc22d265abaf8a60451ec2a3d20cda187723264
|
7
|
+
data.tar.gz: 6f75732d17cc94c7a6887e7a05794cd6fc9c0eb811496d6d5d7c7f9d84d73e099e98ff88cad6379e4455db8ff9098292d991657f8db05b2c5cb31fb9ea41efa1
|
data/lib/britishgashive.rb
CHANGED
@@ -1,97 +1,113 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'uri'
|
4
|
-
require 'net/http'
|
5
|
-
require 'json'
|
6
|
-
|
7
|
-
class BritishGasHive
|
8
|
-
|
9
|
-
@hub = nil
|
10
|
-
@cookie = nil
|
11
|
-
|
12
|
-
def initialize(username, password, caller, bg = false)
|
13
|
-
if bg == true
|
14
|
-
@uri = URI("https://api.bgchlivehome.co.uk/v5")
|
15
|
-
else
|
16
|
-
@uri = URI("https://api.alertme.com/v5")
|
17
|
-
end
|
18
|
-
@session = self.login(username, password, caller)
|
19
|
-
@username = username
|
20
|
-
@password = password
|
21
|
-
end
|
22
|
-
|
23
|
-
def login(username, password, caller)
|
24
|
-
http = Net::HTTP.new(@uri.host, @uri.port)
|
25
|
-
http.use_ssl = true
|
26
|
-
|
27
|
-
request = Net::HTTP::Post.new("#{@uri.path}/login")
|
28
|
-
request.set_form_data({"username" => username, "password" => password, "caller" => caller})
|
29
|
-
|
30
|
-
response = http.request(request)
|
31
|
-
all_cookies = response.get_fields('set-cookie')
|
32
|
-
cookies_array = Array.new
|
33
|
-
all_cookies.each { | cookie |
|
34
|
-
cookies_array.push(cookie.split('; ')[0])
|
35
|
-
}
|
36
|
-
@cookie = cookies_array.join('; ')
|
37
|
-
|
38
|
-
json = JSON.parse(response.body)
|
39
|
-
@hub = json["hubIds"].first
|
40
|
-
end
|
41
|
-
|
42
|
-
def getDevices
|
43
|
-
http = Net::HTTP.new(@uri.host, @uri.port)
|
44
|
-
http.use_ssl = true
|
45
|
-
|
46
|
-
header = {'Cookie' => @cookie}
|
47
|
-
|
48
|
-
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices", header)
|
49
|
-
res = http.request(req)
|
50
|
-
JSON.parse(res.body)
|
51
|
-
end
|
52
|
-
|
53
|
-
def getDeviceByType(type)
|
54
|
-
http = Net::HTTP.new(@uri.host, @uri.port)
|
55
|
-
http.use_ssl = true
|
56
|
-
|
57
|
-
header = {'Cookie' => @cookie}
|
58
|
-
|
59
|
-
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices/#{type}", header)
|
60
|
-
res = http.request(req)
|
61
|
-
JSON.parse(res.body)
|
62
|
-
end
|
63
|
-
|
64
|
-
def getTarget()
|
65
|
-
http = Net::HTTP.new(@uri.host, @uri.port)
|
66
|
-
http.use_ssl = true
|
67
|
-
|
68
|
-
header = {'Cookie' => @cookie}
|
69
|
-
|
70
|
-
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/climate/targetTemperature", header)
|
71
|
-
res = http.request(req)
|
72
|
-
JSON.parse(res.body)
|
73
|
-
end
|
74
|
-
|
75
|
-
def getClimate()
|
76
|
-
http = Net::HTTP.new(@uri.host, @uri.port)
|
77
|
-
http.use_ssl = true
|
78
|
-
|
79
|
-
header = {'Cookie' => @cookie}
|
80
|
-
|
81
|
-
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/climate", header)
|
82
|
-
res = http.request(req)
|
83
|
-
JSON.parse(res.body)
|
84
|
-
end
|
85
|
-
|
86
|
-
def getTemperature()
|
87
|
-
http = Net::HTTP.new(@uri.host, @uri.port)
|
88
|
-
http.use_ssl = true
|
89
|
-
|
90
|
-
header = {'Cookie' => @cookie}
|
91
|
-
|
92
|
-
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/temperature", header)
|
93
|
-
res = http.request(req)
|
94
|
-
JSON.parse(res.body)
|
95
|
-
end
|
96
|
-
|
97
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
class BritishGasHive
|
8
|
+
|
9
|
+
@hub = nil
|
10
|
+
@cookie = nil
|
11
|
+
|
12
|
+
def initialize(username, password, caller, bg = false)
|
13
|
+
if bg == true
|
14
|
+
@uri = URI("https://api.bgchlivehome.co.uk/v5")
|
15
|
+
else
|
16
|
+
@uri = URI("https://api.alertme.com/v5")
|
17
|
+
end
|
18
|
+
@session = self.login(username, password, caller)
|
19
|
+
@username = username
|
20
|
+
@password = password
|
21
|
+
end
|
22
|
+
|
23
|
+
def login(username, password, caller)
|
24
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
25
|
+
http.use_ssl = true
|
26
|
+
|
27
|
+
request = Net::HTTP::Post.new("#{@uri.path}/login")
|
28
|
+
request.set_form_data({"username" => username, "password" => password, "caller" => caller})
|
29
|
+
|
30
|
+
response = http.request(request)
|
31
|
+
all_cookies = response.get_fields('set-cookie')
|
32
|
+
cookies_array = Array.new
|
33
|
+
all_cookies.each { | cookie |
|
34
|
+
cookies_array.push(cookie.split('; ')[0])
|
35
|
+
}
|
36
|
+
@cookie = cookies_array.join('; ')
|
37
|
+
|
38
|
+
json = JSON.parse(response.body)
|
39
|
+
@hub = json["hubIds"].first
|
40
|
+
end
|
41
|
+
|
42
|
+
def getDevices
|
43
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
44
|
+
http.use_ssl = true
|
45
|
+
|
46
|
+
header = {'Cookie' => @cookie}
|
47
|
+
|
48
|
+
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices", header)
|
49
|
+
res = http.request(req)
|
50
|
+
JSON.parse(res.body)
|
51
|
+
end
|
52
|
+
|
53
|
+
def getDeviceByType(type)
|
54
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
55
|
+
http.use_ssl = true
|
56
|
+
|
57
|
+
header = {'Cookie' => @cookie}
|
58
|
+
|
59
|
+
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices/#{type}", header)
|
60
|
+
res = http.request(req)
|
61
|
+
JSON.parse(res.body)
|
62
|
+
end
|
63
|
+
|
64
|
+
def getTarget()
|
65
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
66
|
+
http.use_ssl = true
|
67
|
+
|
68
|
+
header = {'Cookie' => @cookie}
|
69
|
+
|
70
|
+
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/climate/targetTemperature", header)
|
71
|
+
res = http.request(req)
|
72
|
+
JSON.parse(res.body)
|
73
|
+
end
|
74
|
+
|
75
|
+
def getClimate()
|
76
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
77
|
+
http.use_ssl = true
|
78
|
+
|
79
|
+
header = {'Cookie' => @cookie}
|
80
|
+
|
81
|
+
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/climate", header)
|
82
|
+
res = http.request(req)
|
83
|
+
JSON.parse(res.body)
|
84
|
+
end
|
85
|
+
|
86
|
+
def getTemperature()
|
87
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
88
|
+
http.use_ssl = true
|
89
|
+
|
90
|
+
header = {'Cookie' => @cookie}
|
91
|
+
|
92
|
+
req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/temperature", header)
|
93
|
+
res = http.request(req)
|
94
|
+
JSON.parse(res.body)
|
95
|
+
end
|
96
|
+
|
97
|
+
def setTemperature(temperature, unit)
|
98
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
99
|
+
http.use_ssl = true
|
100
|
+
|
101
|
+
header = {'Cookie' => @cookie}
|
102
|
+
|
103
|
+
req = Net::HTTP::Put.new("#{@uri.path}/users/#{@username}/widgets/climate/targetTemperature", header)
|
104
|
+
req.set_form_data({"temperature" => temperature, "temperatureUnit" => unit})
|
105
|
+
res = http.request(req)
|
106
|
+
if res.code == "204"
|
107
|
+
print "Sucess"
|
108
|
+
else
|
109
|
+
print "Fail"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: BritishGasHive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Douce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby interface for the alertMe API used by British Gas in the HIVE
|
14
14
|
Active Heating system, Very limited at the moment more features to come soon
|