Class: Parsbank::SOAP
- Inherits:
-
Object
- Object
- Parsbank::SOAP
- Defined in:
- lib/parsbank/soap.rb
Overview
SOAP Client Class - Standard SOAP generation with namespaces and headers
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#call(action, body, headers = {}) ⇒ Object
Main method to make a SOAP request.
-
#initialize(endpoint, namespace) ⇒ SOAP
constructor
Initialize SOAP Client with endpoint, namespace, and optional logger.
Constructor Details
#initialize(endpoint, namespace) ⇒ SOAP
Initialize SOAP Client with endpoint, namespace, and optional logger
12 13 14 15 16 17 |
# File 'lib/parsbank/soap.rb', line 12 def initialize(endpoint, namespace) @endpoint = URI.parse(endpoint) @namespace = namespace @logger = Logger.new(STDOUT) @logger.level = Parsbank.configuration.debug ? Logger::DEBUG : Logger::WARN end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/parsbank/soap.rb', line 9 def endpoint @endpoint end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/parsbank/soap.rb', line 9 def logger @logger end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
9 10 11 |
# File 'lib/parsbank/soap.rb', line 9 def namespace @namespace end |
Instance Method Details
#call(action, body, headers = {}) ⇒ Object
Main method to make a SOAP request
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/parsbank/soap.rb', line 20 def call(action, body, headers = {}) log_request(action, body) xml = build_envelope(action, body.map { |k, v| "<s:#{k}>#{v}</#{k}>" }.join('')) http = Net::HTTP.new(@endpoint.host, @endpoint.port) http.use_ssl = (@endpoint.scheme == 'https') request = Net::HTTP::Post.new(@endpoint.request_uri) request.content_type = 'text/xml; charset=utf-8' request['SOAPAction'] = "#{@namespace}/#{action}" request.body = xml headers.store('Parsbank-RubyGem', Parsbank::VERSION) headers.each { |key, value| request[key] = value } begin response = http.request(request) log_response(response) parse_response(response) rescue Timeout::Error => e handle_error("Request timed out", e) rescue SocketError => e handle_error("Network connection failed", e) rescue Errno::ECONNREFUSED => e handle_error("Connection refused by server", e) rescue StandardError => e handle_error("Unexpected error: #{e.message}", e) end end |