Class: VantivLite::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/vantiv_lite/request.rb

Constant Summary collapse

InvalidConfig =
Class.new(StandardError)
ResponseError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = VantivLite.default_config, http: nil, serializer: nil) ⇒ Request

Returns a new instance of Request.

Raises:



24
25
26
27
28
29
30
# File 'lib/vantiv_lite/request.rb', line 24

def initialize(config = VantivLite.default_config, http: nil, serializer: nil)
  raise InvalidConfig, 'invalid or missing config' unless config.is_a?(Config)
  @config = config
  @http = http || _http
  @parser = XML.parser_with(config.xml_lib)
  @serializer = serializer || XML.serializer_with(config.xml_lib)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#httpObject (readonly)

Returns the value of attribute http.



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

def http
  @http
end

#serializerObject (readonly)

Returns the value of attribute serializer.



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

def serializer
  @serializer
end

Instance Method Details

#call(request_hash, *dig_keys) ⇒ Object



32
33
34
# File 'lib/vantiv_lite/request.rb', line 32

def call(request_hash, *dig_keys)
  Response.new(post(serializer.(format_request(request_hash))), *dig_keys, parser: @parser)
end

#post(xml) ⇒ Object



36
37
38
# File 'lib/vantiv_lite/request.rb', line 36

def post(xml)
  http.dup.start { |h| h.request(post_request(xml)) }
end