Class: Arbetsformedlingen::API::BaseSOAPClient
- Inherits:
-
Object
- Object
- Arbetsformedlingen::API::BaseSOAPClient
- Defined in:
- lib/arbetsformedlingen/api/base_soap_client.rb
Overview
Base client for SOAP clients
Direct Known Subclasses
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#service_url ⇒ Object
readonly
Returns the value of attribute service_url.
Instance Method Summary collapse
-
#client_request(name, args: {}) ⇒ Response
Perform client request.
-
#initialize(url, namespace) ⇒ BaseSOAPClient
constructor
Initialize client.
Constructor Details
#initialize(url, namespace) ⇒ BaseSOAPClient
Initialize client
13 14 15 16 17 |
# File 'lib/arbetsformedlingen/api/base_soap_client.rb', line 13 def initialize(url, namespace) @service_url = url @namespace = namespace @request = SOAPRequest.new(url) end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
10 11 12 |
# File 'lib/arbetsformedlingen/api/base_soap_client.rb', line 10 def namespace @namespace end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
10 11 12 |
# File 'lib/arbetsformedlingen/api/base_soap_client.rb', line 10 def request @request end |
#service_url ⇒ Object (readonly)
Returns the value of attribute service_url.
10 11 12 |
# File 'lib/arbetsformedlingen/api/base_soap_client.rb', line 10 def service_url @service_url end |
Instance Method Details
#client_request(name, args: {}) ⇒ Response
Perform client request
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 |
# File 'lib/arbetsformedlingen/api/base_soap_client.rb', line 23 def client_request(name, args: {}) soap_body = SOAPBuilder.wrap do |body| # rubocop:disable Lint/UnusedBlockArgument # HACK: Work around the XMLBuilder DSL ruby_statements = args.map do |key, value| if value.is_a?(Array) inner_ruby_statements = value.map do |(k, v)| "inode.#{k}('#{v}')" end <<~RUBY_EVAL node.#{key} { |inode| #{inner_ruby_statements.join(';')} } RUBY_EVAL else "node.#{key}('#{value}')" end end ruby_xml_builder_code = <<~RUBY_EVAL body.#{name}(xmlns: namespace) { |node| #{ruby_statements.join(';')} } RUBY_EVAL instance_eval(ruby_xml_builder_code) end request.post(soap_body.to_xml) end |