Class: ExactorApi::ExactorApiService

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/exactor_api_service.rb

Instance Method Summary collapse

Instance Method Details

#send_request(taxRequest) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/exactor_api_service.rb', line 10

def send_request (taxRequest)

  unless taxRequest.is_a? TaxRequest
    return nil
  end
  request = create_request(taxRequest)
  request.add_field("Content-Type","application/xml")

  plugin_name = taxRequest.xmlattr_plugin
  plugin_version = taxRequest.xmlattr_version

  request.add_field("User-Agent", "#{plugin_name}-#{plugin_version}")

  response = Net::HTTP.start(API_URI.hostname, 80) do |http|
    http.request(request)
  end

  case response
    when Net::HTTPSuccess then
      return XmlSimple.xml_in(response.body)
    when Net::HTTPBadRequest then
      raise ArgumentError.new(response.body)
    else
      return nil
  end

  return nil
end