Skip to content

Commit

Permalink
Changes to the way Savon handles attributes, as per
Browse files Browse the repository at this point in the history
savonrb/savon#518

causes the attribute handling to break. This is a first pass at moving
all the attribute parsing to the new behavior.
  • Loading branch information
johnadamson committed Mar 11, 2017
1 parent 99f2fb0 commit 86ca658
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 64 deletions.
2 changes: 1 addition & 1 deletion lib/marketingcloudsdk/objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def cleanProps
# If the ID property is specified for the destination then it must be a list import
if properties.has_key?('DestinationObject') then
if properties['DestinationObject'].has_key?('ID') then
properties[:attributes!] = { 'DestinationObject' => { 'xsi:type' => 'tns:List'}}
properties['DesintationObject'][:'@xsi:type'] = 'tns:List'
end
end
end
Expand Down
30 changes: 17 additions & 13 deletions lib/marketingcloudsdk/soap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ module Soap
def header
raise 'Require legacy token for soap header' unless internal_token
{
'oAuth' => {'oAuthToken' => internal_token},
:attributes! => { 'oAuth' => { 'xmlns' => 'http://exacttarget.com' }}
'oAuth' => {
:'@xmlns' => 'http://exacttarget.com',
'oAuthToken' => internal_token
}
}
end

Expand Down Expand Up @@ -163,7 +165,7 @@ def soap_perform object_type, action, properties
message = {}
message['Action'] = action
message['Definitions'] = {'Definition' => properties}
message['Definitions'][:attributes!] = { 'Definition' => { 'xsi:type' => ('tns:' + object_type) }}
message['Definitions'][:'@xsi:type'] = 'tns:' + object_type

soap_request :perform, message
end
Expand All @@ -181,7 +183,7 @@ def soap_configure object_type, action, properties
else
message['Configurations'] = {'Configuration' => properties}
end
message['Configurations'][:attributes!] = { 'Configuration' => { 'xsi:type' => ('tns:' + object_type) }}
message['Configurations'][:'@xsi:type'] = 'tns:' + object_type

soap_request :configure, message
end
Expand All @@ -205,13 +207,12 @@ def soap_get object_type, properties=nil, filter=nil

if filter and filter.kind_of? Hash
message['Filter'] = filter
message[:attributes!] = { 'Filter' => { 'xsi:type' => 'tns:SimpleFilterPart' } }
message['Filter'][:'@xsi:type'] = 'tns:SimpleFilterPart'

if filter.has_key?('LogicalOperator')
message[:attributes!] = { 'Filter' => { 'xsi:type' => 'tns:ComplexFilterPart' }}
message['Filter'][:attributes!] = {
'LeftOperand' => { 'xsi:type' => 'tns:SimpleFilterPart' },
'RightOperand' => { 'xsi:type' => 'tns:SimpleFilterPart' }}
message['Filter'][:'@xsi:type'] = 'tns:ComplexFilterPart'
message['Filter']['LeftOperand']['@xsi:type'] = 'tns:SimpleFilterPart'
message['Filter']['RightOperand']['@xsi:type'] = 'tns:SimpleFilterPart'
end
end
message = {'RetrieveRequest' => message}
Expand Down Expand Up @@ -257,10 +258,13 @@ def soap_cud action, object_type, properties, upsert=nil
# end
#

message = {
'Objects' => properties,
:attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + object_type) } }
}
message = {'Objects' => properties}

if properties.is_a? Array
properties.each { |p| p[:'@xsi:type'] = ('tns:' + object_type) }
else
message['Objects'][:'@xsi:type'] = 'tns:' + object_type
end

if upsert
message['Options'] = {"SaveOptions" => {"SaveOption" => {"PropertyName"=> "*", "SaveAction" => "UpdateAdd"}}}
Expand Down
57 changes: 25 additions & 32 deletions lib/new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ def initialize(getWSDL = true, debug = false, params = nil)

self.determineStack

