Class: Drip::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
17
18
# File 'lib/drip/response.rb', line 10

def initialize(status, body)
  @status = status
  @body = body
  @links = parse_links
  @meta = parse_meta
  @members = parse_members

  @body.freeze
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



33
34
35
36
# File 'lib/drip/response.rb', line 33

def method_missing(method_name, *args, &block)
  return super unless member_map.keys.include?(method_name)
  members[member_map[method_name]]
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/drip/response.rb', line 8

def body
  @body
end

Returns the value of attribute links.



8
9
10
# File 'lib/drip/response.rb', line 8

def links
  @links
end

#membersObject (readonly)

Returns the value of attribute members.



8
9
10
# File 'lib/drip/response.rb', line 8

def members
  @members
end

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'lib/drip/response.rb', line 8

def meta
  @meta
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/drip/response.rb', line 8

def status
  @status
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
23
# File 'lib/drip/response.rb', line 20

def ==(other)
  status == other.status &&
    body == other.body
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/drip/response.rb', line 29

def respond_to?(method_name, include_private = false)
  member_map.keys.include?(method_name) || super
end

#success?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/drip/response.rb', line 25

def success?
  (200..299).cover?(status)
end