Class: TINCheck::Request

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

Constant Summary collapse

SERVICES =
{
  list_match: 'ValidateListMatch',
  status: 'ServiceStatus',
  tin_name: 'ValidateTinName',
  validate_all: 'ValidateTinNameAddressListMatch'
}.freeze
SERVICE_XMLNS =
'http://www.TinCheck.com/WebServices/PVSService/'.freeze
InvalidConfig =
Class.new(StandardError)
ResponseError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Request.

Raises:



22
23
24
25
26
27
28
# File 'lib/tincheck/request.rb', line 22

def initialize(config = TINCheck.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.



20
21
22
# File 'lib/tincheck/request.rb', line 20

def config
  @config
end

#httpObject (readonly)

Returns the value of attribute http.



20
21
22
# File 'lib/tincheck/request.rb', line 20

def http
  @http
end

#serializerObject (readonly)

Returns the value of attribute serializer.



20
21
22
# File 'lib/tincheck/request.rb', line 20

def serializer
  @serializer
end

Instance Method Details

#call(request_hash) ⇒ Object



30
31
32
33
# File 'lib/tincheck/request.rb', line 30

def call(request_hash)
  r = post(serializer.(format_request(request_hash)))
  Response.with_http_response(r, parser: @parser)
end

#post(xml) ⇒ Object



35
36
37
# File 'lib/tincheck/request.rb', line 35

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

#statusObject



39
40
41
# File 'lib/tincheck/request.rb', line 39

def status(*)
  call(SERVICES[:status] => {})
end

#tin_name(**kwargs) ⇒ Object



43
44
45
46
# File 'lib/tincheck/request.rb', line 43

def tin_name(**kwargs)
  require_arguments!(kwargs, :name, :tin)
  call(SERVICES[:tin_name] => tin_name_arg(**kwargs))
end