Class: Fulfillment::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/fulfillment/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



9
10
11
# File 'lib/fulfillment/response.rb', line 9

def initialize(raw_response)
  @raw_response = raw_response
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/fulfillment/response.rb', line 5

def errors
  @errors
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



5
6
7
# File 'lib/fulfillment/response.rb', line 5

def raw_response
  @raw_response
end

Instance Method Details

#on_error {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
# File 'lib/fulfillment/response.rb', line 17

def on_error
  yield self unless success?
  self
end

#raise_errorsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fulfillment/response.rb', line 22

def raise_errors
  case status
  when 400
    fail InvalidRequest, body
  when 401
    fail AccessDenied, body
  when 403
    fail InvalidEvent, body
  when 404
    fail ResourceNotFound, body
  when 405
    fail MethodNotAllowed, body
  when (400..499)
    fail ServiceError, body
  when (500..599)
    fail ServerError, body
  end
end

#success?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/fulfillment/response.rb', line 13

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