Skip to content

Commit

Permalink
added local :attributes option - #361
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed Jan 10, 2013
1 parent a05469a commit 648325f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

This also fixes [rubiii/savon#2](https://github.com/rubiii/savon/issues/2) logging on Windows.

* Feature: [#361](https://github.com/savonrb/savon/issues/361) added the local `:attributes`
option to allow adding XML attributes to the SOAP message tag.

## 2.0.2 (2012-12-20)

* Fix: [#297](https://github.com/savonrb/savon/issues/297#issuecomment-11536517) added the global
Expand Down
11 changes: 9 additions & 2 deletions lib/savon/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ def header
end

def namespaced_message_tag
return [namespace_identifier, message_tag] unless @used_namespaces[[@operation_name.to_s]]
[@used_namespaces[[@operation_name.to_s]], message_tag]
if @used_namespaces[[@operation_name.to_s]]
[@used_namespaces[[@operation_name.to_s]], message_tag, message_attributes]
else
[namespace_identifier, message_tag, message_attributes]
end
end

def message_tag
Expand All @@ -99,6 +102,10 @@ def message_tag
@message_tag = message_tag.to_sym
end

def message_attributes
@locals[:attributes] || {}
end

def message
element_form_default = @globals[:element_form_default] || @wsdl.element_form_default
# TODO: clean this up! [dh, 2012-12-17]
Expand Down
5 changes: 5 additions & 0 deletions lib/savon/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ def message_tag(message_tag)
@options[:message_tag] = message_tag
end

# Attributes for the SOAP message tag.
def attributes(attributes)
@options[:attributes] = attributes
end

# Value of the SOAPAction HTTP header.
def soap_action(soap_action)
@options[:soap_action] = soap_action
Expand Down
7 changes: 7 additions & 0 deletions spec/savon/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@
expect(response.http.body).to include("<symbol>AAPL</symbol>")
end

it "accepts arguments for the message tag" do
client = new_client(:endpoint => @server.url(:repeat))
response = client.call(:authenticate, :attributes => { "ID" => "ABC321"})

expect(response.http.body).to include('<tns:authenticate ID="ABC321">')
end

it "raises when the operation name is not a symbol" do
expect { new_client.call("not a symbol") }.to raise_error(
ArgumentError,
Expand Down
9 changes: 9 additions & 0 deletions spec/savon/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,15 @@ def mock_stdout
end
end

context "request: attributes" do
it "when set, adds the attributes to the message tag" do
client = new_client(:endpoint => @server.url(:repeat))
response = client.call(:authenticate, :attributes => { "Token" => "secret"})

expect(response.http.body).to include('<tns:authenticate Token="secret">')
end
end

context "request: soap_action" do
it "without it, Savon tries to get the SOAPAction from the WSDL document and falls back to Gyoku" do
client = new_client(:endpoint => @server.url(:inspect_request))
Expand Down

0 comments on commit 648325f

Please sign in to comment.