sfmc-fuelsdk-ruby 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +28 -28
- data/Gemfile +3 -3
- data/Gemfile.lock +92 -90
- data/Guardfile +8 -8
- data/LICENSE.md +13 -13
- data/README.md +166 -143
- data/Rakefile +1 -1
- data/lib/marketingcloudsdk.rb +74 -74
- data/lib/marketingcloudsdk/client.rb +348 -296
- data/lib/marketingcloudsdk/http_request.rb +118 -118
- data/lib/marketingcloudsdk/objects.rb +757 -757
- data/lib/marketingcloudsdk/rest.rb +118 -118
- data/lib/marketingcloudsdk/soap.rb +296 -282
- data/lib/marketingcloudsdk/targeting.rb +99 -99
- data/lib/marketingcloudsdk/utils.rb +47 -47
- data/lib/marketingcloudsdk/version.rb +39 -39
- data/lib/new.rb +1240 -1240
- data/marketingcloudsdk.gemspec +30 -30
- data/samples/sample-AddSubscriberToList.rb +56 -56
- data/samples/sample-CreateAndStartDataExtensionImport.rb +29 -29
- data/samples/sample-CreateAndStartListImport.rb +27 -27
- data/samples/sample-CreateContentAreas.rb +48 -48
- data/samples/sample-CreateDataExtensions.rb +54 -54
- data/samples/sample-CreateProfileAttributes.rb +48 -48
- data/samples/sample-SendEmailToDataExtension.rb +23 -23
- data/samples/sample-SendEmailToList.rb +23 -23
- data/samples/sample-SendTriggeredSends.rb +30 -30
- data/samples/sample-bounceevent.rb +70 -70
- data/samples/sample-campaign.rb +211 -211
- data/samples/sample-clickevent.rb +71 -71
- data/samples/sample-contentarea.rb +122 -122
- data/samples/sample-dataextension.rb +209 -209
- data/samples/sample-directverb.rb +54 -54
- data/samples/sample-email.rb +122 -122
- data/samples/sample-email.senddefinition.rb +134 -134
- data/samples/sample-folder.rb +143 -143
- data/samples/sample-import.rb +103 -103
- data/samples/sample-list.rb +105 -105
- data/samples/sample-list.subscriber.rb +97 -97
- data/samples/sample-openevent.rb +70 -70
- data/samples/sample-profileattribute.rb +56 -56
- data/samples/sample-sentevent.rb +70 -70
- data/samples/sample-subscriber.rb +135 -135
- data/samples/sample-triggeredsend.rb +129 -129
- data/samples/sample-unsubevent.rb +72 -72
- data/samples/sample_helper.rb.template +10 -10
- data/spec/client_spec.rb +218 -218
- data/spec/default_values_fallback_spec.rb +30 -30
- data/spec/helper_funcs_spec.rb +11 -11
- data/spec/http_request_spec.rb +61 -61
- data/spec/objects_helper_spec.rb +32 -32
- data/spec/objects_spec.rb +484 -484
- data/spec/rest_spec.rb +48 -48
- data/spec/soap_spec.rb +140 -140
- data/spec/spec_helper.rb +14 -14
- data/spec/targeting_spec.rb +44 -44
- metadata +9 -9
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/marketingcloudsdk.rb
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
=begin
|
2
|
-
Copyright (c) 2013 ExactTarget, Inc.
|
3
|
-
|
4
|
-
All rights reserved.
|
5
|
-
|
6
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7
|
-
|
8
|
-
following conditions are met:
|
9
|
-
|
10
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
11
|
-
|
12
|
-
following disclaimer.
|
13
|
-
|
14
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
15
|
-
|
16
|
-
following disclaimer in the documentation and/or other materials provided with the distribution.
|
17
|
-
|
18
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
|
19
|
-
|
20
|
-
products derived from this software without specific prior written permission.
|
21
|
-
|
22
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
-
|
24
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
25
|
-
|
26
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
27
|
-
|
28
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
-
|
30
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
-
|
32
|
-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
33
|
-
|
34
|
-
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
|
-
=end
|
36
|
-
|
37
|
-
require "marketingcloudsdk/version"
|
38
|
-
|
39
|
-
require 'rubygems'
|
40
|
-
require 'date'
|
41
|
-
require 'jwt'
|
42
|
-
|
43
|
-
module MarketingCloudSDK
|
44
|
-
require 'marketingcloudsdk/utils'
|
45
|
-
autoload :HTTPRequest, 'marketingcloudsdk/http_request'
|
46
|
-
autoload :Targeting, 'marketingcloudsdk/targeting'
|
47
|
-
autoload :Soap, 'marketingcloudsdk/soap'
|
48
|
-
autoload :Rest, 'marketingcloudsdk/rest'
|
49
|
-
require 'marketingcloudsdk/client'
|
50
|
-
require 'marketingcloudsdk/objects'
|
51
|
-
end
|
52
|
-
|
53
|
-
# backwards compatability
|
54
|
-
ET_Client = MarketingCloudSDK::Client
|
55
|
-
ET_BounceEvent = MarketingCloudSDK::BounceEvent
|
56
|
-
ET_ClickEvent = MarketingCloudSDK::ClickEvent
|
57
|
-
ET_ContentArea = MarketingCloudSDK::ContentArea
|
58
|
-
ET_DataExtension = MarketingCloudSDK::DataExtension
|
59
|
-
ET_DataFolder = MarketingCloudSDK::DataFolder
|
60
|
-
ET_Folder = MarketingCloudSDK::Folder
|
61
|
-
ET_Email = MarketingCloudSDK::Email
|
62
|
-
ET_List = MarketingCloudSDK::List
|
63
|
-
ET_OpenEvent = MarketingCloudSDK::OpenEvent
|
64
|
-
ET_SentEvent = MarketingCloudSDK::SentEvent
|
65
|
-
ET_Subscriber = MarketingCloudSDK::Subscriber
|
66
|
-
ET_UnsubEvent = MarketingCloudSDK::UnsubEvent
|
67
|
-
ET_TriggeredSend = MarketingCloudSDK::TriggeredSend
|
68
|
-
ET_Campaign = MarketingCloudSDK::Campaign
|
69
|
-
ET_Get = MarketingCloudSDK::Get
|
70
|
-
ET_Post = MarketingCloudSDK::Post
|
71
|
-
ET_Delete = MarketingCloudSDK::Delete
|
72
|
-
ET_Patch = MarketingCloudSDK::Patch
|
73
|
-
ET_ProfileAttribute = MarketingCloudSDK::ProfileAttribute
|
74
|
-
ET_Import = MarketingCloudSDK::Import
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2013 ExactTarget, Inc.
|
3
|
+
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7
|
+
|
8
|
+
following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
11
|
+
|
12
|
+
following disclaimer.
|
13
|
+
|
14
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
15
|
+
|
16
|
+
following disclaimer in the documentation and/or other materials provided with the distribution.
|
17
|
+
|
18
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
|
19
|
+
|
20
|
+
products derived from this software without specific prior written permission.
|
21
|
+
|
22
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
+
|
24
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
25
|
+
|
26
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
27
|
+
|
28
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
|
30
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
+
|
32
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
33
|
+
|
34
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
=end
|
36
|
+
|
37
|
+
require "marketingcloudsdk/version"
|
38
|
+
|
39
|
+
require 'rubygems'
|
40
|
+
require 'date'
|
41
|
+
require 'jwt'
|
42
|
+
|
43
|
+
module MarketingCloudSDK
|
44
|
+
require 'marketingcloudsdk/utils'
|
45
|
+
autoload :HTTPRequest, 'marketingcloudsdk/http_request'
|
46
|
+
autoload :Targeting, 'marketingcloudsdk/targeting'
|
47
|
+
autoload :Soap, 'marketingcloudsdk/soap'
|
48
|
+
autoload :Rest, 'marketingcloudsdk/rest'
|
49
|
+
require 'marketingcloudsdk/client'
|
50
|
+
require 'marketingcloudsdk/objects'
|
51
|
+
end
|
52
|
+
|
53
|
+
# backwards compatability
|
54
|
+
ET_Client = MarketingCloudSDK::Client
|
55
|
+
ET_BounceEvent = MarketingCloudSDK::BounceEvent
|
56
|
+
ET_ClickEvent = MarketingCloudSDK::ClickEvent
|
57
|
+
ET_ContentArea = MarketingCloudSDK::ContentArea
|
58
|
+
ET_DataExtension = MarketingCloudSDK::DataExtension
|
59
|
+
ET_DataFolder = MarketingCloudSDK::DataFolder
|
60
|
+
ET_Folder = MarketingCloudSDK::Folder
|
61
|
+
ET_Email = MarketingCloudSDK::Email
|
62
|
+
ET_List = MarketingCloudSDK::List
|
63
|
+
ET_OpenEvent = MarketingCloudSDK::OpenEvent
|
64
|
+
ET_SentEvent = MarketingCloudSDK::SentEvent
|
65
|
+
ET_Subscriber = MarketingCloudSDK::Subscriber
|
66
|
+
ET_UnsubEvent = MarketingCloudSDK::UnsubEvent
|
67
|
+
ET_TriggeredSend = MarketingCloudSDK::TriggeredSend
|
68
|
+
ET_Campaign = MarketingCloudSDK::Campaign
|
69
|
+
ET_Get = MarketingCloudSDK::Get
|
70
|
+
ET_Post = MarketingCloudSDK::Post
|
71
|
+
ET_Delete = MarketingCloudSDK::Delete
|
72
|
+
ET_Patch = MarketingCloudSDK::Patch
|
73
|
+
ET_ProfileAttribute = MarketingCloudSDK::ProfileAttribute
|
74
|
+
ET_Import = MarketingCloudSDK::Import
|
@@ -1,296 +1,348 @@
|
|
1
|
-
=begin
|
2
|
-
Copyright (c) 2013 ExactTarget, Inc.
|
3
|
-
|
4
|
-
All rights reserved.
|
5
|
-
|
6
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7
|
-
|
8
|
-
following conditions are met:
|
9
|
-
|
10
|
-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
11
|
-
|
12
|
-
following disclaimer.
|
13
|
-
|
14
|
-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
15
|
-
|
16
|
-
following disclaimer in the documentation and/or other materials provided with the distribution.
|
17
|
-
|
18
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
|
19
|
-
|
20
|
-
products derived from this software without specific prior written permission.
|
21
|
-
|
22
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
-
|
24
|
-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
25
|
-
|
26
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
27
|
-
|
28
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
-
|
30
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
-
|
32
|
-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
33
|
-
|
34
|
-
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
|
-
|
36
|
-
=end
|
37
|
-
|
38
|
-
require 'securerandom'
|
39
|
-
module MarketingCloudSDK
|
40
|
-
class Response
|
41
|
-
# not doing accessor so user, can't update these values from response.
|
42
|
-
# You will see in the code some of these
|
43
|
-
# items are being updated via back doors and such.
|
44
|
-
attr_reader :code, :message, :results, :request_id, :body, :raw
|
45
|
-
|
46
|
-
# some defaults
|
47
|
-
def success
|
48
|
-
@success ||= false
|
49
|
-
end
|
50
|
-
alias :success? :success
|
51
|
-
alias :status :success # backward compatibility
|
52
|
-
|
53
|
-
def more
|
54
|
-
@more ||= false
|
55
|
-
end
|
56
|
-
alias :more? :more
|
57
|
-
|
58
|
-
def initialize raw, client
|
59
|
-
@client = client # keep connection with client in case we request more
|
60
|
-
@results = []
|
61
|
-
@raw = raw
|
62
|
-
unpack raw
|
63
|
-
rescue => ex # all else fails return raw
|
64
|
-
puts ex.message
|
65
|
-
raw
|
66
|
-
end
|
67
|
-
|
68
|
-
def continue
|
69
|
-
raise NotImplementedError
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
def unpack raw
|
74
|
-
raise NotImplementedError
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
class Client
|
79
|
-
attr_accessor :debug, :access_token, :auth_token, :internal_token, :refresh_token,
|
80
|
-
:id, :secret, :signature, :base_api_url, :package_name, :package_folders, :parent_folders, :auth_token_expiration,
|
81
|
-
:request_token_url, :soap_endpoint
|
82
|
-
|
83
|
-
include MarketingCloudSDK::Soap
|
84
|
-
include MarketingCloudSDK::Rest
|
85
|
-
|
86
|
-
def jwt= encoded_jwt
|
87
|
-
raise 'Require app signature to decode JWT' unless self.signature
|
88
|
-
decoded_jwt = JWT.decode(encoded_jwt, self.signature, true)
|
89
|
-
|
90
|
-
self.auth_token = decoded_jwt['request']['user']['oauthToken']
|
91
|
-
self.internal_token = decoded_jwt['request']['user']['internalOauthToken']
|
92
|
-
self.refresh_token = decoded_jwt['request']['user']['refreshToken']
|
93
|
-
self.auth_token_expiration = Time.new + decoded_jwt['request']['user']['expiresIn']
|
94
|
-
self.package_name = decoded_jwt['request']['application']['package']
|
95
|
-
end
|
96
|
-
|
97
|
-
def initialize(params={}, debug=false)
|
98
|
-
@refresh_mutex = Mutex.new
|
99
|
-
self.debug = debug
|
100
|
-
client_config = params['client']
|
101
|
-
if client_config
|
102
|
-
self.id = client_config["id"]
|
103
|
-
self.secret = client_config["secret"]
|
104
|
-
self.signature = client_config["signature"]
|
105
|
-
self.base_api_url = !(client_config["base_api_url"].to_s.strip.empty?) ? client_config["base_api_url"] : 'https://www.exacttargetapis.com'
|
106
|
-
self.request_token_url =
|
107
|
-
self.soap_endpoint = client_config["soap_endpoint"]
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
def
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
result =
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2013 ExactTarget, Inc.
|
3
|
+
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
7
|
+
|
8
|
+
following conditions are met:
|
9
|
+
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
11
|
+
|
12
|
+
following disclaimer.
|
13
|
+
|
14
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
15
|
+
|
16
|
+
following disclaimer in the documentation and/or other materials provided with the distribution.
|
17
|
+
|
18
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
|
19
|
+
|
20
|
+
products derived from this software without specific prior written permission.
|
21
|
+
|
22
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
+
|
24
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
25
|
+
|
26
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
27
|
+
|
28
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
|
30
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
31
|
+
|
32
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
33
|
+
|
34
|
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
|
36
|
+
=end
|
37
|
+
|
38
|
+
require 'securerandom'
|
39
|
+
module MarketingCloudSDK
|
40
|
+
class Response
|
41
|
+
# not doing accessor so user, can't update these values from response.
|
42
|
+
# You will see in the code some of these
|
43
|
+
# items are being updated via back doors and such.
|
44
|
+
attr_reader :code, :message, :results, :request_id, :body, :raw
|
45
|
+
|
46
|
+
# some defaults
|
47
|
+
def success
|
48
|
+
@success ||= false
|
49
|
+
end
|
50
|
+
alias :success? :success
|
51
|
+
alias :status :success # backward compatibility
|
52
|
+
|
53
|
+
def more
|
54
|
+
@more ||= false
|
55
|
+
end
|
56
|
+
alias :more? :more
|
57
|
+
|
58
|
+
def initialize raw, client
|
59
|
+
@client = client # keep connection with client in case we request more
|
60
|
+
@results = []
|
61
|
+
@raw = raw
|
62
|
+
unpack raw
|
63
|
+
rescue => ex # all else fails return raw
|
64
|
+
puts ex.message
|
65
|
+
raw
|
66
|
+
end
|
67
|
+
|
68
|
+
def continue
|
69
|
+
raise NotImplementedError
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def unpack raw
|
74
|
+
raise NotImplementedError
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class Client
|
79
|
+
attr_accessor :debug, :access_token, :auth_token, :internal_token, :refresh_token,
|
80
|
+
:id, :secret, :signature, :base_api_url, :package_name, :package_folders, :parent_folders, :auth_token_expiration,
|
81
|
+
:request_token_url, :soap_endpoint, :use_oAuth2_authentication, :account_id, :scope
|
82
|
+
|
83
|
+
include MarketingCloudSDK::Soap
|
84
|
+
include MarketingCloudSDK::Rest
|
85
|
+
|
86
|
+
def jwt= encoded_jwt
|
87
|
+
raise 'Require app signature to decode JWT' unless self.signature
|
88
|
+
decoded_jwt = JWT.decode(encoded_jwt, self.signature, true)
|
89
|
+
|
90
|
+
self.auth_token = decoded_jwt['request']['user']['oauthToken']
|
91
|
+
self.internal_token = decoded_jwt['request']['user']['internalOauthToken']
|
92
|
+
self.refresh_token = decoded_jwt['request']['user']['refreshToken']
|
93
|
+
self.auth_token_expiration = Time.new + decoded_jwt['request']['user']['expiresIn']
|
94
|
+
self.package_name = decoded_jwt['request']['application']['package']
|
95
|
+
end
|
96
|
+
|
97
|
+
def initialize(params={}, debug=false)
|
98
|
+
@refresh_mutex = Mutex.new
|
99
|
+
self.debug = debug
|
100
|
+
client_config = params['client']
|
101
|
+
if client_config
|
102
|
+
self.id = client_config["id"]
|
103
|
+
self.secret = client_config["secret"]
|
104
|
+
self.signature = client_config["signature"]
|
105
|
+
self.base_api_url = !(client_config["base_api_url"].to_s.strip.empty?) ? client_config["base_api_url"] : 'https://www.exacttargetapis.com'
|
106
|
+
self.request_token_url = client_config["request_token_url"]
|
107
|
+
self.soap_endpoint = client_config["soap_endpoint"]
|
108
|
+
self.use_oAuth2_authentication = client_config["use_oAuth2_authentication"]
|
109
|
+
self.account_id = client_config["account_id"]
|
110
|
+
self.scope = client_config["scope"]
|
111
|
+
end
|
112
|
+
|
113
|
+
# Set a default value in case no 'client' params is sent
|
114
|
+
if (!self.base_api_url)
|
115
|
+
self.base_api_url = 'https://www.exacttargetapis.com'
|
116
|
+
end
|
117
|
+
|
118
|
+
if (self.request_token_url.to_s.strip.empty?)
|
119
|
+
if(use_oAuth2_authentication == true)
|
120
|
+
raise 'request_token_url (Auth TSE) is mandatory when using OAuth2 authentication'
|
121
|
+
else
|
122
|
+
self.request_token_url = 'https://auth.exacttargetapis.com/v1/requestToken'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
self.jwt = params['jwt'] if params['jwt']
|
127
|
+
self.refresh_token = params['refresh_token'] if params['refresh_token']
|
128
|
+
|
129
|
+
self.wsdl = params["defaultwsdl"] if params["defaultwsdl"]
|
130
|
+
|
131
|
+
self.refresh
|
132
|
+
end
|
133
|
+
|
134
|
+
def refresh force=false
|
135
|
+
@refresh_mutex.synchronize do
|
136
|
+
raise 'Require Client Id and Client Secret to refresh tokens' unless (id && secret)
|
137
|
+
|
138
|
+
if (self.use_oAuth2_authentication == true)
|
139
|
+
self.refreshWithOAuth2(force)
|
140
|
+
return
|
141
|
+
end
|
142
|
+
|
143
|
+
#If we don't already have a token or the token expires within 5 min(300 seconds)
|
144
|
+
if (self.access_token.nil? || Time.new + 300 > self.auth_token_expiration || force) then
|
145
|
+
payload = Hash.new.tap do |h|
|
146
|
+
h['clientId']= id
|
147
|
+
h['clientSecret'] = secret
|
148
|
+
h['refreshToken'] = refresh_token if refresh_token
|
149
|
+
h['accessType'] = 'offline'
|
150
|
+
end
|
151
|
+
|
152
|
+
options = Hash.new.tap do |h|
|
153
|
+
h['data'] = payload
|
154
|
+
h['content_type'] = 'application/json'
|
155
|
+
h['params'] = {'legacy' => 1}
|
156
|
+
end
|
157
|
+
response = post(request_token_url, options)
|
158
|
+
raise "Unable to refresh token: #{response['message']}" unless response.has_key?('accessToken')
|
159
|
+
|
160
|
+
self.access_token = response['accessToken']
|
161
|
+
self.internal_token = response['legacyToken']
|
162
|
+
self.auth_token_expiration = Time.new + response['expiresIn']
|
163
|
+
self.refresh_token = response['refreshToken'] if response.has_key?("refreshToken")
|
164
|
+
return true
|
165
|
+
else
|
166
|
+
return false
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def refreshWithOAuth2 force=false
|
172
|
+
raise 'Require Client Id and Client Secret to refresh tokens' unless (id && secret)
|
173
|
+
#If we don't already have a token or the token expires within 5 min(300 seconds)
|
174
|
+
if (self.access_token.nil? || Time.new + 300 > self.auth_token_expiration || force) then
|
175
|
+
payload = Hash.new.tap do |h|
|
176
|
+
h['client_id']= id
|
177
|
+
h['client_secret'] = secret
|
178
|
+
h['grant_type'] = 'client_credentials'
|
179
|
+
|
180
|
+
if (not self.account_id.to_s.strip.empty?)then
|
181
|
+
h['account_id'] = account_id
|
182
|
+
end
|
183
|
+
|
184
|
+
if (not self.scope.to_s.strip.empty?)then
|
185
|
+
h['scope'] = scope
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
options = Hash.new.tap do |h|
|
190
|
+
h['data'] = payload
|
191
|
+
h['content_type'] = 'application/json'
|
192
|
+
end
|
193
|
+
|
194
|
+
self.request_token_url += '/v2/token'
|
195
|
+
|
196
|
+
response = post(request_token_url, options)
|
197
|
+
raise "Unable to refresh token: #{response['message']}" unless response.has_key?('access_token')
|
198
|
+
|
199
|
+
self.access_token = response['access_token']
|
200
|
+
self.auth_token_expiration = Time.new + response['expires_in']
|
201
|
+
self.soap_endpoint = response['soap_instance_url'] + 'service.asmx'
|
202
|
+
self.base_api_url = response['rest_instance_url']
|
203
|
+
return true
|
204
|
+
else
|
205
|
+
return false
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def refresh!
|
210
|
+
refresh true
|
211
|
+
end
|
212
|
+
|
213
|
+
def AddSubscriberToList(email, ids, subscriber_key = nil)
|
214
|
+
s = MarketingCloudSDK::Subscriber.new
|
215
|
+
s.client = self
|
216
|
+
lists = ids.collect{|id| {'ID' => id}}
|
217
|
+
s.properties = {"EmailAddress" => email, "Lists" => lists}
|
218
|
+
p s.properties
|
219
|
+
s.properties['SubscriberKey'] = subscriber_key if subscriber_key
|
220
|
+
|
221
|
+
# Try to add the subscriber
|
222
|
+
if(rsp = s.post and rsp.results.first[:error_code] == '12014')
|
223
|
+
# subscriber already exists we need to update.
|
224
|
+
rsp = s.patch
|
225
|
+
end
|
226
|
+
rsp
|
227
|
+
end
|
228
|
+
|
229
|
+
def CreateDataExtensions(definitions)
|
230
|
+
de = MarketingCloudSDK::DataExtension.new
|
231
|
+
de.client = self
|
232
|
+
de.properties = definitions
|
233
|
+
de.post
|
234
|
+
end
|
235
|
+
def SendTriggeredSends(arrayOfTriggeredRecords)
|
236
|
+
sendTS = ET_TriggeredSend.new
|
237
|
+
sendTS.authStub = self
|
238
|
+
|
239
|
+
sendTS.properties = arrayOfTriggeredRecords
|
240
|
+
sendResponse = sendTS.send
|
241
|
+
|
242
|
+
return sendResponse
|
243
|
+
end
|
244
|
+
def SendEmailToList(emailID, listID, sendClassificationCustomerKey)
|
245
|
+
email = ET_Email::SendDefinition.new
|
246
|
+
email.properties = {"Name"=>SecureRandom.uuid, "CustomerKey"=>SecureRandom.uuid, "Description"=>"Created with RubySDK"}
|
247
|
+
email.properties["SendClassification"] = {"CustomerKey"=>sendClassificationCustomerKey}
|
248
|
+
email.properties["SendDefinitionList"] = {"List"=> {"ID"=>listID}, "DataSourceTypeID"=>"List"}
|
249
|
+
email.properties["Email"] = {"ID"=>emailID}
|
250
|
+
email.authStub = self
|
251
|
+
result = email.post
|
252
|
+
if result.status then
|
253
|
+
sendresult = email.send
|
254
|
+
if sendresult.status then
|
255
|
+
deleteresult = email.delete
|
256
|
+
return sendresult
|
257
|
+
else
|
258
|
+
raise "Unable to send using send definition due to: #{result.results[0][:status_message]}"
|
259
|
+
end
|
260
|
+
else
|
261
|
+
raise "Unable to create send definition due to: #{result.results[0][:status_message]}"
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def SendEmailToDataExtension(emailID, sendableDataExtensionCustomerKey, sendClassificationCustomerKey)
|
266
|
+
email = ET_Email::SendDefinition.new
|
267
|
+
email.properties = {"Name"=>SecureRandom.uuid, "CustomerKey"=>SecureRandom.uuid, "Description"=>"Created with RubySDK"}
|
268
|
+
email.properties["SendClassification"] = {"CustomerKey"=> sendClassificationCustomerKey}
|
269
|
+
email.properties["SendDefinitionList"] = {"CustomerKey"=> sendableDataExtensionCustomerKey, "DataSourceTypeID"=>"CustomObject"}
|
270
|
+
email.properties["Email"] = {"ID"=>emailID}
|
271
|
+
email.authStub = self
|
272
|
+
result = email.post
|
273
|
+
if result.status then
|
274
|
+
sendresult = email.send
|
275
|
+
if sendresult.status then
|
276
|
+
deleteresult = email.delete
|
277
|
+
return sendresult
|
278
|
+
else
|
279
|
+
raise "Unable to send using send definition due to: #{result.results[0][:status_message]}"
|
280
|
+
end
|
281
|
+
else
|
282
|
+
raise "Unable to create send definition due to: #{result.results[0][:status_message]}"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
def CreateAndStartListImport(listId,fileName)
|
286
|
+
import = ET_Import.new
|
287
|
+
import.authStub = self
|
288
|
+
import.properties = {"Name"=> "SDK Generated Import #{DateTime.now.to_s}"}
|
289
|
+
import.properties["CustomerKey"] = SecureRandom.uuid
|
290
|
+
import.properties["Description"] = "SDK Generated Import"
|
291
|
+
import.properties["AllowErrors"] = "true"
|
292
|
+
import.properties["DestinationObject"] = {"ID"=>listId}
|
293
|
+
import.properties["FieldMappingType"] = "InferFromColumnHeadings"
|
294
|
+
import.properties["FileSpec"] = fileName
|
295
|
+
import.properties["FileType"] = "CSV"
|
296
|
+
import.properties["RetrieveFileTransferLocation"] = {"CustomerKey"=>"ExactTarget Enhanced FTP"}
|
297
|
+
import.properties["UpdateType"] = "AddAndUpdate"
|
298
|
+
result = import.post
|
299
|
+
|
300
|
+
if result.status then
|
301
|
+
return import.start
|
302
|
+
else
|
303
|
+
raise "Unable to create import definition due to: #{result.results[0][:status_message]}"
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
def CreateAndStartDataExtensionImport(dataExtensionCustomerKey, fileName, overwrite)
|
308
|
+
import = ET_Import.new
|
309
|
+
import.authStub = self
|
310
|
+
import.properties = {"Name"=> "SDK Generated Import #{DateTime.now.to_s}"}
|
311
|
+
import.properties["CustomerKey"] = SecureRandom.uuid
|
312
|
+
import.properties["Description"] = "SDK Generated Import"
|
313
|
+
import.properties["AllowErrors"] = "true"
|
314
|
+
import.properties["DestinationObject"] = {"CustomerKey"=>dataExtensionCustomerKey}
|
315
|
+
import.properties["FieldMappingType"] = "InferFromColumnHeadings"
|
316
|
+
import.properties["FileSpec"] = fileName
|
317
|
+
import.properties["FileType"] = "CSV"
|
318
|
+
import.properties["RetrieveFileTransferLocation"] = {"CustomerKey"=>"ExactTarget Enhanced FTP"}
|
319
|
+
if overwrite then
|
320
|
+
import.properties["UpdateType"] = "Overwrite"
|
321
|
+
else
|
322
|
+
import.properties["UpdateType"] = "AddAndUpdate"
|
323
|
+
end
|
324
|
+
result = import.post
|
325
|
+
|
326
|
+
if result.status then
|
327
|
+
return import.start
|
328
|
+
else
|
329
|
+
raise "Unable to create import definition due to: #{result.results[0][:status_message]}"
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
def CreateProfileAttributes(allAttributes)
|
334
|
+
attrs = ET_ProfileAttribute.new
|
335
|
+
attrs.authStub = self
|
336
|
+
attrs.properties = allAttributes
|
337
|
+
return attrs.post
|
338
|
+
end
|
339
|
+
|
340
|
+
def CreateContentAreas(arrayOfContentAreas)
|
341
|
+
postC = ET_ContentArea.new
|
342
|
+
postC.authStub = self
|
343
|
+
postC.properties = arrayOfContentAreas
|
344
|
+
sendResponse = postC.post
|
345
|
+
return sendResponse
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|