Class: Rester::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rester/client/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(status, hash = {}) ⇒ Response

Returns a new instance of Response.



4
5
6
7
8
9
# File 'lib/rester/client/response.rb', line 4

def initialize(status, hash={})
  @_status = status
  @_data = hash.dup || {}
  Utils.deep_freeze(@_data)
  freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



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

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

Instance Method Details

#==(obj) ⇒ Object



19
20
21
# File 'lib/rester/client/response.rb', line 19

def ==(obj)
  @_data == obj
end

#successful?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/rester/client/response.rb', line 11

def successful?
  @_status && @_status.between?(200, 299)
end

#to_hObject



15
16
17
# File 'lib/rester/client/response.rb', line 15

def to_h
  @_data.dup
end