Class: BritishGasHive
- Inherits:
-
Object
- Object
- BritishGasHive
- Defined in:
- lib/britishgashive.rb
Instance Method Summary collapse
- #getClimate ⇒ Object
- #getDeviceByType(type) ⇒ Object
- #getDevices ⇒ Object
- #getTarget ⇒ Object
- #getTemperature ⇒ Object
-
#initialize(username, password, caller, bg = false) ⇒ BritishGasHive
constructor
A new instance of BritishGasHive.
- #login(username, password, caller) ⇒ Object
- #setTemperature(temperature, unit) ⇒ Object
Constructor Details
#initialize(username, password, caller, bg = false) ⇒ BritishGasHive
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/britishgashive.rb', line 12 def initialize(username, password, caller, bg = false) if bg == true @uri = URI("https://api.bgchlivehome.co.uk/v5") else @uri = URI("https://api.alertme.com/v5") end @session = self.login(username, password, caller) @username = username @password = password end |
Instance Method Details
#getClimate ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/britishgashive.rb', line 75 def getClimate() http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => } req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/climate", header) res = http.request(req) JSON.parse(res.body) end |
#getDeviceByType(type) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/britishgashive.rb', line 53 def getDeviceByType(type) http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => } req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices/#{type}", header) res = http.request(req) JSON.parse(res.body) end |
#getDevices ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/britishgashive.rb', line 42 def getDevices http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => } req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices", header) res = http.request(req) JSON.parse(res.body) end |
#getTarget ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/britishgashive.rb', line 64 def getTarget() http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => } req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/climate/targetTemperature", header) res = http.request(req) JSON.parse(res.body) end |
#getTemperature ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/britishgashive.rb', line 86 def getTemperature() http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => } req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/temperature", header) res = http.request(req) JSON.parse(res.body) end |
#login(username, password, caller) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/britishgashive.rb', line 23 def login(username, password, caller) http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true request = Net::HTTP::Post.new("#{@uri.path}/login") request.set_form_data({"username" => username, "password" => password, "caller" => caller}) response = http.request(request) = response.get_fields('set-cookie') = Array.new .each { | | .push(.split('; ')[0]) } = .join('; ') json = JSON.parse(response.body) @hub = json["hubIds"].first end |
#setTemperature(temperature, unit) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/britishgashive.rb', line 97 def setTemperature(temperature, unit) http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => } req = Net::HTTP::Put.new("#{@uri.path}/users/#{@username}/widgets/climate/targetTemperature", header) req.set_form_data({"temperature" => temperature, "temperatureUnit" => unit}) res = http.request(req) if res.code == "204" print "Sucess" else print "Fail" end end |