Class: TransactPro::Response
- Inherits:
-
Object
- Object
- TransactPro::Response
- Defined in:
- lib/transact_pro/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Instance Method Summary collapse
-
#initialize(body) ⇒ Response
constructor
A new instance of Response.
- #redirect_link ⇒ Object
- #status ⇒ Object
- #tid ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(body) ⇒ Response
Returns a new instance of Response.
4 5 6 |
# File 'lib/transact_pro/response.rb', line 4 def initialize(body) @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
2 3 4 |
# File 'lib/transact_pro/response.rb', line 2 def body @body end |
Instance Method Details
#redirect_link ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/transact_pro/response.rb', line 20 def redirect_link link_portion = body.split("~").detect do |portion| portion[%r'\ARedirectOnsite:'] end link_portion.nil? ? nil : link_portion.match(%r'\ARedirectOnsite:(https?://.*?tid=[[:alnum:]]+)'i)[1] end |
#status ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/transact_pro/response.rb', line 30 def status status_portion = body.split("~").detect do |portion| portion[%r'\A(OK)|(Status)\:'] end if status_portion.to_s[%r'\AOK'] "OK" elsif status_portion.to_s[%r'\AStatus'] status = status_portion.match(%r'\AStatus:(.*)')[1] status == "Success" ? "OK" : "FAIL" else "ERROR" end end |
#tid ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/transact_pro/response.rb', line 45 def tid tid_portion = body.split("~").detect do |portion| portion[%r'\AOK\:'] end tid_portion.nil? ? nil : tid_portion.match(%r'\A(.*?)\:(.*)')[2] end |
#to_h ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/transact_pro/response.rb', line 12 def to_h @to_h ||= body.split("~").inject({}) do |mem, portion| match = portion.match(%r'\A([^\:]+?)\:(.*)') mem[match[1]] = match[2] mem end end |
#to_s ⇒ Object
8 9 10 |
# File 'lib/transact_pro/response.rb', line 8 def to_s body end |