class AlertMe

Public Class Methods

new(username, password, caller, bg = false) click to toggle source
# File lib/alertme.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

getDeviceByType(type) click to toggle source
# File lib/alertme.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/alertme.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
getHeatingControllerById(id) click to toggle source
# File lib/alertme.rb, line 64
def getHeatingControllerById(id)
  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/HeatingController/#{id}", header)
  res = http.request(req)
  JSON.parse(res.body)
end
getHouseholdDetails() click to toggle source
# File lib/alertme.rb, line 75
def getHouseholdDetails
  http = Net::HTTP.new(@uri.host, @uri.port)
  http.use_ssl = true

  header = {'Cookie' => @cookie}

  req = Net::HTTP::Get.new("#{@uri.path}/users/#{@username}/householdDetails", header)
  res = http.request(req)
  JSON.parse(res.body)["values"]
end
login(username, password, caller) click to toggle source
# File lib/alertme.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