class BritishGasHive
Public Class Methods
new(username, password, caller, bg = false)
click to toggle source
# 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
Public Instance Methods
getClimate()
click to toggle source
# File lib/britishgashive.rb, line 75 def getClimate() http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => @cookie} req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/climate", header) res = http.request(req) JSON.parse(res.body) end
getDeviceByType(type)
click to toggle source
# File lib/britishgashive.rb, line 53 def getDeviceByType(type) http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => @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()
click to toggle source
# File lib/britishgashive.rb, line 42 def getDevices http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => @cookie} req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/hubs/#{@hub}/devices", header) res = http.request(req) JSON.parse(res.body) end
getTarget()
click to toggle source
# File lib/britishgashive.rb, line 64 def getTarget() http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => @cookie} req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/widgets/climate/targetTemperature", header) res = http.request(req) JSON.parse(res.body) end
getTemperature()
click to toggle source
# File lib/britishgashive.rb, line 86 def getTemperature() http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => @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)
click to toggle source
# 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) all_cookies = response.get_fields('set-cookie') cookies_array = Array.new all_cookies.each { | cookie | cookies_array.push(cookie.split('; ')[0]) } @cookie = cookies_array.join('; ') json = JSON.parse(response.body) @hub = json["hubIds"].first end
setTemperature(temperature, unit)
click to toggle source
# File lib/britishgashive.rb, line 97 def setTemperature(temperature, unit) http = Net::HTTP.new(@uri.host, @uri.port) http.use_ssl = true header = {'Cookie' => @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