Class: VatInfo::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/vat_info/query.rb

Constant Summary collapse

DOCS =
'https://adisspr.mfcr.cz/adistc/adis/idpr_pub/dpr_info/ws_spdph.faces'.freeze
WSDL =
'http://adisrws.mfcr.cz/adistc/axis2/services/rozhraniCRPDPH.rozhraniCRPDPHSOAP?wsdl'.freeze
TIMEOUT =
2
SERVICE_UNAVAILABLE =
503
REQUEST_TIME_OUT =
408

Class Method Summary collapse

Class Method Details

.call(request, endpoint, wsdl = WSDL, timeout = TIMEOUT) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vat_info/query.rb', line 13

def self.call(request, endpoint, wsdl = WSDL, timeout = TIMEOUT)
  client = Savon.client(wsdl: wsdl, open_timeout: timeout)

  begin
    response = client.call(endpoint, xml: request)
    if response.success?
      VatInfo::Response.new(status_code: 200, raw: response.body)
    else
      VatInfo::Response.new(status_code: SERVICE_UNAVAILABLE)
    end
  rescue Savon::HTTPError => e
    if e.to_s.include?('sorry-page.html')
      VatInfo::Response.new(status_code: SERVICE_UNAVAILABLE)
    else
      raise e
    end
  rescue Net::OpenTimeout
    VatInfo::Response.new(status_code: REQUEST_TIME_OUT)
  rescue Savon::SOAPFault => e
    raise SchemaError, 'The SOAP schema of VAT service may have changed. Go to '\
                       "#{DOCS} to verify. Original error: #{e}"
  end
end