Class: V2Intuity::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
# File 'lib/v2_intuity/response.rb', line 5

def initialize(attributes = {})
  @request = attributes[:request]
  @response = attributes[:response]
  @errors = []
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

#requestObject

Returns the value of attribute request.



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

def request
  @request
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#add_errors(error) ⇒ Object



24
25
26
# File 'lib/v2_intuity/response.rb', line 24

def add_errors(error)
  @errors.push(error)
end

#bodyObject



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

def body
  !@response.nil? ? @response.body : nil
end

#codeObject



40
41
42
# File 'lib/v2_intuity/response.rb', line 40

def code
  !@response.nil? ? @response.code : nil
end

#define_response_and_json(response) ⇒ Object



11
12
13
14
# File 'lib/v2_intuity/response.rb', line 11

def define_response_and_json(response)
  @response = response if @response.nil?
  g_json if @json.nil?
end

#g_jsonObject

store parsed response so we don’t have to reparse



34
35
36
37
38
# File 'lib/v2_intuity/response.rb', line 34

def g_json # store parsed response so we don't have to reparse
  return @json if @json

  json(parse_json(@response.body)) unless @response.to_s.nil?
end

#headersObject



16
17
18
# File 'lib/v2_intuity/response.rb', line 16

def headers
  !@response.nil? ? @response.headers : nil
end

#messageObject



44
45
46
# File 'lib/v2_intuity/response.rb', line 44

def message
  !@response.nil? ? @response.message : nil
end

#success?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/v2_intuity/response.rb', line 28

def success?
  return nil if @response.nil?

  @errors.to_a.empty? ? true : false
end