@authObj = {'oAuth' => {'oAuthToken' => @internalAuthToken}}
@authObj[:attributes!] = { 'oAuth' => { 'xmlns' => 'http://exacttarget.com' }}
@authObj = {'oAuth' => {
:@xmlns => 'http://exacttarget.com',
'oAuthToken' => @internalAuthToken
}}

myWSDL = File.read(@path + '/ExactTargetWSDL.xml')
@auth = Savon.client(
Expand Down Expand Up @@ -257,8 +259,10 @@ def refreshToken(force = nil)
self.determineStack
end

@authObj = {'oAuth' => {'oAuthToken' => @internalAuthToken}}
@authObj[:attributes!] = { 'oAuth' => { 'xmlns' => 'http://exacttarget.com' }}
@authObj = {'oAuth' => {
:@xmlns => 'http://exacttarget.com',
'oAuthToken' => @internalAuthToken
}}

myWSDL = File.read(@path + '/ExactTargetWSDL.xml')
@auth = Savon.client(
Expand Down Expand Up @@ -362,24 +366,20 @@ def initialize(authStub = nil, objType = nil)
end

class ET_Post < ET_Constructor
def initialize(authStub, objType, props = nil)
def initialize(authStub, objType, props = {})
@results = []

begin
authStub.refreshToken
if props.is_a? Array then
obj = {
'Objects' => [],
:attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + objType) } }
}
obj = { 'Objects' => [] }
props.each{ |p|
p[':@xsi:type'] = 'tns:' + objType
obj['Objects'] << p
}
else
obj = {
'Objects' => props,
:attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + objType) } }
}
obj = { 'Objects' => props }
obj['Objects']['@xsi:type'] = 'tns:' + objType
end

response = authStub.auth.call(:create, :message => obj)
Expand Down Expand Up @@ -410,18 +410,14 @@ def initialize(authStub, objType, props = nil)
begin
authStub.refreshToken
if props.is_a? Array then
obj = {
'Objects' => [],
:attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + objType) } }
}
obj = { 'Objects' => [] }
props.each{ |p|
p[':@xsi:type'] = 'tns:' + objType
obj['Objects'] << p
}
else
obj = {
'Objects' => props,
:attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + objType) } }
}
obj = { 'Objects' => props }
obj['Objects']['@xsi:type'] = 'tns:' + objType
end

response = authStub.auth.call(:delete, :message => obj)
Expand All @@ -447,18 +443,14 @@ def initialize(authStub, objType, props = nil)
begin
authStub.refreshToken
if props.is_a? Array then
obj = {
'Objects' => [],
:attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + objType) } }
}
obj = { 'Objects' => [] }
props.each{ |p|
p[':@xsi:type'] = 'tns:' + objType
obj['Objects'] << p
}
else
obj = {
'Objects' => props,
:attributes! => { 'Objects' => { 'xsi:type' => ('tns:' + objType) } }
}
obj = { 'Objects' => props }
obj['Objects']['@xsi:type'] = 'tns:' + objType
end

response = authStub.auth.call(:update, :message => obj)
Expand Down Expand Up @@ -537,11 +529,12 @@ def initialize(authStub, objType, props = nil, filter = nil)
if filter then
if filter.has_key?('LogicalOperator') then
obj['Filter'] = filter
obj[:attributes!] = { 'Filter' => { 'xsi:type' => 'tns:ComplexFilterPart' }}
obj['Filter'][:attributes!] = { 'LeftOperand' => { 'xsi:type' => 'tns:SimpleFilterPart' }, 'RightOperand' => { 'xsi:type' => 'tns:SimpleFilterPart' }}
obj['Filter'][:'@xsi:type'] = 'tns:ComplexFilterPart'
obj['Filter']['LeftOperand'][:'@xsi:type'] = 'tns:SimpleFilterPart'
obj['Filter']['RightOperand'][:'@xsi:type'] = 'tns:SimpleFilterPart'
else
obj['Filter'] = filter
obj[:attributes!] = { 'Filter' => { 'xsi:type' => 'tns:SimpleFilterPart' } }
obj['Filter'][:'@xsi:type'] = 'tns:SimpleFilterPart'
end
end

