Class: Wirecard::Elastic::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/wirecard/elastic/response.rb,
lib/wirecard/elastic/response/base.rb,
lib/wirecard/elastic/response/refund.rb,
lib/wirecard/elastic/response/transaction.rb

Defined Under Namespace

Classes: Base, Refund, Transaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request:, action:) ⇒ Response

Returns a new instance of Response.



9
10
11
12
# File 'lib/wirecard/elastic/response.rb', line 9

def initialize(request:, action:)
  @request = request
  @action = action
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



7
8
9
# File 'lib/wirecard/elastic/response.rb', line 7

def action
  @action
end

#requestObject (readonly)

Returns the value of attribute request.



7
8
9
# File 'lib/wirecard/elastic/response.rb', line 7

def request
  @request
end

Instance Method Details

#dispatch!Object

check the response and parse it if possible via JSON transmit the process to one of the Response subclasses (e.g. Refund, Transaction)



16
17
18
19
20
21
22
# File 'lib/wirecard/elastic/response.rb', line 16

def dispatch!
  if response.nil?
    raise Wirecard::Elastic::Error, "The request failed."
  else
    Wirecard::Elastic::Response.const_get(action.capitalize).new(request, response)
  end
end

#responseObject

process the API feedback by converting it into JSON



25
26
27
# File 'lib/wirecard/elastic/response.rb', line 25

def response
  @response ||= JSON.parse(request.feedback.body).deep_symbolize_keys if valid_body?
end