BritishGasHive 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/britishgashive.rb +97 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 148d15ebb61649f323b5e49d7b194ca3d6778b19
4
+ data.tar.gz: 9d390e7308ef5fe39f715a854368abd3f6274e74
5
+ SHA512:
6
+ metadata.gz: aaa2a6ee7f86cc3209afc644128ea99082f6dc1a311800d9f55f08fabb3b1d511899695bca2246154e03f3d2d178e3e5f6168a991832b1c9a7cfe1af268544d5
7
+ data.tar.gz: b251a186cde1b31fbd5ac84d5cba7ec92107bfeecbaf58cdb4b3fd6fe5395448ce182b6207fa463eb922d365ee1beca1efb0696922ca1a339ab230d6b2de078f
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'uri'
4
+ require 'net/http'
5
+ require 'json'
6
+
7
+ class AlertMe
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
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: BritishGasHive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Douce
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby interface for the AlertMe API used by British Gas in the HIVE
14
+ Active Heating system, Very limited at the moment more features to come soon
15
+ email: affix@affix.me
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/britishgashive.rb
21
+ homepage: http://rubygems.org/gems/BritishGasHive
22
+ licenses:
23
+ - GPL
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.5
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Ruby Bindings for the BritishGasHive API!
45
+ test_files: []