Class: MyTado::Response::AbstractResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/my_tado/response/abstract_response.rb

Overview

Make response a bit easier to deal with in Ruby, largely by converting datetimes to Ruby DateTime objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ AbstractResponse

Returns a new instance of AbstractResponse.



12
13
14
15
# File 'lib/my_tado/response/abstract_response.rb', line 12

def initialize(raw_response)
  @raw_response = raw_response
  parse
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/my_tado/response/abstract_response.rb', line 25

def method_missing(method_name, *args, &block)
  if @parsed_response.respond_to?(method_name)
    @parsed_response.public_send(method_name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



10
11
12
# File 'lib/my_tado/response/abstract_response.rb', line 10

def raw_response
  @raw_response
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/my_tado/response/abstract_response.rb', line 17

def ok?
  raw_response.ok?
end

#parseObject



21
22
23
# File 'lib/my_tado/response/abstract_response.rb', line 21

def parse
  @parsed_response = recursive_parse(raw_response.parsed_response)
end

#respond_to_missing?(method_name, *_args) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/my_tado/response/abstract_response.rb', line 33

def respond_to_missing?(method_name, *_args)
  @parsed_response.respond_to?(method_name)
end