Class: Mambu::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faraday_response) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
12
# File 'lib/mambu/response.rb', line 5

def initialize(faraday_response)
  @faraday_response = faraday_response
  @http_status = faraday_response.status
  @body = parse_body(faraday_response.body)
  return self if success?
  @error_code = @body[:return_code]
  @error_status = @body[:return_status]
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/mambu/response.rb', line 3

def body
  @body
end

#error_codeObject (readonly)

Returns the value of attribute error_code.



3
4
5
# File 'lib/mambu/response.rb', line 3

def error_code
  @error_code
end

#error_statusObject (readonly)

Returns the value of attribute error_status.



3
4
5
# File 'lib/mambu/response.rb', line 3

def error_status
  @error_status
end

#faraday_responseObject (readonly)

Returns the value of attribute faraday_response.



3
4
5
# File 'lib/mambu/response.rb', line 3

def faraday_response
  @faraday_response
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



3
4
5
# File 'lib/mambu/response.rb', line 3

def http_status
  @http_status
end

Instance Method Details

#errorObject



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

def error
  return nil if success?
  Mambu::Error.new(error_message, error_code, error_status)
end

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !success?
end

#error_messageObject



22
23
24
# File 'lib/mambu/response.rb', line 22

def error_message
  error_status.humanize
end

#success?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/mambu/response.rb', line 14

def success?
  @faraday_response.success?
end