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.



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

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



31
32
33
34
# File 'lib/drip/response.rb', line 31

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.



6
7
8
# File 'lib/drip/response.rb', line 6

def body
  @body
end

Returns the value of attribute links.



6
7
8
# File 'lib/drip/response.rb', line 6

def links
  @links
end

#membersObject (readonly)

Returns the value of attribute members.



6
7
8
# File 'lib/drip/response.rb', line 6

def members
  @members
end

#metaObject (readonly)

Returns the value of attribute meta.



6
7
8
# File 'lib/drip/response.rb', line 6

def meta
  @meta
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/drip/response.rb', line 6

def status
  @status
end

Instance Method Details

#==(other) ⇒ Object



18
19
20
21
# File 'lib/drip/response.rb', line 18

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

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

Returns:

  • (Boolean)


27
28
29
# File 'lib/drip/response.rb', line 27

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

#success?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/drip/response.rb', line 23

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