Class: Arbetsformedlingen::API::SOAPRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/arbetsformedlingen/api/soap_request.rb

Overview

API SOAP request

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#localeObject (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

#uriObject (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

#urlObject (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

Parameters:

  • body (String)

Returns:



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