Skip to content

Commit ed0fb09

Browse files
committed
1 parent 99f2fb0 commit ed0fb09

File tree

2 files changed

+67
-61
lines changed

2 files changed

+67
-61
lines changed

lib/marketingcloudsdk/client.rb

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@
33
44
All rights reserved.
55
6-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
77
88
following conditions are met:
99
10-
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
10+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
1111
1212
following disclaimer.
1313
14-
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
14+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
1515
1616
following disclaimer in the documentation and/or other materials provided with the distribution.
1717
18-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
18+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
1919
2020
products derived from this software without specific prior written permission.
2121
22-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
2323
24-
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2525
26-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2727
28-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2929
30-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
3131
32-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
3333
3434
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535
36-
=end
36+
=end
3737

3838
require 'securerandom'
3939
module MarketingCloudSDK
@@ -42,7 +42,7 @@ class Response
4242
# You will see in the code some of these
4343
# items are being updated via back doors and such.
4444
attr_reader :code, :message, :results, :request_id, :body, :raw
45-
45+
4646
# some defaults
4747
def success
4848
@success ||= false
@@ -84,13 +84,19 @@ class Client
8484

8585
def jwt= encoded_jwt
8686
raise 'Require app signature to decode JWT' unless self.signature
87-
decoded_jwt = JWT.decode(encoded_jwt, self.signature, true)
87+
decoded_jwt = JWT.decode(encoded_jwt, self.signature, true)[0]
8888

89-
self.auth_token = decoded_jwt['request']['user']['oauthToken']
90-
self.internal_token = decoded_jwt['request']['user']['internalOauthToken']
91-
self.refresh_token = decoded_jwt['request']['user']['refreshToken']
92-
self.auth_token_expiration = Time.new + decoded_jwt['request']['user']['expiresIn']
93-
self.package_name = decoded_jwt['request']['application']['package']
89+
if decoded_jwt['request']['claimsVersion'] == 2
90+
self.refresh_token = decoded_jwt['request']['rest']['refreshToken']
91+
self.auth_token_expiration = Time.at(decoded_jwt['exp'])
92+
self.package_name = decoded_jwt['request']['application']['package']
93+
else
94+
self.auth_token = decoded_jwt['request']['user']['oauthToken']
95+
self.internal_token = decoded_jwt['request']['user']['internalOauthToken']
96+
self.refresh_token = decoded_jwt['request']['user']['refreshToken']
97+
self.auth_token_expiration = Time.new + decoded_jwt['request']['user']['expiresIn']
98+
self.package_name = decoded_jwt['request']['application']['package']
99+
end
94100
end
95101

96102
def initialize(params={}, debug=false)
@@ -135,7 +141,7 @@ def refresh force=false
135141
self.auth_token_expiration = Time.new + response['expiresIn']
136142
self.refresh_token = response['refreshToken'] if response.has_key?("refreshToken")
137143
return true
138-
else
144+
else
139145
return false
140146
end
141147
end
@@ -150,7 +156,7 @@ def AddSubscriberToList(email, ids, subscriber_key = nil)
150156
s.client = self
151157
lists = ids.collect{|id| {'ID' => id}}
152158
s.properties = {"EmailAddress" => email, "Lists" => lists}
153-
p s.properties
159+
p s.properties
154160
s.properties['SubscriberKey'] = subscriber_key if subscriber_key
155161

