Class: Arbetsformedlingen::API::SOAPRequest
- Inherits:
-
Object
- Object
- Arbetsformedlingen::API::SOAPRequest
- Defined in:
- lib/arbetsformedlingen/api/soap_request.rb
Overview
API SOAP request
Instance Attribute Summary collapse
-
#locale ⇒ Object
readonly
SOAP response Response = KeyStruct.new(:code, :body, :xml).
-
#uri ⇒ Object
readonly
SOAP response Response = KeyStruct.new(:code, :body, :xml).
-
#url ⇒ Object
readonly
SOAP response Response = KeyStruct.new(:code, :body, :xml).
Instance Method Summary collapse
-
#initialize(url, locale: nil) ⇒ SOAPRequest
constructor
Initialize SOAP request.
-
#post(body) ⇒ Response
Performs a POST request.
Constructor Details
#initialize(url, locale: nil) ⇒ SOAPRequest
Initialize SOAP request
22 23 24 25 26 27 28 29 30 |
# File 'lib/arbetsformedlingen/api/soap_request.rb', line 22 def initialize(url, locale: nil) unless Object.const_defined?(:Nokogiri) raise(ArgumentError, "unable to require 'nokogiri' gem, please install it") end @url = url @uri = URI(url) @locale = locale end |
Instance Attribute Details
#locale ⇒ Object (readonly)
SOAP response Response = KeyStruct.new(:code, :body, :xml)
19 20 21 |
# File 'lib/arbetsformedlingen/api/soap_request.rb', line 19 def locale @locale end |
#uri ⇒ Object (readonly)
SOAP response Response = KeyStruct.new(:code, :body, :xml)
19 20 21 |
# File 'lib/arbetsformedlingen/api/soap_request.rb', line 19 def uri @uri end |
#url ⇒ Object (readonly)
SOAP response Response = KeyStruct.new(:code, :body, :xml)
19 20 21 |
# File 'lib/arbetsformedlingen/api/soap_request.rb', line 19 def url @url end |
Instance Method Details
#post(body) ⇒ Response
Performs a POST request
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/arbetsformedlingen/api/soap_request.rb', line 35 def post(body) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == 'https' request = Net::HTTP::Post.new(uri) request['Content-Type'] = 'text/xml' request['Accept-Language'] = locale if locale request.body = body response = http.request(request) Response.new(response, uri) end |