Class: Stellae::Request
- Inherits:
-
Object
- Object
- Stellae::Request
- Defined in:
- lib/stellae/request.rb
Constant Summary collapse
- SCHEMA =
{ soap_envelop: "http://www.w3.org/2003/05/soap-envelope", addressing: "http://www.w3.org/2005/08/addressing", datacontract: "http://schemas.datacontract.org/2004/07/", instance: "http://www.w3.org/2001/XMLSchema-instance" }
Instance Method Summary collapse
- #build_header(xml, action) ⇒ Object
- #build_user(xml) ⇒ Object
- #construct_xml(type) ⇒ Object
-
#initialize(client) ⇒ Request
constructor
A new instance of Request.
- #soap_field(xml, field, value = nil, prefix = "a") ⇒ Object
- #soap_value(value) ⇒ Object
Constructor Details
#initialize(client) ⇒ Request
Returns a new instance of Request.
13 14 15 |
# File 'lib/stellae/request.rb', line 13 def initialize(client) @client = client end |
Instance Method Details
#build_header(xml, action) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/stellae/request.rb', line 32 def build_header(xml, action) xml.s :Header do xml.a :Action, "SII/ISIIService/#{action}", :"s:mustUnderstand" => "1" xml.a :MessageID, "urn:uuid:56b55a70-8bbc-471d-94bb-9ca060bcf99f" xml.a :ReplyTo do xml.a :Address, "http://www.w3.org/2005/08/addressing/anonymous" end xml.a :To, @client.request_uri.split('?').first, :"s:mustUnderstand" => "1" end end |
#build_user(xml) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/stellae/request.rb', line 43 def build_user(xml) xml.user :"xmlns:a" => SCHEMA[:datacontract], :"xmlns:i" => SCHEMA[:instance] do soap_field xml, :user_name, @client.username soap_field xml, :user_password, @client.password end end |
#construct_xml(type) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stellae/request.rb', line 17 def construct_xml(type) @client.type = type xml = Builder::XmlMarkup.new xml.s :Envelope, :"xmlns:s" => SCHEMA[:soap_envelop], :"xmlns:a" => SCHEMA[:addressing] do build_header(xml, type) xml.s :Body do xml.tag! type, :"xmlns" => "SII" do build_user xml yield(xml) end end end xml.target! end |
#soap_field(xml, field, value = nil, prefix = "a") ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/stellae/request.rb', line 50 def soap_field(xml, field, value = nil, prefix = "a") if block_given? xml.tag! prefix, field.to_sym do yield(xml) end else xml.tag! prefix, field.to_sym, soap_value(value) end end |
#soap_value(value) ⇒ Object
60 61 62 |
# File 'lib/stellae/request.rb', line 60 def soap_value(value) value.presence || { :"i:nil" => "true" } end |