Class: Wirecard::Elastic::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/wirecard/elastic/request.rb,
lib/wirecard/elastic/request/base.rb,
lib/wirecard/elastic/request/refund.rb,
lib/wirecard/elastic/request/transaction.rb,
lib/wirecard/elastic/request/body/builder.rb,
lib/wirecard/elastic/request/body/builder/xml.rb,
lib/wirecard/elastic/request/body/params/refund.rb

Defined Under Namespace

Modules: Body Classes: Base, Refund, Transaction

Constant Summary collapse

CONTENT_TYPE =

content type might be flexible in the future for now it’s a simple constant as the API is still simple

'text/xml'.freeze
ALLOWED_METHODS =

allowed methods to communicate to the API a get is usually without body a post will be with XML datas transmitted

[:get, :post]
URL_PATTERN =

checking of the URL validity via REGEX

/\A#{URI::regexp(['http', 'https'])}\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query_uri:, payment_method:, method: :get, body: '') ⇒ Request

prepare the request datas and check the query URL on the fly



25
26
27
28
29
30
31
# File 'lib/wirecard/elastic/request.rb', line 25

def initialize(query_uri:, payment_method:, method: :get, body: '')
  @payment_method = payment_method
  @method         = method
  @body           = body
  @query_uri      = query_uri
  raise Wirecard::Elastic::ConfigError, "Invalid engine URL. Please check your configuration." unless valid_query?
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



22
23
24
# File 'lib/wirecard/elastic/request.rb', line 22

def body
  @body
end

#methodObject (readonly)

Returns the value of attribute method.



22
23
24
# File 'lib/wirecard/elastic/request.rb', line 22

def method
  @method
end

#payment_methodObject (readonly)

Returns the value of attribute payment_method.



22
23
24
# File 'lib/wirecard/elastic/request.rb', line 22

def payment_method
  @payment_method
end

#query_uriObject (readonly)

Returns the value of attribute query_uri.



22
23
24
# File 'lib/wirecard/elastic/request.rb', line 22

def query_uri
  @query_uri
end

Instance Method Details

#dispatch!Object

process the actual call and return the instance raise an error if the server didn’t answer anything



35
36
37
38
39
40
41
42
43
# File 'lib/wirecard/elastic/request.rb', line 35

def dispatch!
  @dispatch ||= begin
    if feedback.nil?
      raise Wirecard::Elastic::Error, "The request was not successful"
    else
      self
    end
  end
end

#feedbackObject

get the http raw response from the API it’s supposed to be a simple string we might parse as JSON later on



53
54
55
56
57
# File 'lib/wirecard/elastic/request.rb', line 53

def feedback
  @feedback ||= Net::HTTP.start(query_url.host, query_url.port,
  :use_ssl     => https_request?,
  :verify_mode => OpenSSL::SSL::VERIFY_NONE) { |connection| send(connection) }
end

#queryObject

compose the query via configuration and transmitted URI



46
47
48
# File 'lib/wirecard/elastic/request.rb', line 46

def query
  @query ||= "#{gateway[:engine_url]}#{query_uri}.json"
end