Module: FuelSDK::Soap
Instance Attribute Summary collapse
Attributes included from Targeting
#auth_token, #endpoint
Instance Method Summary
collapse
-
#add_complex_filter_part(filter) ⇒ Object
-
#add_simple_filter_part(filter) ⇒ Object
-
#cache_editable(object_type, properties) ⇒ Object
-
#cache_properties(action, object_type, properties) ⇒ Object
-
#cache_retrievable(object_type, properties) ⇒ Object
-
#cached_properties?(action, object_type) ⇒ Boolean
-
#create_action_message(message_type, object_type, properties, action) ⇒ Object
-
#create_object_type_message(object_type, properties, filter) ⇒ Object
-
#create_objects_message(object_type, object_properties) ⇒ Object
-
#describe(object_type) ⇒ Object
-
#describe_data_extension(dataextension) ⇒ Object
-
#describe_dataextension_message(dataextension) ⇒ Object
-
#describe_object_type_message(object_type) ⇒ Object
-
#editable_properties_cached?(object_type) ⇒ Boolean
-
#format_dataextension_cud_properties(properties) ⇒ Object
-
#format_object_cud_properties(object_type, properties) ⇒ Object
-
#get_all_object_properties(object_type) ⇒ Object
-
#get_dataextension_properties(dataextension) ⇒ Object
-
#get_editable_properties(object_type) ⇒ Object
-
#get_retrievable_properties(object_type) ⇒ Object
-
#header ⇒ Object
-
#is_a_dataextension?(object_type) ⇒ Boolean
-
#normalize_customer_key(filter, object_type) ⇒ Object
-
#normalize_filter(filter, object_type = '') ⇒ Object
-
#normalize_properties_for_cud(object_type, properties) ⇒ Object
-
#normalize_properties_for_retrieve(object_type, properties) ⇒ Object
-
#retrievable_properties_cached?(object_type) ⇒ Boolean
-
#soap_client ⇒ Object
-
#soap_configure(object_type, properties, action) ⇒ Object
-
#soap_delete(object_type, properties) ⇒ Object
-
#soap_describe(object_type) ⇒ Object
-
#soap_get(object_type, properties = nil, filter = nil) ⇒ Object
-
#soap_perform(object_type, properties, action) ⇒ Object
-
#soap_post(object_type, properties) ⇒ Object
-
#soap_put(object_type, properties) ⇒ Object
(also: #soap_patch)
Methods included from Targeting
#determine_stack, #refresh
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
90
91
92
|
# File 'lib/fuelsdk/soap.rb', line 90
def debug
@debug
end
|
#internal_token ⇒ Object
Returns the value of attribute internal_token.
90
91
92
|
# File 'lib/fuelsdk/soap.rb', line 90
def internal_token
@internal_token
end
|
#wsdl ⇒ Object
Returns the value of attribute wsdl.
90
91
92
|
# File 'lib/fuelsdk/soap.rb', line 90
def wsdl
@wsdl
end
|
Instance Method Details
#add_complex_filter_part(filter) ⇒ Object
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/fuelsdk/soap.rb', line 240
def add_complex_filter_part filter
raise 'Missing SimpleFilterParts' if !filter['LeftOperand'] || !filter['RightOperand']
filter['LeftOperand']['@xsi:type'] = 'tns:SimpleFilterPart'
filter['RightOperand']['@xsi:type'] = 'tns:SimpleFilterPart'
filter['@xsi:type'] = 'tns:ComplexFilterPart'
{
'Filter' => filter
}
end
|
#add_simple_filter_part(filter) ⇒ Object
233
234
235
236
237
238
|
# File 'lib/fuelsdk/soap.rb', line 233
def add_simple_filter_part filter
filter['@xsi:type'] = 'tns:SimpleFilterPart'
{
'Filter' => filter
}
end
|
#cache_editable(object_type, properties) ⇒ Object
205
206
207
|
# File 'lib/fuelsdk/soap.rb', line 205
def cache_editable object_type, properties
cache_properties :editable, object_type, properties
end
|
#cache_properties(action, object_type, properties) ⇒ Object
174
175
176
177
|
# File 'lib/fuelsdk/soap.rb', line 174
def cache_properties action, object_type, properties
raise 'Properties should be in cache as a list' unless properties.kind_of? Array
cache[action][object_type] = properties
end
|
#cache_retrievable(object_type, properties) ⇒ Object
187
188
189
|
# File 'lib/fuelsdk/soap.rb', line 187
def cache_retrievable object_type, properties
cache_properties :retrievable, object_type, properties
end
|
#cached_properties?(action, object_type) ⇒ Boolean
179
180
181
|
# File 'lib/fuelsdk/soap.rb', line 179
def cached_properties? action, object_type
cache[action][object_type] rescue nil
end
|
#create_action_message(message_type, object_type, properties, action) ⇒ Object
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/fuelsdk/soap.rb', line 303
def create_action_message message_type, object_type, properties, action
properties = Array.wrap(properties)
properties.each do |property|
property['@xsi:type'] = "tns:#{object_type}"
end
{
'Action' => action,
message_type => {
message_type.singularize => properties,
}
}
end
|
#create_object_type_message(object_type, properties, filter) ⇒ Object
274
275
276
|
# File 'lib/fuelsdk/soap.rb', line 274
def create_object_type_message object_type, properties, filter
{'ObjectType' => object_type, 'Properties' => properties}.merge filter
end
|
#create_objects_message(object_type, object_properties) ⇒ Object
327
328
329
330
331
332
333
334
335
336
337
|
# File 'lib/fuelsdk/soap.rb', line 327
def create_objects_message object_type, object_properties
raise 'Object properties must be a List' unless object_properties.kind_of? Array
raise 'Object properties must be a List of Hashes' unless object_properties.first.kind_of? Hash
object_properties.each do |property|
property['@xsi:type'] = "tns:#{object_type}"
end
{
'Objects' => object_properties,
}
end
|
#describe(object_type) ⇒ Object
155
156
157
158
159
160
161
|
# File 'lib/fuelsdk/soap.rb', line 155
def describe object_type
rsp = soap_describe(object_type)
unless rsp.success?
rsp = describe_data_extension object_type
end
rsp
end
|
#describe_data_extension(dataextension) ⇒ Object
144
145
146
147
148
149
|
# File 'lib/fuelsdk/soap.rb', line 144
def describe_data_extension dataextension
soap_get('DataExtensionField',
'Name',
describe_dataextension_message(dataextension)
)
end
|
#describe_dataextension_message(dataextension) ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/fuelsdk/soap.rb', line 136
def describe_dataextension_message dataextension
{
'Property' => "DataExtension.CustomerKey",
'SimpleOperator' => 'equals',
'Value' => dataextension
}
end
|
#describe_object_type_message(object_type) ⇒ Object
126
127
128
129
130
131
132
133
134
|
# File 'lib/fuelsdk/soap.rb', line 126
def describe_object_type_message object_type
{
'DescribeRequests' => {
'ObjectDefinitionRequest' => {
'ObjectType' => object_type
}
}
}
end
|
#editable_properties_cached?(object_type) ⇒ Boolean
201
202
203
|
# File 'lib/fuelsdk/soap.rb', line 201
def editable_properties_cached? object_type
cached_properties? :editable, object_type
end
|
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
# File 'lib/fuelsdk/soap.rb', line 339
def format_dataextension_cud_properties properties
Array.wrap(properties).each do |p|
formated_attrs = []
p.each do |k, v|
unless k == 'CustomerKey'
p.delete k
attrs = FuelSDK.format_name_value_pairs k => v
formated_attrs.concat attrs
end
end
unless formated_attrs.blank?
p['Properties'] ||= {}
(p['Properties']['Property'] ||= []).concat formated_attrs
end
end
end
|
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
# File 'lib/fuelsdk/soap.rb', line 360
def format_object_cud_properties object_type, properties
type_attrs = get_editable_properties object_type
properties.each do |p|
formated_attrs = []
p.each do |k, v|
if type_attrs.include? k
p.delete k
attrs = FuelSDK.format_name_value_pairs k => v
formated_attrs.concat attrs
end
end
(p['Attributes'] ||= []).concat formated_attrs unless formated_attrs.blank?
end
end
|
#get_all_object_properties(object_type) ⇒ Object
163
164
165
166
167
|
# File 'lib/fuelsdk/soap.rb', line 163
def get_all_object_properties object_type
rsp = soap_describe object_type
raise DescribeError.new(rsp, "Unable to get #{object_type}") unless rsp.success?
rsp
end
|
#get_dataextension_properties(dataextension) ⇒ Object
169
170
171
172
|
# File 'lib/fuelsdk/soap.rb', line 169
def get_dataextension_properties dataextension
describe_dataextension(dataextension)
.results.collect{|f| f[:name]}
end
|
#get_editable_properties(object_type) ⇒ Object
209
210
211
212
213
214
215
216
217
|
# File 'lib/fuelsdk/soap.rb', line 209
def get_editable_properties object_type
if props=editable_properties_cached?(object_type)
props
elsif is_a_dataextension? object_type
[]
else
cache_editable object_type, get_all_object_properties(object_type).editable
end
end
|
#get_retrievable_properties(object_type) ⇒ Object
191
192
193
194
195
196
197
198
199
|
# File 'lib/fuelsdk/soap.rb', line 191
def get_retrievable_properties object_type
if props=retrievable_properties_cached?(object_type)
props
elsif is_a_dataextension? object_type
[]
else
cache_retrievable object_type, get_all_object_properties(object_type).retrievable
end
end
|
94
95
96
97
98
99
100
101
102
|
# File 'lib/fuelsdk/soap.rb', line 94
def
raise 'Require legacy token for soap header' unless internal_token
{
'oAuth' => {
'oAuthToken' => internal_token,
'@xmlns' => 'http://exacttarget.com'
}
}
end
|
#is_a_dataextension?(object_type) ⇒ Boolean
356
357
358
|
# File 'lib/fuelsdk/soap.rb', line 356
def is_a_dataextension? object_type
object_type.start_with? 'DataExtension'
end
|
#normalize_customer_key(filter, object_type) ⇒ Object
251
252
253
254
255
256
257
258
259
|
# File 'lib/fuelsdk/soap.rb', line 251
def normalize_customer_key filter, object_type
filter.tap do |f|
if is_a_dataextension? object_type
if filter['Property'] == 'CustomerKey'
f['Property'] = 'DataExtension.CustomerKey'
end
end
end
end
|
#normalize_filter(filter, object_type = '') ⇒ Object
261
262
263
264
265
266
267
268
269
270
271
272
|
# File 'lib/fuelsdk/soap.rb', line 261
def normalize_filter filter, object_type=''
if filter and filter.kind_of? Hash
normalize_customer_key filter, object_type
if filter.has_key?('LogicalOperator')
add_complex_filter_part filter
else
add_simple_filter_part filter
end
else
{}
end
end
|
#normalize_properties_for_cud(object_type, properties) ⇒ Object
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/fuelsdk/soap.rb', line 375
def normalize_properties_for_cud object_type, properties
properties = Array.wrap(properties)
raise 'Object properties must be a Hash' unless properties.first.kind_of? Hash
if is_a_dataextension? object_type
format_dataextension_cud_properties properties
else
format_object_cud_properties object_type, properties
end
end
|
#normalize_properties_for_retrieve(object_type, properties) ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/fuelsdk/soap.rb', line 219
def normalize_properties_for_retrieve object_type, properties
if properties.nil? or properties.blank?
get_retrievable_properties object_type
elsif properties.kind_of? Hash
properties.keys
elsif properties.kind_of? String
[properties]
elsif properties.kind_of? Symbol
[properties.to_s]
else
properties
end
end
|
#retrievable_properties_cached?(object_type) ⇒ Boolean
183
184
185
|
# File 'lib/fuelsdk/soap.rb', line 183
def retrievable_properties_cached? object_type
cached_properties? :retrievable, object_type
end
|
#soap_client ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/fuelsdk/soap.rb', line 112
def soap_client
self.refresh unless internal_token
@soap_client ||= Savon.client(
soap_header: ,
wsdl: wsdl,
endpoint: endpoint,
wsse_auth: ["*", "*"],
raise_errors: false,
log: debug,
open_timeout:180,
read_timeout: 180
)
end
|
322
323
324
325
|
# File 'lib/fuelsdk/soap.rb', line 322
def soap_configure object_type, properties, action
message = create_action_message 'Configurations', object_type, properties, action
soap_request :configure, message
end
|
#soap_delete(object_type, properties) ⇒ Object
299
300
301
|
# File 'lib/fuelsdk/soap.rb', line 299
def soap_delete object_type, properties
soap_cud :delete, object_type, properties
end
|
#soap_describe(object_type) ⇒ Object
151
152
153
|
# File 'lib/fuelsdk/soap.rb', line 151
def soap_describe object_type
soap_request :describe, describe_object_type_message(object_type)
end
|
#soap_get(object_type, properties = nil, filter = nil) ⇒ Object
278
279
280
281
282
283
284
285
286
287
288
|
# File 'lib/fuelsdk/soap.rb', line 278
def soap_get object_type, properties=nil, filter=nil
properties = normalize_properties_for_retrieve object_type, properties
filter = normalize_filter filter
message = create_object_type_message(object_type, properties, filter)
soap_request :retrieve, 'RetrieveRequest' => message
rescue DescribeError => err
return err.response
end
|
317
318
319
320
|
# File 'lib/fuelsdk/soap.rb', line 317
def soap_perform object_type, properties, action
message = create_action_message 'Definitions', object_type, properties, action
soap_request :perform, message
end
|
#soap_post(object_type, properties) ⇒ Object
290
291
292
|
# File 'lib/fuelsdk/soap.rb', line 290
def soap_post object_type, properties
soap_cud :create, object_type, properties
end
|
#soap_put(object_type, properties) ⇒ Object
Also known as:
soap_patch
294
295
296
|
# File 'lib/fuelsdk/soap.rb', line 294
def soap_put object_type, properties
soap_cud :update, object_type, properties
end
|