156162
# Try to add the subscriber
@@ -170,55 +176,55 @@ def CreateDataExtensions(definitions)
170176
def SendTriggeredSends(arrayOfTriggeredRecords)
171177
sendTS = ET_TriggeredSend.new
172178
sendTS.authStub = self
173-
179+
174180
sendTS.properties = arrayOfTriggeredRecords
175181
sendResponse = sendTS.send
176-
182+
177183
return sendResponse
178184
end
179185
def SendEmailToList(emailID, listID, sendClassificationCustomerKey)
180-
email = ET_Email::SendDefinition.new
181-
email.properties = {"Name"=>SecureRandom.uuid, "CustomerKey"=>SecureRandom.uuid, "Description"=>"Created with RubySDK"}
186+
email = ET_Email::SendDefinition.new
187+
email.properties = {"Name"=>SecureRandom.uuid, "CustomerKey"=>SecureRandom.uuid, "Description"=>"Created with RubySDK"}
182188
email.properties["SendClassification"] = {"CustomerKey"=>sendClassificationCustomerKey}
183189
email.properties["SendDefinitionList"] = {"List"=> {"ID"=>listID}, "DataSourceTypeID"=>"List"}
184190
email.properties["Email"] = {"ID"=>emailID}
185191
email.authStub = self
186192
result = email.post
187-
if result.status then
188-
sendresult = email.send
189-
if sendresult.status then
193+
if result.status then
194+
sendresult = email.send
195+
if sendresult.status then
190196
deleteresult = email.delete
191197
return sendresult
192-
else
198+
else
193199
raise "Unable to send using send definition due to: #{result.results[0][:status_message]}"
194-
end
200+
end
195201
else
196202
raise "Unable to create send definition due to: #{result.results[0][:status_message]}"
197-
end
198-
end
199-
203+
end
204+
end
205+
200206
def SendEmailToDataExtension(emailID, sendableDataExtensionCustomerKey, sendClassificationCustomerKey)
201-
email = ET_Email::SendDefinition.new
202-
email.properties = {"Name"=>SecureRandom.uuid, "CustomerKey"=>SecureRandom.uuid, "Description"=>"Created with RubySDK"}
207+
email = ET_Email::SendDefinition.new
208+
email.properties = {"Name"=>SecureRandom.uuid, "CustomerKey"=>SecureRandom.uuid, "Description"=>"Created with RubySDK"}
203209
email.properties["SendClassification"] = {"CustomerKey"=> sendClassificationCustomerKey}
204210
email.properties["SendDefinitionList"] = {"CustomerKey"=> sendableDataExtensionCustomerKey, "DataSourceTypeID"=>"CustomObject"}
205211
email.properties["Email"] = {"ID"=>emailID}
206212
email.authStub = self
207213
result = email.post
208-
if result.status then
209-
sendresult = email.send
210-
if sendresult.status then
214+
if result.status then
215+
sendresult = email.send
216+
if sendresult.status then
211217
deleteresult = email.delete
212218
return sendresult
213-
else
219+
else
214220
raise "Unable to send using send definition due to: #{result.results[0][:status_message]}"
215-
end
221+
end
216222
else
217223
raise "Unable to create send definition due to: #{result.results[0][:status_message]}"
218-
end
224+
end
219225
end
220226
def CreateAndStartListImport(listId,fileName)
221-
import = ET_Import.new
227+
import = ET_Import.new
222228
import.authStub = self
223229
import.properties = {"Name"=> "SDK Generated Import #{DateTime.now.to_s}"}
224230
import.properties["CustomerKey"] = SecureRandom.uuid
@@ -231,16 +237,16 @@ def CreateAndStartListImport(listId,fileName)
231237
import.properties["RetrieveFileTransferLocation"] = {"CustomerKey"=>"ExactTarget Enhanced FTP"}
232238
import.properties["UpdateType"] = "AddAndUpdate"
233239
result = import.post
234-
235-
if result.status then
236-
return import.start
240+
241+
if result.status then
242+
return import.start
237243
else
238244
raise "Unable to create import definition due to: #{result.results[0][:status_message]}"
239-
end
240-
end
241-
245+
end
246+
end
247+
242248
def CreateAndStartDataExtensionImport(dataExtensionCustomerKey, fileName, overwrite)
243-
import = ET_Import.new
249+
import = ET_Import.new
244250
import.authStub = self
245251
import.properties = {"Name"=> "SDK Generated Import #{DateTime.now.to_s}"}
246252
import.properties["CustomerKey"] = SecureRandom.uuid
@@ -253,30 +259,30 @@ def CreateAndStartDataExtensionImport(dataExtensionCustomerKey, fileName, overwr
253259
import.properties["RetrieveFileTransferLocation"] = {"CustomerKey"=>"ExactTarget Enhanced FTP"}
254260
if overwrite then
255261
import.properties["UpdateType"] = "Overwrite"
256-
else
262+
else
257263
import.properties["UpdateType"] = "AddAndUpdate"
258-
end
264+
end
259265
result = import.post
260-
261-
if result.status then
262-
return import.start
266+
267+
if result.status then
268+
return import.start
263269
else
264270
raise "Unable to create import definition due to: #{result.results[0][:status_message]}"
265-
end
266-
end
267-
271+
end
272+
end
273+
268274
def CreateProfileAttributes(allAttributes)
269-
attrs = ET_ProfileAttribute.new
275+
attrs = ET_ProfileAttribute.new
270276
attrs.authStub = self
271277
attrs.properties = allAttributes
272278
return attrs.post
273279
end
274-
280+
275281
def CreateContentAreas(arrayOfContentAreas)
276282
postC = ET_ContentArea.new
277283
postC.authStub = self
278284
postC.properties = arrayOfContentAreas
279-
sendResponse = postC.post
285+
sendResponse = postC.post
280286
return sendResponse
281287
end
282288
end

marketingcloudsdk.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
2525
spec.add_development_dependency "guard-rspec",'~> 2.0'
2626

2727
spec.add_dependency "savon", "2.2.0"
28-
spec.add_dependency "json", "~>1.8",">= 1.8.1"
29-
spec.add_dependency "jwt", "~>1.0",">= 1.0.0"
28+
spec.add_dependency "json", "~>1.8",">= 1.8.1"
29+
spec.add_dependency "jwt", "~>1.0",">= 1.5.4"
3030
end

0 commit comments

Comments
 (0)