class Fritzbox::Smarthome::Resource
Public Class Methods
get(command:, ain: nil, param: nil)
click to toggle source
# File lib/fritzbox/smarthome/resource.rb, line 5 def get(command:, ain: nil, param: nil) url = "#{config.endpoint}/webservices/homeautoswitch.lua?switchcmd=#{command}&sid=#{authenticate}" url = "#{url}&ain=#{ain}" if ain.present? url = "#{url}¶m=#{param}" if param.present? HTTParty.get(url, **httparty_options) end
Private Class Methods
authenticate()
click to toggle source
# File lib/fritzbox/smarthome/resource.rb, line 17 def authenticate response = HTTParty.get(login_endpoint, **httparty_options) xml = nori.parse(response.body) challenge = xml.dig('SessionInfo', 'Challenge') md5 = Digest::MD5.hexdigest("#{challenge}-#{config.password}".encode('UTF-16LE')) url = "#{login_endpoint}?response=#{challenge}-#{md5}" url = "#{url}&username=#{config.username}" if config.username.present? response = HTTParty.get(url, **httparty_options) xml = nori.parse(response.body) xml.dig('SessionInfo', 'SID') end
httparty_options()
click to toggle source
# File lib/fritzbox/smarthome/resource.rb, line 37 def httparty_options { verify: config.verify_ssl, logger: config.logger }.compact end
login_endpoint()
click to toggle source
# File lib/fritzbox/smarthome/resource.rb, line 33 def login_endpoint "#{config.endpoint}/login_sid.lua" end
nori()
click to toggle source
# File lib/fritzbox/smarthome/resource.rb, line 44 def nori @nori ||= Nori.new end