Class: Bluepay::Response
- Inherits:
-
Object
- Object
- Bluepay::Response
- Defined in:
- lib/bluepay/response.rb
Overview
bpdailyreport2 returns csv in body bp10emu returns 302, html body, details are in Location header stq returns query string in body
#data returns a unified merge of all the data sources, with tabular data under the key :rows as an array of OpenStruct instances
Constant Summary collapse
- LOCATION =
'Location'.freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #body ⇒ Object
- #body_csv ⇒ Object
- #body_params ⇒ Object
- #body_rows ⇒ Object
- #code ⇒ Object
- #data ⇒ Object
- #headers ⇒ Object
-
#initialize(http) ⇒ Response
constructor
A new instance of Response.
- #location_query_params ⇒ Object
- #params ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(http) ⇒ Response
Returns a new instance of Response.
14 15 16 |
# File 'lib/bluepay/response.rb', line 14 def initialize(http) @response = http end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
12 13 14 |
# File 'lib/bluepay/response.rb', line 12 def action @action end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
12 13 14 |
# File 'lib/bluepay/response.rb', line 12 def response @response end |
Instance Method Details
#body ⇒ Object
57 58 59 |
# File 'lib/bluepay/response.rb', line 57 def body response.body end |
#body_csv ⇒ Object
34 35 36 37 |
# File 'lib/bluepay/response.rb', line 34 def body_csv require 'csv' CSV.parse(response.body, headers: true) rescue Array.new end |
#body_params ⇒ Object
22 23 24 |
# File 'lib/bluepay/response.rb', line 22 def body_params URI.decode_www_form(response.body).sort.to_h rescue {} end |
#body_rows ⇒ Object
39 40 41 |
# File 'lib/bluepay/response.rb', line 39 def body_rows body_csv.each.map {|r| OpenStruct.new(r.to_h)} end |
#code ⇒ Object
53 54 55 |
# File 'lib/bluepay/response.rb', line 53 def code response.code.to_i end |
#data ⇒ Object
43 44 45 46 47 |
# File 'lib/bluepay/response.rb', line 43 def data params.to_h.merge( rows: body_rows ) end |
#headers ⇒ Object
61 62 63 |
# File 'lib/bluepay/response.rb', line 61 def headers response.to_hash end |
#location_query_params ⇒ Object
18 19 20 |
# File 'lib/bluepay/response.rb', line 18 def location_query_params URI.decode_www_form(URI(response['Location']).query).sort.to_h rescue {} end |
#params ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/bluepay/response.rb', line 26 def params location_query_params.merge(body_params).inject({}) { |memo, kv| k, v = kv memo[k.to_s.downcase.to_sym] = v memo } end |
#to_h ⇒ Object
49 50 51 |
# File 'lib/bluepay/response.rb', line 49 def to_h data end |