Expand Down
2 changes: 1 addition & 1 deletion marketingcloudsdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "guard",'~> 1.1'
spec.add_development_dependency "guard-rspec",'~> 2.0'

spec.add_dependency "savon", "2.2.0"
spec.add_dependency "savon", "2.11.0"
spec.add_dependency "json", "~>1.8",">= 1.8.1"
spec.add_dependency "jwt", "~>1.0",">= 1.0.0"
end
39 changes: 22 additions & 17 deletions spec/soap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
client.internal_token = 'innerspace'
expect(client.header).to eq(
{
'oAuth' => { 'oAuthToken' => 'innerspace' },
:attributes! => {
'oAuth' => { 'xmlns' => 'http://exacttarget.com' }
'oAuth' => {
:@xmlns => 'http://exacttarget.com',
'oAuthToken' => 'innerspace'
}
}
)
Expand Down Expand Up @@ -76,27 +76,28 @@
it 'formats soap :create message for single object' do
expect(subject.soap_post 'Subscriber', 'EmailAddress' => 'test@fuelsdk.com' ).to eq([:create,
{
'Objects' => [{'EmailAddress' => 'test@fuelsdk.com'}],
:attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
'Objects' => [{:'@xsi:type' => 'tns:Subscriber', 'EmailAddress' => 'test@fuelsdk.com'}]
}])
end

it 'formats soap :create message for multiple objects' do
expect(subject.soap_post 'Subscriber', [{'EmailAddress' => 'first@fuelsdk.com'}, {'EmailAddress' => 'second@fuelsdk.com'}] ).to eq([:create,
{
'Objects' => [{'EmailAddress' => 'first@fuelsdk.com'}, {'EmailAddress' => 'second@fuelsdk.com'}],
:attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
'Objects' => [
{:'@xsi:type' => 'tns:Subscriber', 'EmailAddress' => 'first@fuelsdk.com'},
{:'@xsi:type' => 'tns:Subscriber', 'EmailAddress' => 'second@fuelsdk.com'}
],
}])
end

it 'formats soap :create message for single object with an attribute' do
expect(subject.soap_post 'Subscriber', {'EmailAddress' => 'test@fuelsdk.com', 'Attributes'=> [{'Name'=>'First Name', 'Value'=>'first'}]}).to eq([:create,
{
'Objects' => [{
:'@xsi:type' => 'tns:Subscriber',
'EmailAddress' => 'test@fuelsdk.com',
'Attributes' => [{'Name' => 'First Name', 'Value' => 'first'}],
}],
:attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
}]
}])
end

Expand All @@ -110,8 +111,8 @@
{'Name' => 'First Name', 'Value' => 'first'},
{'Name' => 'Last Name', 'Value' => 'subscriber'},
],
}],
:attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
:'@xsi:type' => 'tns:Subscriber'
}]
}])
end

Expand All @@ -120,19 +121,23 @@
{'EmailAddress' => 'second@fuelsdk.com', 'Attributes'=> [{'Name'=>'First Name', 'Value'=>'second'}, {'Name'=>'Last Name', 'Value'=>'subscriber'}]}]).to eq([:create,
{
'Objects' => [
{'EmailAddress' => 'first@fuelsdk.com',
{
'EmailAddress' => 'first@fuelsdk.com',
'Attributes' => [
{'Name' => 'First Name', 'Value' => 'first'},
{'Name' => 'Last Name', 'Value' => 'subscriber'},
]
],
:'@xsi:type' => 'tns:Subscriber'
},
{'EmailAddress' => 'second@fuelsdk.com',
{
'EmailAddress' => 'second@fuelsdk.com',
'Attributes' => [
{'Name' => 'First Name', 'Value' => 'second'},
{'Name' => 'Last Name', 'Value' => 'subscriber'},
]
}],
:attributes! => {'Objects' => {'xsi:type' => ('tns:Subscriber')}}
],
:'@xsi:type' => 'tns:Subscriber'
}
]
}])
end
end
Expand Down

0 comments on commit 86ca658

Please sign in to comment.