Class: Fritzbox::Smarthome::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/fritzbox/smarthome/resource.rb

Direct Known Subclasses

Actor

Constant Summary collapse

AuthenticationError =
Class.new(RuntimeError)

Class Method Summary collapse

Class Method Details

.get(command:, ain: nil, param: nil, **params) ⇒ Object

Parameters:

  • params (Hash)

    key/value pairs that will be appended to the switchcmd query string



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fritzbox/smarthome/resource.rb', line 10

def get(command:, ain: nil, param: nil, **params)
  url = "#{config.endpoint}/webservices/homeautoswitch.lua?switchcmd=#{command}&sid=#{authenticate}"
  url = "#{url}&ain=#{ain}"     if ain.present?
  url = "#{url}&param=#{param}" if param.present?

  params.each_with_object(url) do |(key, value)|
    url = "#{url}&#{key}=#{value}"
  end

  response = measure(url) { HTTParty.get(url, **httparty_options) }

  raise AuthenticationError if response.code == 403

  response
rescue AuthenticationError
  raise if session.nil?

  self.session = nil
  retry
end

.parse(response) ⇒ Object



31
32
33
# File 'lib/fritzbox/smarthome/resource.rb', line 31

def parse(response)
  nori.parse(response.body)
end