fuelsdk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ sample.rb
20
+ ExactTargetWSDL.xml
21
+ config.yaml
22
+ /objsamples/config.yaml
23
+ /objsamples/AllTest.bat
24
+ .DS_STORE
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+ guard 'rspec' do
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ end
8
+
data/README.md ADDED
@@ -0,0 +1,117 @@
1
+ FuelSDK-Ruby
2
+ ============
3
+
4
+ ExactTarget Fuel SDK for Ruby
5
+
6
+ ## Overview ##
7
+ The Fuel SDK for Ruby provides easy access to ExactTarget's Fuel API Family services, including a collection of REST APIs and a SOAP API. These APIs provide access to ExactTarget functionality via common collection types such as array/hash.
8
+
9
+ ## Requirements ##
10
+ Ruby Version 1.9.3
11
+
12
+ Gems:
13
+
14
+ - [savon (2.x)](http://rubygems.org/gems/savon)
15
+ - [json (1.7.x)](http://rubygems.org/gems/json)
16
+ - [jwt (0.1.6)](https://rubygems.org/gems/jwt)
17
+
18
+
19
+ ## Getting Started ##
20
+ After downloading the project, rename the config.yaml.template file to config.yaml.
21
+
22
+ Edit config.yaml so you can input the ClientID and Client Secret values provided when you registered your application. If you are building a HubExchange application for the Interactive Marketing Hub then, you must also provide the Application Signature (appsignature). Only change the value for the defaultwsdl configuration item if instructed by ExactTarget.
23
+
24
+ If you have not registered your application or you need to lookup your Application Key or Application Signature values, please go to App Center at [Code@: ExactTarget's Developer Community](http://code.exacttarget.com/appcenter "Code@ App Center").
25
+
26
+ ## Example Request ##
27
+ All ExactTarget objects exposed through the Fuel SDK begin with be prefixed with "ET\_". Start by working with the ET_List object:
28
+
29
+ Add a require statement to reference the Fuel SDK's functionality:
30
+ > require 'fuelsdk'
31
+
32
+ Next, create an instance of the ET_Client class:
33
+ > myClient = FuelSDK::ET_Client.new
34
+
35
+ Create an instance of the object type we want to work with:
36
+ > list = FuelSDK::ET_List.new
37
+
38
+ Associate the ET_Client to the object using the authStub property:
39
+ > list.authStub = myClient
40
+
41
+ Utilize one of the ET_List methods:
42
+ > response = list.get
43
+
44
+ Print out the results for viewing
45
+ > p response
46
+
47
+ **Example Output:**
48
+
49
+ <pre>
50
+ #&lt;ET_Get:0x355bc48
51
+ @results=[
52
+ {
53
+ :client=>{
54
+ :id=>"1000001",
55
+ :partner_client_key=>nil
56
+ },
57
+ :partner_key=>nil,
58
+ :created_date=>#&lt;DateTime: 2009-06-12T14:42:06+00:00 ((2454995j,52926s,100000000n),+0s,2299161j)&gt;,
59
+ :modified_date=>#&lt;DateTime: 2011-08-17T14:50:30+00:00 ((2455791j,53430s,697000000n),+0s,2299161j)&gt;,
60
+ :id=>"1718921",
61
+ :object_id=>"f41c7d1b-8957-de11-92ee-001cc494ae9e",
62
+ :customer_key=>"All Subscribers - 578623",
63
+ :list_name=>"All Subscribers",
64
+ :category=>"578623",
65
+ :type=>"Private",
66
+ :description=>"Contains all subscribers",
67
+ :list_classification=>"ExactTargetList",
68
+ :"@xsi:type"=>"List"}
69
+ ],
70
+ @code=200,
71
+ @status=true,
72
+ @moreResults=false,
73
+ @request_id="41f0f293-954f-4ac7-8e7a-0a5756022218"
74
+ >
75
+ </pre>
76
+
77
+ ## ET\_Client Class ##
78
+
79
+ The ET\_Client class takes care of many of the required steps when accessing ExactTarget's API, including retrieving appropriate access tokens, handling token state for managing refresh, and determining the appropriate endpoints for API requests. In order to leverage the advantages this class provides, use a single instance of this class for an entire session. Do not instantiate a new ET_Client object for each request made.
80
+
81
+ ## Responses ##
82
+ All methods on Fuel SDK objects return a generic object that follows the same structure, regardless of the type of call. This object contains a common set of properties used to display details about the request.
83
+
84
+ - status: Boolean value that indicates if the call was successful
85
+ - code: HTTP Error Code (will always be 200 for SOAP requests)
86
+ - message: Text values containing more details in the event of an error
87
+ - results: Collection containing the details unique to the method called.
88
+
89
+ Get Methods also return an addition value to indicate if more information is available (that information can be retrieved using the getMoreResults method):
90
+
91
+ - moreResults - Boolean value that indicates on Get requests if more data is available.
92
+
93
+
94
+ ## Samples ##
95
+ Find more sample files that illustrate using all of the available functions for ExactTarget objects exposed through the API in the objsamples directory.
96
+
97
+ Sample List:
98
+
99
+ - [BounceEvent](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-bounceevent.rb)
100
+ - [Campaign](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-campaign.rb)
101
+ - [ClickEvent](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-clickevent.rb)
102
+ - [ContentArea](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-contentarea.rb)
103
+ - [DataExtension](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-dataextension.rb)
104
+ - [Email](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-email.rb)
105
+ - [List](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-list.rb)
106
+ - [List > Subscriber](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-list.subscriber.rb)
107
+ - [OpenEvent](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-openevent.rb)
108
+ - [SentEvent](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-sentevent.rb)
109
+ - [Subscriber](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-subscriber.rb)
110
+ - [TriggeredSend](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-triggeredsend.rb)
111
+ - [UnsubEvent](https://github.com/ExactTarget/FuelSDK-Ruby/blob/master/objsamples/sample-unsubevent.rb)
112
+
113
+
114
+
115
+
116
+
117
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/fuelsdk.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fuelsdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fuelsdk"
8
+ spec.version = FuelSDK::VERSION
9
+ spec.authors = ["MichaelAllenClark", "barberj"]
10
+ spec.email = []
11
+ spec.description = %q{Fuel SDK for Ruby}
12
+ spec.summary = %q{Fuel SDK for Ruby}
13
+ spec.homepage = "https://github.com/ExactTarget/FuelSDK-Ruby"
14
+ spec.license = ""
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(samples|test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard"
25
+ spec.add_development_dependency "guard-rspec"
26
+
27
+ spec.add_dependency "savon", "~> 2.0"
28
+ spec.add_dependency "json", "~> 1.7.0"
29
+ spec.add_dependency "jwt", "~> 0.1.6"
30
+ end
data/lib/fuelsdk.rb ADDED
@@ -0,0 +1,572 @@
1
+ require "fuelsdk/version"
2
+
3
+ require 'rubygems'
4
+ require 'date'
5
+ require 'jwt'
6
+
7
+ module FuelSDK
8
+ autoload :HTTPRequest, 'fuelsdk/http_request'
9
+ autoload :Targeting, 'fuelsdk/targeting'
10
+ autoload :Soap, 'fuelsdk/soap'
11
+ autoload :Rest, 'fuelsdk/rest'
12
+ require 'fuelsdk/client'
13
+ require 'fuelsdk/objects'
14
+ end
15
+
16
+ =begin
17
+ class ET_Constructor
18
+ attr_accessor :status, :code, :message, :results, :request_id, :moreResults
19
+
20
+ def initialize(response = nil, rest = false)
21
+ @results = []
22
+ #if !response.nil? && !rest then
23
+ # @@body = response.body
24
+
25
+ # if ((!response.soap_fault?) or (!response.http_error?)) then
26
+ # @code = response.http.code
27
+ # @status = true
28
+ # elsif (response.soap_fault?) then
29
+ # @code = response.http.code
30
+ # @message = @@body[:fault][:faultstring]
31
+ # @status = false
32
+ # elsif (response.http_error?) then
33
+ # @code = response.http.code
34
+ # @status = false
35
+ # end
36
+ #elsif
37
+ @code = response.code
38
+ @status = true
39
+ if @code != "200" then
40
+ @status = false
41
+ end
42
+
43
+ begin
44
+ @results = JSON.parse(response.body)
45
+ rescue
46
+ @message = response.body
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+
53
+ class ET_BaseObject
54
+ attr_accessor :authStub, :props
55
+ attr_reader :obj, :lastRequestID, :endpoint
56
+
57
+ def initialize
58
+ @authStub = nil
59
+ @props = nil
60
+ @filter = nil
61
+ @lastRequestID = nil
62
+ @endpoint = nil
63
+ end
64
+ end
65
+
66
+ class ET_GetSupportRest < ET_BaseObject
67
+ attr_reader :urlProps, :urlPropsRequired, :lastPageNumber
68
+
69
+ def get(props = nil)
70
+ if props and props.is_a? Hash then
71
+ @props = props
72
+ end
73
+
74
+ completeURL = @endpoint
75
+ additionalQS = {}
76
+
77
+ if @props and @props.is_a? Hash then
78
+ @props.each do |k,v|
79
+ if @urlProps.include?(k) then
80
+ completeURL.sub!("{#{k}}", v)
81
+ else
82
+ additionalQS[k] = v
83
+ end
84
+ end
85
+ end
86
+
87
+ @urlPropsRequired.each do |value|
88
+ if !@props || !@props.has_key?(value) then
89
+ raise "Unable to process request due to missing required prop: #{value}"
90
+ end
91
+ end
92
+
93
+ @urlProps.each do |value|
94
+ completeURL.sub!("/{#{value}}", "")
95
+ end
96
+
97
+ obj = ET_GetRest.new(@authStub, completeURL,additionalQS)
98
+
99
+ if obj.results.has_key?('page') then
100
+ @lastPageNumber = obj.results['page']
101
+ pageSize = obj.results['pageSize']
102
+ if obj.results.has_key?('count') then
103
+ count = obj.results['count']
104
+ elsif obj.results.has_key?('totalCount') then
105
+ count = obj.results['totalCount']
106
+ end
107
+
108
+ if !count.nil? && count > (@lastPageNumber * pageSize) then
109
+ obj.moreResults = true
110
+ end
111
+ end
112
+ return obj
113
+ end
114
+
115
+ def getMoreResults()
116
+ if props and props.is_a? Hash then
117
+ @props = props
118
+ end
119
+
120
+ originalPageValue = "1"
121
+ removePageFromProps = false
122
+
123
+ if !@props.nil? && @props.has_key?('$page') then
124
+ originalPageValue = @props['page']
125
+ else
126
+ removePageFromProps = true
127
+ end
128
+
129
+ if @props.nil?
130
+ @props = {}
131
+ end
132
+
133
+ @props['$page'] = @lastPageNumber + 1
134
+
135
+ obj = self.get
136
+
137
+ if removePageFromProps then
138
+ @props.delete('$page')
139
+ else
140
+ @props['$page'] = originalPageValue
141
+ end
142
+
143
+ return obj
144
+ end
145
+ end
146
+
147
+ class ET_CUDSupportRest < ET_GetSupportRest
148
+
149
+ def post()
150
+ completeURL = @endpoint
151
+
152
+ if @props and @props.is_a? Hash then
153
+ @props.each do |k,v|
154
+ if @urlProps.include?(k) then
155
+ completeURL.sub!("{#{k}}", v)
156
+ end
157
+ end
158
+ end
159
+
160
+ @urlPropsRequired.each do |value|
161
+ if !@props || !@props.has_key?(value) then
162
+ raise "Unable to process request due to missing required prop: #{value}"
163
+ end
164
+ end
165
+
166
+ # Clean Optional Parameters from Endpoint URL first
167
+ @urlProps.each do |value|
168
+ completeURL.sub!("/{#{value}}", "")
169
+ end
170
+
171
+ ET_PostRest.new(@authStub, completeURL, @props)
172
+ end
173
+
174
+ def patch()
175
+ completeURL = @endpoint
176
+ # All URL Props are required when doing Patch
177
+ @urlProps.each do |value|
178
+ if !@props || !@props.has_key?(value) then
179
+ raise "Unable to process request due to missing required prop: #{value}"
180
+ end
181
+ end
182
+
183
+ if @props and @props.is_a? Hash then
184
+ @props.each do |k,v|
185
+ if @urlProps.include?(k) then
186
+ completeURL.sub!("{#{k}}", v)
187
+ end
188
+ end
189
+ end
190
+
191
+ obj = ET_PatchRest.new(@authStub, completeURL, @props)
192
+ end
193
+
194
+ def delete()
195
+ completeURL = @endpoint
196
+ # All URL Props are required when doing Patch
197
+ @urlProps.each do |value|
198
+ if !@props || !@props.has_key?(value) then
199
+ raise "Unable to process request due to missing required prop: #{value}"
200
+ end
201
+ end
202
+
203
+ if @props and @props.is_a? Hash then
204
+ @props.each do |k,v|
205
+ if @urlProps.include?(k) then
206
+ completeURL.sub!("{#{k}}", v)
207
+ end
208
+ end
209
+ end
210
+
211
+ ET_DeleteRest.new(@authStub, completeURL)
212
+ end
213
+
214
+ end
215
+
216
+
217
+ class ET_GetRest < ET_Constructor
218
+ def initialize(authStub, endpoint, qs = nil)
219
+ authStub.refreshToken
220
+
221
+ if qs then
222
+ qs['access_token'] = authStub.authToken
223
+ else
224
+ qs = {"access_token" => authStub.authToken}
225
+ end
226
+
227
+ uri = URI.parse(endpoint)
228
+ uri.query = URI.encode_www_form(qs)
229
+ http = Net::HTTP.new(uri.host, uri.port)
230
+ http.use_ssl = true
231
+ request = Net::HTTP::Get.new(uri.request_uri)
232
+ requestResponse = http.request(request)
233
+
234
+ @moreResults = false
235
+
236
+ obj = super(requestResponse, true)
237
+ return obj
238
+ end
239
+ end
240
+
241
+
242
+ class ET_ContinueRest < ET_Constructor
243
+ def initialize(authStub, endpoint, qs = nil)
244
+ authStub.refreshToken
245
+
246
+ if qs then
247
+ qs['access_token'] = authStub.authToken
248
+ else
249
+ qs = {"access_token" => authStub.authToken}
250
+ end
251
+
252
+ uri = URI.parse(endpoint)
253
+ uri.query = URI.encode_www_form(qs)
254
+ http = Net::HTTP.new(uri.host, uri.port)
255
+ http.use_ssl = true
256
+ request = Net::HTTP::Get.new(uri.request_uri)
257
+ requestResponse = http.request(request)
258
+
259
+ @moreResults = false
260
+
261
+ super(requestResponse, true)
262
+ end
263
+ end
264
+
265
+
266
+ class ET_PostRest < ET_Constructor
267
+ def initialize(authStub, endpoint, payload)
268
+ authStub.refreshToken
269
+
270
+ qs = {"access_token" => authStub.authToken}
271
+ uri = URI.parse(endpoint)
272
+ uri.query = URI.encode_www_form(qs)
273
+ http = Net::HTTP.new(uri.host, uri.port)
274
+ http.use_ssl = true
275
+ request = Net::HTTP::Post.new(uri.request_uri)
276
+ request.body = payload.to_json
277
+ request.add_field "Content-Type", "application/json"
278
+ requestResponse = http.request(request)
279
+
280
+ super(requestResponse, true)
281
+
282
+ end
283
+ end
284
+
285
+ class ET_PatchRest < ET_Constructor
286
+ def initialize(authStub, endpoint, payload)
287
+ authStub.refreshToken
288
+
289
+ qs = {"access_token" => authStub.authToken}
290
+ uri = URI.parse(endpoint)
291
+ uri.query = URI.encode_www_form(qs)
292
+ http = Net::HTTP.new(uri.host, uri.port)
293
+ http.use_ssl = true
294
+ request = Net::HTTP::Patch.new(uri.request_uri)
295
+ request.body = payload.to_json
296
+ request.add_field "Content-Type", "application/json"
297
+ requestResponse = http.request(request)
298
+ super(requestResponse, true)
299
+
300
+ end
301
+ end
302
+
303
+ class ET_DeleteRest < ET_Constructor
304
+ def initialize(authStub, endpoint)
305
+ authStub.refreshToken
306
+
307
+ qs = {"access_token" => authStub.authToken}
308
+
309
+ uri = URI.parse(endpoint)
310
+ uri.query = URI.encode_www_form(qs)
311
+ http = Net::HTTP.new(uri.host, uri.port)
312
+ http.use_ssl = true
313
+ request = Net::HTTP::Delete.new(uri.request_uri)
314
+ requestResponse = http.request(request)
315
+ super(requestResponse, true)
316
+
317
+ end
318
+ end
319
+
320
+ class ET_Campaign < ET_CUDSupportRest
321
+ def initialize
322
+ super
323
+ @endpoint = 'https://www.exacttargetapis.com/hub/v1/campaigns/{id}'
324
+ @urlProps = ["id"]
325
+ @urlPropsRequired = []
326
+ end
327
+
328
+ class Asset < ET_CUDSupportRest
329
+ def initialize
330
+ super
331
+ @endpoint = 'https://www.exacttargetapis.com/hub/v1/campaigns/{id}/assets/{assetId}'
332
+ @urlProps = ["id", "assetId"]
333
+ @urlPropsRequired = ["id"]
334
+ end
335
+ end
336
+ end
337
+
338
+ class ET_DataExtension < ET_CUDSupport
339
+ attr_accessor :columns
340
+
341
+ def initialize
342
+ super
343
+ @obj = 'DataExtension'
344
+ end
345
+
346
+ def post
347
+ originalProps = @props
348
+
349
+ if @props.is_a? Array then
350
+ multiDE = []
351
+ @props.each { |currentDE|
352
+ currentDE['Fields'] = {}
353
+ currentDE['Fields']['Field'] = []
354
+ currentDE['columns'].each { |key|
355
+ currentDE['Fields']['Field'].push(key)
356
+ }
357
+ currentDE.delete('columns')
358
+ multiDE.push(currentDE.dup)
359
+ }
360
+
361
+ @props = multiDE
362
+ else
363
+ @props['Fields'] = {}
364
+ @props['Fields']['Field'] = []
365
+
366
+ @columns.each { |key|
367
+ @props['Fields']['Field'].push(key)
368
+ }
369
+ end
370
+
371
+ obj = super
372
+ @props = originalProps
373
+ return obj
374
+ end
375
+
376
+ def patch
377
+ @props['Fields'] = {}
378
+ @props['Fields']['Field'] = []
379
+ @columns.each { |key|
380
+ @props['Fields']['Field'].push(key)
381
+ }
382
+ obj = super
383
+ @props.delete("Fields")
384
+ return obj
385
+ end
386
+
387
+ class Column < ET_GetSupport
388
+ def initialize
389
+ super
390
+ @obj = 'DataExtensionField'
391
+ end
392
+
393
+ def get
394
+
395
+ if props and props.is_a? Array then
396
+ @props = props
397
+ end
398
+
399
+ if @props and @props.is_a? Hash then
400
+ @props = @props.keys
401
+ end
402
+
403
+ if filter and filter.is_a? Hash then
404
+ @filter = filter
405
+ end
406
+
407
+ fixCustomerKey = false
408
+ if filter and filter.is_a? Hash then
409
+ @filter = filter
410
+ if @filter.has_key?("Property") && @filter["Property"] == "CustomerKey" then
411
+ @filter["Property"] = "DataExtension.CustomerKey"
412
+ fixCustomerKey = true
413
+ end
414
+ end
415
+
416
+ obj = ET_Get.new(@authStub, @obj, @props, @filter)
417
+ @lastRequestID = obj.request_id
418
+
419
+ if fixCustomerKey then
420
+ @filter["Property"] = "CustomerKey"
421
+ end
422
+
423
+ return obj
424
+ end
425
+ end
426
+
427
+ class Row < ET_CUDSupport
428
+ attr_accessor :Name, :CustomerKey
429
+
430
+ def initialize()
431
+ super
432
+ @obj = "DataExtensionObject"
433
+ end
434
+
435
+ def get
436
+ getName
437
+ if props and props.is_a? Array then
438
+ @props = props
439
+ end
440
+
441
+ if @props and @props.is_a? Hash then
442
+ @props = @props.keys
443
+ end
444
+
445
+ if filter and filter.is_a? Hash then
446
+ @filter = filter
447
+ end
448
+
449
+ obj = ET_Get.new(@authStub, "DataExtensionObject[#{@Name}]", @props, @filter)
450
+ @lastRequestID = obj.request_id
451
+
452
+ return obj
453
+ end
454
+
455
+ def post
456
+ getCustomerKey
457
+ originalProps = @props
458
+ ## FIX THIS
459
+ if @props.is_a? Array then
460
+ # multiRow = []
461
+ # @props.each { |currentDE|
462
+
463
+ # currentDE['columns'].each { |key|
464
+ # currentDE['Fields'] = {}
465
+ # currentDE['Fields']['Field'] = []
466
+ # currentDE['Fields']['Field'].push(key)
467
+ # }
468
+ # currentDE.delete('columns')
469
+ # multiRow.push(currentDE.dup)
470
+ # }
471
+
472
+ # @props = multiRow
473
+ else
474
+ currentFields = []
475
+ currentProp = {}
476
+
477
+ @props.each { |key,value|
478
+ currentFields.push({"Name" => key, "Value" => value})
479
+ }
480
+ currentProp['CustomerKey'] = @CustomerKey
481
+ currentProp['Properties'] = {}
482
+ currentProp['Properties']['Property'] = currentFields
483
+ end
484
+
485
+ obj = ET_Post.new(@authStub, @obj, currentProp)
486
+ @props = originalProps
487
+ obj
488
+ end
489
+
490
+ def patch
491
+ getCustomerKey
492
+ currentFields = []
493
+ currentProp = {}
494
+
495
+ @props.each { |key,value|
496
+ currentFields.push({"Name" => key, "Value" => value})
497
+ }
498
+ currentProp['CustomerKey'] = @CustomerKey
499
+ currentProp['Properties'] = {}
500
+ currentProp['Properties']['Property'] = currentFields
501
+
502
+ ET_Patch.new(@authStub, @obj, currentProp)
503
+ end
504
+ def delete
505
+ getCustomerKey
506
+ currentFields = []
507
+ currentProp = {}
508
+
509
+ @props.each { |key,value|
510
+ currentFields.push({"Name" => key, "Value" => value})
511
+ }
512
+ currentProp['CustomerKey'] = @CustomerKey
513
+ currentProp['Keys'] = {}
514
+ currentProp['Keys']['Key'] = currentFields
515
+
516
+ ET_Delete.new(@authStub, @obj, currentProp)
517
+ end
518
+
519
+ private
520
+ def getCustomerKey
521
+ if @CustomerKey.nil? then
522
+ if @CustomerKey.nil? && @Name.nil? then
523
+ raise 'Unable to process DataExtension::Row request due to CustomerKey and Name not being defined on ET_DatExtension::row'
524
+ else
525
+ de = ET_DataExtension.new
526
+ de.authStub = @authStub
527
+ de.props = ["Name","CustomerKey"]
528
+ de.filter = {'Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => @Name}
529
+ getResponse = de.get
530
+ if getResponse.status && (getResponse.results.length == 1) then
531
+ @CustomerKey = getResponse.results[0][:customer_key]
532
+ else
533
+ raise 'Unable to process DataExtension::Row request due to unable to find DataExtension based on Name'
534
+ end
535
+ end
536
+ end
537
+ end
538
+
539
+ def getName
540
+ if @Name.nil? then
541
+ if @CustomerKey.nil? && @Name.nil? then
542
+ raise 'Unable to process DataExtension::Row request due to CustomerKey and Name not being defined on ET_DatExtension::row'
543
+ else
544
+ de = ET_DataExtension.new
545
+ de.authStub = @authStub
546
+ de.props = ["Name","CustomerKey"]
547
+ de.filter = {'Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => @CustomerKey}
548
+ getResponse = de.get
549
+ if getResponse.status && (getResponse.results.length == 1) then
550
+ @Name = getResponse.results[0][:name]
551
+ else
552
+ raise 'Unable to process DataExtension::Row request due to unable to find DataExtension based on CustomerKey'
553
+ end
554
+ end
555
+ end
556
+ end
557
+ end
558
+ end
559
+
560
+ class ET_TriggeredSend < ET_CUDSupport
561
+ attr_accessor :subscribers
562
+ def initialize
563
+ super
564
+ @obj = 'TriggeredSendDefinition'
565
+ end
566
+
567
+ def send
568
+ @tscall = {"TriggeredSendDefinition" => @props, "Subscribers" => @subscribers}
569
+ ET_Post.new(@authStub, "TriggeredSend", @tscall)
570
+ end
571
+ end
572
+ =end