AlertMe 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/alertme.rb +86 -0
  3. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5afb7723174bff990fef9c5313aa30e21ee7794d
4
+ data.tar.gz: 399011bbc2fa75948b5b0963ea1696183bb9a50a
5
+ SHA512:
6
+ metadata.gz: 6a76a21212e4b9b161802f63095e1397c4a1af180ff6442c8ff4b331090b61c273bad589e081f66770634c25f64fc8a7791dfb9f796d699760fac7b74cd613d4
7
+ data.tar.gz: a3f981c2432b31c0b62f47ebf6b7a0d45f3a12a00f0be2476786443054ba399bf369edf6e210e13082886124deed4d75922fd249010d2971fa04229291abf507
@@ -0,0 +1,86 @@
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 getHeatingControllerById(id)
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}/hubs/#{@hub}/devices/HeatingController/#{id}", header)
71
+ res = http.request(req)
72
+ JSON.parse(res.body)
73
+ end
74
+
75
+ def getHouseholdDetails
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}/householdDetails", header)
82
+ res = http.request(req)
83
+ JSON.parse(res.body)["values"]
84
+ end
85
+
86
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: AlertMe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keiran Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby interface for the alertMe API used by Brittish 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/alertme.rb
21
+ homepage: http://rubygems.org/gems/AlertMe
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.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Ruby Bindings for the AlertMe API!
45
+ test_files: []
46
+ has_rdoc: