Class: Veritrans::Result
- Inherits:
-
Object
show all
- Defined in:
- lib/veritrans/result.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(response, url, options, time) ⇒ Result
Returns a new instance of Result.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/veritrans/result.rb', line 7
def initialize(response, url, options, time)
begin
if url =~ %r{/v2/.+/transcript$}
@data = {}
else
@data = Veritrans._json_decode(response.body)
@data.keys.each do |key|
@data[(key.to_sym rescue key) || key] = @data.delete(key)
end
end
rescue => e
Veritrans.logger.info "Error parsing papi response #{e.message}"
Veritrans.logger.info e.backtrace.join("\n")
@data = {}
end
@time = time
@status = response.status
@response = response
@url = url
@options = options
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/veritrans/result.rb', line 67
def method_missing(method_name, *args)
if args.size == 0 && @data && @data.has_key?(method_name)
return @data[method_name]
else
super
end
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
3
4
5
|
# File 'lib/veritrans/result.rb', line 3
def data
@data
end
|
#response ⇒ Object
Returns the value of attribute response.
5
6
7
|
# File 'lib/veritrans/result.rb', line 5
def response
@response
end
|
#status ⇒ Object
Returns the value of attribute status.
4
5
6
|
# File 'lib/veritrans/result.rb', line 4
def status
@status
end
|
Instance Method Details
#body ⇒ Object
63
64
65
|
# File 'lib/veritrans/result.rb', line 63
def body
response.body
end
|
#created? ⇒ Boolean
38
39
40
|
# File 'lib/veritrans/result.rb', line 38
def created?
@data[:status_code] == '201'
end
|
#inspect ⇒ Object
75
76
77
78
79
|
# File 'lib/veritrans/result.rb', line 75
def inspect
time_ms = (@time * 1000).round
data = @data.inspect.gsub(/:([^\s]+)=>/, "\\1: ")
"#<Veritrans::Result:#{object_id} ^^ http_status: #{@status} time: #{time_ms}ms ^^ data: #{data}>"
end
|
#messages ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/veritrans/result.rb', line 55
def messages
if @data[:message].present?
@data[:message].chomp(']').sub(/^\[/, '').split(',').map(&:strip)
else
[]
end
end
|
#redirect_url ⇒ Object
51
52
53
|
# File 'lib/veritrans/result.rb', line 51
def redirect_url
@data[:redirect_url]
end
|
#status_code ⇒ Object
43
44
45
|
# File 'lib/veritrans/result.rb', line 43
def status_code
@data[:status_code].to_i
end
|
#status_message ⇒ Object
47
48
49
|
# File 'lib/veritrans/result.rb', line 47
def status_message
@data[:status_message]
end
|
#success? ⇒ Boolean
33
34
35
|
# File 'lib/veritrans/result.rb', line 33
def success?
@data[:status_code] == '200' || @data[:status_code] == '201'
end
|