sfmc-fuelsdk-ruby 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +39 -39
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
  4. data/.gitignore +29 -29
  5. data/Gemfile +3 -3
  6. data/Gemfile.lock +104 -92
  7. data/Guardfile +8 -8
  8. data/LICENSE.md +13 -13
  9. data/README.md +200 -194
  10. data/Rakefile +1 -1
  11. data/lib/marketingcloudsdk.rb +74 -74
  12. data/lib/marketingcloudsdk/client.rb +395 -395
  13. data/lib/marketingcloudsdk/http_request.rb +118 -118
  14. data/lib/marketingcloudsdk/objects.rb +757 -757
  15. data/lib/marketingcloudsdk/rest.rb +118 -118
  16. data/lib/marketingcloudsdk/soap.rb +296 -296
  17. data/lib/marketingcloudsdk/targeting.rb +99 -99
  18. data/lib/marketingcloudsdk/utils.rb +47 -47
  19. data/lib/marketingcloudsdk/version.rb +39 -39
  20. data/lib/new.rb +1240 -1240
  21. data/marketingcloudsdk.gemspec +30 -30
  22. data/samples/sample-AddSubscriberToList.rb +56 -56
  23. data/samples/sample-CreateAndStartDataExtensionImport.rb +29 -29
  24. data/samples/sample-CreateAndStartListImport.rb +27 -27
  25. data/samples/sample-CreateContentAreas.rb +48 -48
  26. data/samples/sample-CreateDataExtensions.rb +54 -54
  27. data/samples/sample-CreateProfileAttributes.rb +48 -48
  28. data/samples/sample-SendEmailToDataExtension.rb +23 -23
  29. data/samples/sample-SendEmailToList.rb +23 -23
  30. data/samples/sample-SendTriggeredSends.rb +30 -30
  31. data/samples/sample-bounceevent.rb +70 -70
  32. data/samples/sample-campaign.rb +211 -211
  33. data/samples/sample-clickevent.rb +71 -71
  34. data/samples/sample-contentarea.rb +122 -122
  35. data/samples/sample-dataextension.rb +209 -209
  36. data/samples/sample-directverb.rb +54 -54
  37. data/samples/sample-email.rb +122 -122
  38. data/samples/sample-email.senddefinition.rb +134 -134
  39. data/samples/sample-folder.rb +143 -143
  40. data/samples/sample-import.rb +103 -103
  41. data/samples/sample-list.rb +105 -105
  42. data/samples/sample-list.subscriber.rb +97 -97
  43. data/samples/sample-openevent.rb +70 -70
  44. data/samples/sample-profileattribute.rb +56 -56
  45. data/samples/sample-sentevent.rb +70 -70
  46. data/samples/sample-subscriber.rb +135 -135
  47. data/samples/sample-triggeredsend.rb +129 -129
  48. data/samples/sample-unsubevent.rb +72 -72
  49. data/samples/sample_helper.rb.template +10 -10
  50. data/spec/client_spec.rb +416 -416
  51. data/spec/default_values_fallback_spec.rb +30 -30
  52. data/spec/helper_funcs_spec.rb +11 -11
  53. data/spec/http_request_spec.rb +61 -61
  54. data/spec/objects_helper_spec.rb +32 -32
  55. data/spec/objects_spec.rb +484 -484
  56. data/spec/public_or_web_integration_credentials.rb.template +11 -11
  57. data/spec/rest_spec.rb +48 -48
  58. data/spec/soap_spec.rb +140 -140
  59. data/spec/spec_helper.rb +14 -14
  60. data/spec/targeting_spec.rb +44 -44
  61. metadata +14 -27
@@ -1,129 +1,129 @@
1
- require 'marketingcloudsdk'
2
- require 'securerandom'
3
- require_relative 'sample_helper'
4
-
5
- begin
6
- stubObj = MarketingCloudSDK::Client.new auth
7
-
8
- # Get all TriggeredSendDefinitions
9
- p '>>> Get all TriggeredSendDefinitions'
10
- getTS = MarketingCloudSDK::TriggeredSend.new
11
- getTS.authStub = stubObj
12
- getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
13
- getResponse = getTS.get
14
- p 'Retrieve Status: ' + getResponse.status.to_s
15
- p 'Code: ' + getResponse.code.to_s
16
- p 'Message: ' + getResponse.message.to_s
17
- p 'MoreResults: ' + getResponse.more?.to_s
18
- p 'Results Count: ' + getResponse.results.length.to_s
19
- #p 'Results: ' + getResponse.results.to_s
20
- raise 'Failure retrieving triggersend' unless getResponse.success?
21
-
22
- # Generate a unique identifier for the TriggeredSend customer key since they cannot be re-used even after deleted
23
- TSNameForCreateThenDelete = SecureRandom.uuid
24
-
25
- # Create a TriggeredSend Definition
26
- p '>>> Create a TriggeredSend Definition'
27
- postTrig = MarketingCloudSDK::TriggeredSend.new
28
- postTrig.authStub = stubObj
29
- postTrig.props = {'CustomerKey' => TSNameForCreateThenDelete,'Name' => TSNameForCreateThenDelete, 'Email' => {"ID"=>"3113962"}, "SendClassification"=> {"CustomerKey"=> "2240"}}
30
- postResponse = postTrig.post
31
- p 'Post Status: ' + postResponse.status.to_s
32
- p 'Code: ' + postResponse.code.to_s
33
- p 'Message: ' + postResponse.message.to_s
34
- p 'Result Count: ' + postResponse.results.length.to_s
35
- p 'Results: ' + postResponse.results.inspect
36
- raise 'Failure creating triggersend' unless postResponse.success?
37
-
38
- # Specify the name of a TriggeredSend that was setup for testing
39
- # Do not use a production Triggered Send Definition
40
-
41
- NameOfTestTS = "TEXTEXT"
42
-
43
- # Pause a TriggeredSend
44
- p '>>> Pause a TriggeredSend'
45
- patchTrig = MarketingCloudSDK::TriggeredSend.new
46
- patchTrig.authStub = stubObj
47
- patchTrig.props = {"CustomerKey" => NameOfTestTS, "TriggeredSendStatus" =>"Inactive"}
48
- patchResponse = patchTrig.patch
49
- p 'Patch Status: ' + patchResponse.status.to_s
50
- p 'Code: ' + patchResponse.code.to_s
51
- p 'Message: ' + patchResponse.message.to_s
52
- p 'Result Count: ' + patchResponse.results.length.to_s
53
- p 'Results: ' + patchResponse.results.inspect
54
- raise 'Failure updating triggersend' unless patchResponse.success?
55
-
56
- # Retrieve Single TriggeredSend
57
- p '>>> Retrieve Single TriggeredSend'
58
- getTS = MarketingCloudSDK::TriggeredSend.new
59
- getTS.authStub = stubObj
60
- getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
61
- getTS.filter = {'Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => NameOfTestTS}
62
- getResponse = getTS.get
63
- p 'Retrieve Status: ' + getResponse.status.to_s
64
- p 'Code: ' + getResponse.code.to_s
65
- p 'Message: ' + getResponse.message.to_s
66
- p 'MoreResults: ' + getResponse.more?.to_s
67
- p 'Results Count: ' + getResponse.results.length.to_s
68
- p 'Results: ' + getResponse.results.to_s
69
- raise 'Failure retrieving triggersend' unless getResponse.success?
70
-
71
- # Start a TriggeredSend by setting to Active
72
- p '>>> Start a TriggeredSend by setting to Active'
73
- patchTrig = MarketingCloudSDK::TriggeredSend.new
74
- patchTrig.authStub = stubObj
75
- patchTrig.props = {"CustomerKey" => NameOfTestTS, "TriggeredSendStatus" =>"Active"}
76
- patchResponse = patchTrig.patch
77
- p 'Patch Status: ' + patchResponse.status.to_s
78
- p 'Code: ' + patchResponse.code.to_s
79
- p 'Message: ' + patchResponse.message.to_s
80
- p 'Result Count: ' + patchResponse.results.length.to_s
81
- p 'Results: ' + patchResponse.results.inspect
82
- raise 'Failure updating triggersend' unless patchResponse.success?
83
-
84
- # Retrieve Single TriggeredSend After setting back to active
85
- p '>>> Retrieve Single TriggeredSend After setting back to active'
86
- getTS = MarketingCloudSDK::TriggeredSend.new
87
- getTS.authStub = stubObj
88
- getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
89
- getTS.filter = {'Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => NameOfTestTS}
90
- getResponse = getTS.get
91
- p 'Retrieve Status: ' + getResponse.status.to_s
92
- p 'Code: ' + getResponse.code.to_s
93
- p 'Message: ' + getResponse.message.to_s
94
- p 'MoreResults: ' + getResponse.more?.to_s
95
- p 'Results Count: ' + getResponse.results.length.to_s
96
- p 'Results: ' + getResponse.results.to_s
97
- raise 'Failure retrieving triggersend' unless getResponse.success?
98
-
99
- # Send an email with TriggeredSend
100
- p '>>> Send an email with TriggeredSend'
101
- sendTrig = MarketingCloudSDK::TriggeredSend.new
102
- sendTrig.authStub = stubObj
103
- sendTrig.props = [{"CustomerKey" => NameOfTestTS, "Subscribers" => {"EmailAddress"=>"testing@bh.exacttarget.com", "SubscriberKey" => "testing@bh.exacttarget.com"}}]
104
- sendResponse = sendTrig.send
105
- p 'Send Status: ' + sendResponse.status.to_s
106
- p 'Code: ' + sendResponse.code.to_s
107
- p 'Message: ' + sendResponse.message.to_s
108
- p 'Result Count: ' + sendResponse.results.length.to_s
109
- p 'Results: ' + sendResponse.results.inspect
110
- raise 'Failure sending triggersend' unless sendResponse.success?
111
-
112
-
113
- # Delete a TriggeredSend Definition
114
- p '>>> Delete a TriggeredSend Definition '
115
- deleteTrig = MarketingCloudSDK::TriggeredSend.new
116
- deleteTrig.authStub = stubObj
117
- deleteTrig.props = {'CustomerKey' => TSNameForCreateThenDelete}
118
- deleteResponse = deleteTrig.delete
119
- p 'Delete Status: ' + deleteResponse.status.to_s
120
- p 'Code: ' + deleteResponse.code.to_s
121
- p 'Message: ' + deleteResponse.message.to_s
122
- p 'Result Count: ' + deleteResponse.results.length.to_s
123
- p 'Results: ' + deleteResponse.results.inspect
124
- raise 'Failure deleting triggersend' unless deleteResponse.success?
125
-
126
- rescue => e
127
- p "Caught exception: #{e.message}"
128
- p e.backtrace
129
- end
1
+ require 'marketingcloudsdk'
2
+ require 'securerandom'
3
+ require_relative 'sample_helper'
4
+
5
+ begin
6
+ stubObj = MarketingCloudSDK::Client.new auth
7
+
8
+ # Get all TriggeredSendDefinitions
9
+ p '>>> Get all TriggeredSendDefinitions'
10
+ getTS = MarketingCloudSDK::TriggeredSend.new
11
+ getTS.authStub = stubObj
12
+ getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
13
+ getResponse = getTS.get
14
+ p 'Retrieve Status: ' + getResponse.status.to_s
15
+ p 'Code: ' + getResponse.code.to_s
16
+ p 'Message: ' + getResponse.message.to_s
17
+ p 'MoreResults: ' + getResponse.more?.to_s
18
+ p 'Results Count: ' + getResponse.results.length.to_s
19
+ #p 'Results: ' + getResponse.results.to_s
20
+ raise 'Failure retrieving triggersend' unless getResponse.success?
21
+
22
+ # Generate a unique identifier for the TriggeredSend customer key since they cannot be re-used even after deleted
23
+ TSNameForCreateThenDelete = SecureRandom.uuid
24
+
25
+ # Create a TriggeredSend Definition
26
+ p '>>> Create a TriggeredSend Definition'
27
+ postTrig = MarketingCloudSDK::TriggeredSend.new
28
+ postTrig.authStub = stubObj
29
+ postTrig.props = {'CustomerKey' => TSNameForCreateThenDelete,'Name' => TSNameForCreateThenDelete, 'Email' => {"ID"=>"3113962"}, "SendClassification"=> {"CustomerKey"=> "2240"}}
30
+ postResponse = postTrig.post
31
+ p 'Post Status: ' + postResponse.status.to_s
32
+ p 'Code: ' + postResponse.code.to_s
33
+ p 'Message: ' + postResponse.message.to_s
34
+ p 'Result Count: ' + postResponse.results.length.to_s
35
+ p 'Results: ' + postResponse.results.inspect
36
+ raise 'Failure creating triggersend' unless postResponse.success?
37
+
38
+ # Specify the name of a TriggeredSend that was setup for testing
39
+ # Do not use a production Triggered Send Definition
40
+
41
+ NameOfTestTS = "TEXTEXT"
42
+
43
+ # Pause a TriggeredSend
44
+ p '>>> Pause a TriggeredSend'
45
+ patchTrig = MarketingCloudSDK::TriggeredSend.new
46
+ patchTrig.authStub = stubObj
47
+ patchTrig.props = {"CustomerKey" => NameOfTestTS, "TriggeredSendStatus" =>"Inactive"}
48
+ patchResponse = patchTrig.patch
49
+ p 'Patch Status: ' + patchResponse.status.to_s
50
+ p 'Code: ' + patchResponse.code.to_s
51
+ p 'Message: ' + patchResponse.message.to_s
52
+ p 'Result Count: ' + patchResponse.results.length.to_s
53
+ p 'Results: ' + patchResponse.results.inspect
54
+ raise 'Failure updating triggersend' unless patchResponse.success?
55
+
56
+ # Retrieve Single TriggeredSend
57
+ p '>>> Retrieve Single TriggeredSend'
58
+ getTS = MarketingCloudSDK::TriggeredSend.new
59
+ getTS.authStub = stubObj
60
+ getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
61
+ getTS.filter = {'Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => NameOfTestTS}
62
+ getResponse = getTS.get
63
+ p 'Retrieve Status: ' + getResponse.status.to_s
64
+ p 'Code: ' + getResponse.code.to_s
65
+ p 'Message: ' + getResponse.message.to_s
66
+ p 'MoreResults: ' + getResponse.more?.to_s
67
+ p 'Results Count: ' + getResponse.results.length.to_s
68
+ p 'Results: ' + getResponse.results.to_s
69
+ raise 'Failure retrieving triggersend' unless getResponse.success?
70
+
71
+ # Start a TriggeredSend by setting to Active
72
+ p '>>> Start a TriggeredSend by setting to Active'
73
+ patchTrig = MarketingCloudSDK::TriggeredSend.new
74
+ patchTrig.authStub = stubObj
75
+ patchTrig.props = {"CustomerKey" => NameOfTestTS, "TriggeredSendStatus" =>"Active"}
76
+ patchResponse = patchTrig.patch
77
+ p 'Patch Status: ' + patchResponse.status.to_s
78
+ p 'Code: ' + patchResponse.code.to_s
79
+ p 'Message: ' + patchResponse.message.to_s
80
+ p 'Result Count: ' + patchResponse.results.length.to_s
81
+ p 'Results: ' + patchResponse.results.inspect
82
+ raise 'Failure updating triggersend' unless patchResponse.success?
83
+
84
+ # Retrieve Single TriggeredSend After setting back to active
85
+ p '>>> Retrieve Single TriggeredSend After setting back to active'
86
+ getTS = MarketingCloudSDK::TriggeredSend.new
87
+ getTS.authStub = stubObj
88
+ getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
89
+ getTS.filter = {'Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => NameOfTestTS}
90
+ getResponse = getTS.get
91
+ p 'Retrieve Status: ' + getResponse.status.to_s
92
+ p 'Code: ' + getResponse.code.to_s
93
+ p 'Message: ' + getResponse.message.to_s
94
+ p 'MoreResults: ' + getResponse.more?.to_s
95
+ p 'Results Count: ' + getResponse.results.length.to_s
96
+ p 'Results: ' + getResponse.results.to_s
97
+ raise 'Failure retrieving triggersend' unless getResponse.success?
98
+
99
+ # Send an email with TriggeredSend
100
+ p '>>> Send an email with TriggeredSend'
101
+ sendTrig = MarketingCloudSDK::TriggeredSend.new
102
+ sendTrig.authStub = stubObj
103
+ sendTrig.props = [{"CustomerKey" => NameOfTestTS, "Subscribers" => {"EmailAddress"=>"testing@bh.exacttarget.com", "SubscriberKey" => "testing@bh.exacttarget.com"}}]
104
+ sendResponse = sendTrig.send
105
+ p 'Send Status: ' + sendResponse.status.to_s
106
+ p 'Code: ' + sendResponse.code.to_s
107
+ p 'Message: ' + sendResponse.message.to_s
108
+ p 'Result Count: ' + sendResponse.results.length.to_s
109
+ p 'Results: ' + sendResponse.results.inspect
110
+ raise 'Failure sending triggersend' unless sendResponse.success?
111
+
112
+
113
+ # Delete a TriggeredSend Definition
114
+ p '>>> Delete a TriggeredSend Definition '
115
+ deleteTrig = MarketingCloudSDK::TriggeredSend.new
116
+ deleteTrig.authStub = stubObj
117
+ deleteTrig.props = {'CustomerKey' => TSNameForCreateThenDelete}
118
+ deleteResponse = deleteTrig.delete
119
+ p 'Delete Status: ' + deleteResponse.status.to_s
120
+ p 'Code: ' + deleteResponse.code.to_s
121
+ p 'Message: ' + deleteResponse.message.to_s
122
+ p 'Result Count: ' + deleteResponse.results.length.to_s
123
+ p 'Results: ' + deleteResponse.results.inspect
124
+ raise 'Failure deleting triggersend' unless deleteResponse.success?
125
+
126
+ rescue => e
127
+ p "Caught exception: #{e.message}"
128
+ p e.backtrace
129
+ end
@@ -1,72 +1,72 @@
1
- require 'marketingcloudsdk'
2
- require_relative 'sample_helper'
3
-
4
- begin
5
- stubObj = MarketingCloudSDK::Client.new auth
6
-
7
- ## Modify the date below to reduce the number of results returned from the request
8
- ## Setting this too far in the past could result in a very large response size
9
- retrieveDate = '2013-01-15T13:00:00.000'
10
-
11
- p '>>> Retrieve Filtered UnsubEvents with GetMoreResults'
12
- getUnsubEvent = MarketingCloudSDK::UnsubEvent.new()
13
- getUnsubEvent.authStub = stubObj
14
- getUnsubEvent.props = ["SendID","SubscriberKey","EventDate",
15
- "Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
16
- getUnsubEvent.filter = {'Property' => 'EventDate',
17
- 'SimpleOperator' => 'greaterThan','DateValue' => retrieveDate}
18
- getResponse = getUnsubEvent.get
19
- p 'Retrieve Status: ' + getResponse.status.to_s
20
- p 'Code: ' + getResponse.code.to_s
21
- p 'Message: ' + getResponse.message.to_s
22
- p 'MoreResults: ' + getResponse.more?.to_s
23
- p 'RequestID: ' + getResponse.request_id.to_s
24
- p 'Results Length: ' + getResponse.results.length.to_s
25
- # Since this could potentially return a large number of results, we do not want to print the results
26
- #p 'Results: ' + getResponse.results.to_s
27
- raise 'Failure retrieving unsub events' unless getResponse.success?
28
-
29
- while getResponse.more? do
30
- p '>>> Continue Retrieve Filtered UnsubEvents with GetMoreResults'
31
- getResponse = getUnsubEvent.continue
32
- p 'Retrieve Status: ' + getResponse.status.to_s
33
- p 'Code: ' + getResponse.code.to_s
34
- p 'Message: ' + getResponse.message.to_s
35
- p 'MoreResults: ' + getResponse.more?.to_s
36
- p 'RequestID: ' + getResponse.request_id.to_s
37
- p 'Results Length: ' + getResponse.results.length.to_s
38
- end
39
-
40
- # The following request could potentially bring back large amounts of data if run against a production account
41
- =begin
42
- p '>>> Retrieve All UnsubEvents with GetMoreResults'
43
- getUnsubEvent = MarketingCloudSDK::UnsubEvent.new()
44
- getUnsubEvent.authStub = stubObj
45
- getUnsubEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
46
- getResponse = getUnsubEvent.get
47
- p 'Retrieve Status: ' + getResponse.status.to_s
48
- p 'Code: ' + getResponse.code.to_s
49
- p 'Message: ' + getResponse.message.to_s
50
- p 'MoreResults: ' + getResponse.more?.to_s
51
- p 'RequestID: ' + getResponse.request_id.to_s
52
- p 'Results Length: ' + getResponse.results.length.to_s
53
- # Since this could potentially return a large number of results, we do not want to print the results
54
- #p 'Results: ' + getResponse.results.to_s
55
-
56
- while getResponse.more? do
57
- p '>>> Continue Retrieve All UnsubEvents with GetMoreResults'
58
- getResponse = getUnsubEvent.continue
59
- p 'Retrieve Status: ' + getResponse.status.to_s
60
- p 'Code: ' + getResponse.code.to_s
61
- p 'Message: ' + getResponse.message.to_s
62
- p 'MoreResults: ' + getResponse.more?.to_s
63
- p 'RequestID: ' + getResponse.request_id.to_s
64
- p 'Results Length: ' + getResponse.results.length.to_s
65
- end
66
- =end
67
-
68
- rescue => e
69
- p "Caught exception: #{e.message}"
70
- p e.backtrace
71
- end
72
-
1
+ require 'marketingcloudsdk'
2
+ require_relative 'sample_helper'
3
+
4
+ begin
5
+ stubObj = MarketingCloudSDK::Client.new auth
6
+
7
+ ## Modify the date below to reduce the number of results returned from the request
8
+ ## Setting this too far in the past could result in a very large response size
9
+ retrieveDate = '2013-01-15T13:00:00.000'
10
+
11
+ p '>>> Retrieve Filtered UnsubEvents with GetMoreResults'
12
+ getUnsubEvent = MarketingCloudSDK::UnsubEvent.new()
13
+ getUnsubEvent.authStub = stubObj
14
+ getUnsubEvent.props = ["SendID","SubscriberKey","EventDate",
15
+ "Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
16
+ getUnsubEvent.filter = {'Property' => 'EventDate',
17
+ 'SimpleOperator' => 'greaterThan','DateValue' => retrieveDate}
18
+ getResponse = getUnsubEvent.get
19
+ p 'Retrieve Status: ' + getResponse.status.to_s
20
+ p 'Code: ' + getResponse.code.to_s
21
+ p 'Message: ' + getResponse.message.to_s
22
+ p 'MoreResults: ' + getResponse.more?.to_s
23
+ p 'RequestID: ' + getResponse.request_id.to_s
24
+ p 'Results Length: ' + getResponse.results.length.to_s
25
+ # Since this could potentially return a large number of results, we do not want to print the results
26
+ #p 'Results: ' + getResponse.results.to_s
27
+ raise 'Failure retrieving unsub events' unless getResponse.success?
28
+
29
+ while getResponse.more? do
30
+ p '>>> Continue Retrieve Filtered UnsubEvents with GetMoreResults'
31
+ getResponse = getUnsubEvent.continue
32
+ p 'Retrieve Status: ' + getResponse.status.to_s
33
+ p 'Code: ' + getResponse.code.to_s
34
+ p 'Message: ' + getResponse.message.to_s
35
+ p 'MoreResults: ' + getResponse.more?.to_s
36
+ p 'RequestID: ' + getResponse.request_id.to_s
37
+ p 'Results Length: ' + getResponse.results.length.to_s
38
+ end
39
+
40
+ # The following request could potentially bring back large amounts of data if run against a production account
41
+ =begin
42
+ p '>>> Retrieve All UnsubEvents with GetMoreResults'
43
+ getUnsubEvent = MarketingCloudSDK::UnsubEvent.new()
44
+ getUnsubEvent.authStub = stubObj
45
+ getUnsubEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
46
+ getResponse = getUnsubEvent.get
47
+ p 'Retrieve Status: ' + getResponse.status.to_s
48
+ p 'Code: ' + getResponse.code.to_s
49
+ p 'Message: ' + getResponse.message.to_s
50
+ p 'MoreResults: ' + getResponse.more?.to_s
51
+ p 'RequestID: ' + getResponse.request_id.to_s
52
+ p 'Results Length: ' + getResponse.results.length.to_s
53
+ # Since this could potentially return a large number of results, we do not want to print the results
54
+ #p 'Results: ' + getResponse.results.to_s
55
+
56
+ while getResponse.more? do
57
+ p '>>> Continue Retrieve All UnsubEvents with GetMoreResults'
58
+ getResponse = getUnsubEvent.continue
59
+ p 'Retrieve Status: ' + getResponse.status.to_s
60
+ p 'Code: ' + getResponse.code.to_s
61
+ p 'Message: ' + getResponse.message.to_s
62
+ p 'MoreResults: ' + getResponse.more?.to_s
63
+ p 'RequestID: ' + getResponse.request_id.to_s
64
+ p 'Results Length: ' + getResponse.results.length.to_s
65
+ end
66
+ =end
67
+
68
+ rescue => e
69
+ p "Caught exception: #{e.message}"
70
+ p e.backtrace
71
+ end
72
+
@@ -1,10 +1,10 @@
1
- def auth
2
- {
3
- 'client' => {
4
- 'id' => YOURID,
5
- 'secret' => YOURSERET,
6
- 'base_api_url' => 'https://www.exacttargetapis.com',
7
- 'request_token_url' => 'https://auth.exacttargetapis.com/v1/requestToken'
8
- }
9
- }
10
- end
1
+ def auth
2
+ {
3
+ 'client' => {
4
+ 'id' => YOURID,
5
+ 'secret' => YOURSERET,
6
+ 'base_api_url' => 'https://www.exacttargetapis.com',
7
+ 'request_token_url' => 'https://auth.exacttargetapis.com/v1/requestToken'
8
+ }
9
+ }
10
+ end
data/spec/client_spec.rb CHANGED
@@ -1,416 +1,416 @@
1
- require 'spec_helper.rb'
2
- require 'public_or_web_integration_credentials'
3
-
4
- def get_test_stub
5
- {'client' => {
6
- 'use_oAuth2_authentication' => true,
7
- 'id' => 'id',
8
- 'secret' => 'secret',
9
- 'request_token_url' => 'request_token_url',
10
- 'account_id' => 'account_id',
11
- 'authorization_code' => 'authorization_code',
12
- 'redirect_URI' => 'redirect_URI'
13
- }}
14
- end
15
-
16
- describe(MarketingCloudSDK::Client) do
17
-
18
- context 'initialized' do
19
-
20
- before(:each) do
21
- allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
22
- end
23
-
24
- it 'with client parameters' do
25
- test_stub = get_test_stub
26
-
27
- client = MarketingCloudSDK::Client.new(test_stub)
28
-
29
- expect(client.use_oAuth2_authentication).to be test_stub['client']['use_oAuth2_authentication']
30
- expect(client.id).to eq test_stub['client']['id']
31
- expect(client.secret).to eq test_stub['client']['secret']
32
- expect(client.account_id).to eq test_stub['client']['account_id']
33
- expect(client.request_token_url).to eq test_stub['client']['request_token_url']
34
- end
35
-
36
- it 'with debug=true' do
37
- client = MarketingCloudSDK::Client.new(get_test_stub, true)
38
-
39
- expect(client.debug).to be true
40
- end
41
-
42
- it 'with debug=false' do
43
- client = MarketingCloudSDK::Client.new(get_test_stub, false)
44
-
45
- expect(client.debug).to be false
46
- end
47
-
48
- it 'with base_api_url set to default value if base_api_url is not set' do
49
- client = MarketingCloudSDK::Client.new(get_test_stub)
50
-
51
- expect(client.base_api_url).to eq 'https://www.exacttargetapis.com'
52
- end
53
-
54
- it 'with null/blank/empty request_token_url and use_oAuth2_authentication=true should raise exception' do
55
- expected_exception = 'request_token_url (Auth TSE) is mandatory when using OAuth2 authentication'
56
-
57
- test_stub = get_test_stub
58
-
59
- [nil, ' ', ''].each do |exception_raiser|
60
- test_stub['client']['request_token_url'] = exception_raiser
61
- expect { MarketingCloudSDK::Client.new(test_stub) }.to raise_error(expected_exception)
62
- end
63
- end
64
-
65
- it 'with SoapClient' do
66
- client = MarketingCloudSDK::Client.new(get_test_stub)
67
-
68
- expect(client).to be_kind_of MarketingCloudSDK::Soap
69
- end
70
-
71
- it 'with RestClient' do
72
- client = MarketingCloudSDK::Client.new(get_test_stub)
73
-
74
- expect(client).to be_kind_of MarketingCloudSDK::Rest
75
- end
76
-
77
- it 'with wsdl set to default value if not set in params' do
78
- client = MarketingCloudSDK::Client.new(get_test_stub)
79
-
80
- expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl'
81
- end
82
-
83
- it 'with application_type set to \'server\' if application_type is not set in params' do
84
- client = MarketingCloudSDK::Client.new(get_test_stub)
85
-
86
- expect(client.application_type).to eq 'server'
87
- end
88
-
89
- describe 'with web/public app and null/blank/empty authorization_code or redirect_URI should raise exception' do
90
- expected_exception = 'authorization_code or redirect_URI is null: For Public/Web Apps, the authorization_code and redirect_URI must be passed when instantiating Client'
91
-
92
- exception_raisers = Hash.new.tap do |h|
93
- h[nil] = 'nil'
94
- h[' '] = 'blank string'
95
- h[''] = 'empty string'
96
- end
97
-
98
- test_stub = get_test_stub
99
-
100
- ['web', 'public'].each do |app_type|
101
- [nil, ' ', ''].each do |exception_raiser|
102
- ['authorization_code', 'redirect_URI'].each do |under_test_prop|
103
-
104
- it "#{app_type} app with #{exception_raisers[exception_raiser]} #{under_test_prop} raises an exception" do
105
-
106
- test_stub['client']['application_type'] = app_type
107
- test_stub['client'][under_test_prop] = exception_raiser
108
-
109
- expect { MarketingCloudSDK::Client.new(test_stub) }.to raise_error(expected_exception)
110
- end
111
- end
112
- end
113
- end
114
- end
115
-
116
- it 'with public app and null/blank/empty id should raise exception' do
117
- expected_exception = 'id is null: id must be passed when instantiating Client'
118
-
119
- test_stub = get_test_stub
120
- test_stub['client']['application_type'] = 'public'
121
- test_stub['client']['authorization_code'] = 'authorization_code'
122
- test_stub['client']['redirect_URI'] = 'redirect_URI'
123
-
124
- [nil, ' ', ''].each do |exception_raiser|
125
- test_stub['client']['id'] = exception_raiser
126
-
127
- expect { MarketingCloudSDK::Client.new(test_stub) }.to raise_error(expected_exception)
128
- end
129
- end
130
-
131
- describe 'with web/server app and null/blank/empty id or secret should raise exception' do
132
- expected_exception = 'id and secret must pe passed when instantiating Client'
133
-
134
- exception_raisers = Hash.new.tap do |h|
135
- h[nil] = 'nil'
136
- h[' '] = 'blank string'
137
- h[''] = 'empty string'
138
- end
139
-
140
- test_stub = get_test_stub
141
- test_stub['client']['authorization_code'] = 'authorization_code'
142
- test_stub['client']['redirect_URI'] = 'redirect_URI'
143
-
144
- ['web', 'server'].each do |app_type|
145
- [nil, ' ', ''].each do |exception_raiser|
146
- ['id', 'secret'].each do |under_test_prop|
147
-
148
- it "#{app_type} app with #{exception_raisers[exception_raiser]} #{under_test_prop} raises an exception" do
149
-
150
- test_stub['client']['application_type'] = app_type
151
- test_stub['client'][under_test_prop] = exception_raiser
152
-
153
- expect { MarketingCloudSDK::Client.new(test_stub) }.to raise_error(expected_exception)
154
- end
155
- end
156
- end
157
- end
158
- end
159
-
160
- describe 'with a wsdl' do
161
-
162
- test_stub = get_test_stub
163
-
164
- let(:client) { MarketingCloudSDK::Client.new test_stub }
165
-
166
- it'creates a SoapClient' do
167
- expect(client).to be_kind_of MarketingCloudSDK::Soap
168
- end
169
-
170
- it'#wsdl returns default wsdl' do
171
- expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl'
172
- end
173
- end
174
- end
175
-
176
- context 'instance can set' do
177
-
178
- before(:each) do
179
- allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
180
- end
181
-
182
- let(:client) { MarketingCloudSDK::Client.new (get_test_stub)}
183
-
184
- it 'client id' do
185
- client.id = 'some_id'
186
-
187
- expect(client.id).to eq 'some_id'
188
- end
189
-
190
- it 'client secret' do
191
- client.secret = 'some_secret'
192
-
193
- expect(client.secret).to eq 'some_secret'
194
- end
195
-
196
- it 'refresh token' do
197
- client.refresh_token = 'some_refresh_token'
198
-
199
- expect(client.refresh_token).to eq 'some_refresh_token'
200
- end
201
-
202
- it 'debug' do
203
- client.debug = false
204
- expect(client.debug).to be false
205
-
206
- client.debug = true
207
- expect(client.debug).to be true
208
- end
209
- end
210
-
211
- describe '#jwt=' do
212
-
213
- let(:payload) {
214
- {
215
- 'request' => {
216
- 'user'=> {
217
- 'oauthToken' => 'oAuthToken',
218
- 'expiresIn' => 3600,
219
- 'internalOauthToken' => 'internalOauthToken',
220
- 'refreshToken' => 'refreshToken'
221
- },
222
- 'application'=> {
223
- 'package' => 'JustTesting'
224
- }
225
- }
226
- }
227
- }
228
-
229
- let(:sig){
230
- sig = 'signature'
231
- }
232
-
233
- let(:encoded) {
234
- JWT.encode(payload, sig)
235
- }
236
-
237
- it 'raises an exception when signature is missing' do
238
- test_stub = get_test_stub
239
- test_stub['jwt'] = encoded
240
-
241
- expect { MarketingCloudSDK::Client.new test_stub }.to raise_exception 'Require app signature to decode JWT'
242
- end
243
-
244
- describe 'decodes JWT' do
245
-
246
- before(:each) do
247
- allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
248
- end
249
-
250
- let(:sig){
251
- sig = 'signature'
252
- }
253
-
254
- let(:encoded) {
255
- JWT.encode(payload, sig)
256
- }
257
-
258
- let(:client) {
259
- test_stub = get_test_stub
260
- test_stub['client']['signature'] = sig
261
- test_stub['jwt'] = encoded
262
-
263
- MarketingCloudSDK::Client.new test_stub
264
- }
265
-
266
- it 'making auth token available to client' do
267
- expect(client.auth_token).to eq payload['request']['user']['oauthToken']
268
- end
269
-
270
- it 'making internal token available to client' do
271
- expect(client.internal_token).to eq payload['request']['user']['internalOauthToken']
272
- end
273
-
274
- it 'making refresh token available to client' do
275
- expect(client.refresh_token).to eq payload['request']['user']['refreshToken']
276
- end
277
- end
278
- end
279
-
280
- describe '#refresh_token' do
281
-
282
- before(:each) do
283
- allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
284
- end
285
-
286
- let(:client) { MarketingCloudSDK::Client.new get_test_stub }
287
-
288
- it 'defaults to nil' do
289
- expect(client.refresh_token).to be_nil
290
- end
291
-
292
- it 'can be accessed' do
293
- client.refresh_token = 'refresh_token'
294
- expect(client.refresh_token).to eq 'refresh_token'
295
- end
296
- end
297
-
298
- context 'authentication payload' do
299
-
300
- before(:each) do
301
- allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
302
- end
303
-
304
- it 'should have public app attributes' do
305
- test_stub = get_test_stub
306
- test_stub['client']['application_type'] = 'public'
307
-
308
- client = MarketingCloudSDK::Client.new(test_stub)
309
-
310
- payload = client.createPayload
311
-
312
- expect(client.id).to eq payload['client_id']
313
- expect(client.redirect_URI).to eq payload['redirect_uri']
314
- expect(client.authorization_code).to eq payload['code']
315
- expect('authorization_code').to eq payload['grant_type']
316
- end
317
-
318
- it 'should not have client secret for public app' do
319
- test_stub = get_test_stub
320
- test_stub['client']['application_type'] = 'public'
321
-
322
- client = MarketingCloudSDK::Client.new(test_stub)
323
-
324
- payload = client.createPayload
325
-
326
- expect(payload.key?('client_secret')).to be false
327
- end
328
-
329
- it 'should have web app attributes' do
330
- test_stub = get_test_stub
331
- test_stub['client']['application_type'] = 'web'
332
-
333
- client = MarketingCloudSDK::Client.new(test_stub)
334
-
335
- payload = client.createPayload
336
-
337
- expect('authorization_code').to eq payload['grant_type']
338
- expect(client.id).to eq payload['client_id']
339
- expect(client.secret).to eq payload['client_secret']
340
- expect(client.redirect_URI).to eq payload['redirect_uri']
341
- expect(client.authorization_code).to eq payload['code']
342
- end
343
-
344
- it 'should have server attributes' do
345
- test_stub = get_test_stub
346
- test_stub['client']['application_type'] = 'server'
347
-
348
- client = MarketingCloudSDK::Client.new(test_stub)
349
-
350
- payload = client.createPayload
351
-
352
- expect('client_credentials').to eq payload['grant_type']
353
- expect(client.id).to eq payload['client_id']
354
- expect(client.secret).to eq payload['client_secret']
355
- end
356
-
357
- it 'should not have code and redirect_uri for server app' do
358
- test_stub = get_test_stub
359
- test_stub['client']['application_type'] = 'server'
360
-
361
- client = MarketingCloudSDK::Client.new(test_stub)
362
-
363
- payload = client.createPayload
364
-
365
- expect(payload.key?('code')).to be false
366
- expect(payload.key?('redirect_uri')).to be false
367
- end
368
-
369
- it 'should have refresh_token attribute when refresh_token is not null/blank/empty on client' do
370
- test_stub = get_test_stub
371
- test_stub['refresh_token'] = 'refresh_token'
372
- test_stub['client']['application_type'] = 'public'
373
-
374
- client = MarketingCloudSDK::Client.new(test_stub)
375
-
376
- payload = client.createPayload
377
-
378
- expect('refresh_token').to eq payload['grant_type']
379
- expect(client.refresh_token).to eq payload['refresh_token']
380
- end
381
- end
382
-
383
- context 'for public and web integrations, access_token and refresh_token' do
384
- # Test expects a Public/Web App integration config in spec/public_or_web_integration_credentials.rb
385
- it 'should differ if refresh token is enforced' do
386
-
387
- client = MarketingCloudSDK::Client.new(auth)
388
-
389
- auth_token1 = client.access_token
390
- refresh_token1 = client.refresh_token
391
-
392
- client.refreshWithOAuth2(true)
393
-
394
- auth_token2 = client.access_token
395
- refresh_token2 = client.refresh_token
396
-
397
- expect(auth_token1).not_to eq(auth_token2)
398
- expect(refresh_token1).not_to eq(refresh_token2)
399
- end
400
- end
401
-
402
- describe 'includes HTTPRequest' do
403
-
404
- before(:each) do
405
- allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
406
- end
407
-
408
- subject { MarketingCloudSDK::Client.new get_test_stub}
409
-
410
- it { should respond_to(:get) }
411
- it { should respond_to(:post) }
412
- it { should respond_to(:patch) }
413
- it { should respond_to(:delete) }
414
-
415
- end
416
- end
1
+ require 'spec_helper.rb'
2
+ require 'public_or_web_integration_credentials'
3
+
4
+ def get_test_stub
5
+ {'client' => {
6
+ 'use_oAuth2_authentication' => true,
7
+ 'id' => 'id',
8
+ 'secret' => 'secret',
9
+ 'request_token_url' => 'request_token_url',
10
+ 'account_id' => 'account_id',
11
+ 'authorization_code' => 'authorization_code',
12
+ 'redirect_URI' => 'redirect_URI'
13
+ }}
14
+ end
15
+
16
+ describe(MarketingCloudSDK::Client) do
17
+
18
+ context 'initialized' do
19
+
20
+ before(:each) do
21
+ allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
22
+ end
23
+
24
+ it 'with client parameters' do
25
+ test_stub = get_test_stub
26
+
27
+ client = MarketingCloudSDK::Client.new(test_stub)
28
+
29
+ expect(client.use_oAuth2_authentication).to be test_stub['client']['use_oAuth2_authentication']
30
+ expect(client.id).to eq test_stub['client']['id']
31
+ expect(client.secret).to eq test_stub['client']['secret']
32
+ expect(client.account_id).to eq test_stub['client']['account_id']
33
+ expect(client.request_token_url).to eq test_stub['client']['request_token_url']
34
+ end
35
+
36
+ it 'with debug=true' do
37
+ client = MarketingCloudSDK::Client.new(get_test_stub, true)
38
+
39
+ expect(client.debug).to be true
40
+ end
41
+
42
+ it 'with debug=false' do
43
+ client = MarketingCloudSDK::Client.new(get_test_stub, false)
44
+
45
+ expect(client.debug).to be false
46
+ end
47
+
48
+ it 'with base_api_url set to default value if base_api_url is not set' do
49
+ client = MarketingCloudSDK::Client.new(get_test_stub)
50
+
51
+ expect(client.base_api_url).to eq 'https://www.exacttargetapis.com'
52
+ end
53
+
54
+ it 'with null/blank/empty request_token_url and use_oAuth2_authentication=true should raise exception' do
55
+ expected_exception = 'request_token_url (Auth TSE) is mandatory when using OAuth2 authentication'
56
+
57
+ test_stub = get_test_stub
58
+
59
+ [nil, ' ', ''].each do |exception_raiser|
60
+ test_stub['client']['request_token_url'] = exception_raiser
61
+ expect { MarketingCloudSDK::Client.new(test_stub) }.to raise_error(expected_exception)
62
+ end
63
+ end
64
+
65
+ it 'with SoapClient' do
66
+ client = MarketingCloudSDK::Client.new(get_test_stub)
67
+
68
+ expect(client).to be_kind_of MarketingCloudSDK::Soap
69
+ end
70
+
71
+ it 'with RestClient' do
72
+ client = MarketingCloudSDK::Client.new(get_test_stub)
73
+
74
+ expect(client).to be_kind_of MarketingCloudSDK::Rest
75
+ end
76
+
77
+ it 'with wsdl set to default value if not set in params' do
78
+ client = MarketingCloudSDK::Client.new(get_test_stub)
79
+
80
+ expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl'
81
+ end
82
+
83
+ it 'with application_type set to \'server\' if application_type is not set in params' do
84
+ client = MarketingCloudSDK::Client.new(get_test_stub)
85
+
86
+ expect(client.application_type).to eq 'server'
87
+ end
88
+
89
+ describe 'with web/public app and null/blank/empty authorization_code or redirect_URI should raise exception' do
90
+ expected_exception = 'authorization_code or redirect_URI is null: For Public/Web Apps, the authorization_code and redirect_URI must be passed when instantiating Client'
91
+
92
+ exception_raisers = Hash.new.tap do |h|
93
+ h[nil] = 'nil'
94
+ h[' '] = 'blank string'
95
+ h[''] = 'empty string'
96
+ end
97
+
98
+ test_stub = get_test_stub
99
+
100
+ ['web', 'public'].each do |app_type|
101
+ [nil, ' ', ''].each do |exception_raiser|
102
+ ['authorization_code', 'redirect_URI'].each do |under_test_prop|
103
+
104
+ it "#{app_type} app with #{exception_raisers[exception_raiser]} #{under_test_prop} raises an exception" do
105
+
106
+ test_stub['client']['application_type'] = app_type
107
+ test_stub['client'][under_test_prop] = exception_raiser
108
+
109
+ expect { MarketingCloudSDK::Client.new(test_stub) }.to raise_error(expected_exception)
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ it 'with public app and null/blank/empty id should raise exception' do
117
+ expected_exception = 'id is null: id must be passed when instantiating Client'
118
+
119
+ test_stub = get_test_stub
120
+ test_stub['client']['application_type'] = 'public'
121
+ test_stub['client']['authorization_code'] = 'authorization_code'
122
+ test_stub['client']['redirect_URI'] = 'redirect_URI'
123
+
124
+ [nil, ' ', ''].each do |exception_raiser|
125
+ test_stub['client']['id'] = exception_raiser
126
+
127
+ expect { MarketingCloudSDK::Client.new(test_stub) }.to raise_error(expected_exception)
128
+ end
129
+ end
130
+
131
+ describe 'with web/server app and null/blank/empty id or secret should raise exception' do
132
+ expected_exception = 'id and secret must pe passed when instantiating Client'
133
+
134
+ exception_raisers = Hash.new.tap do |h|
135
+ h[nil] = 'nil'
136
+ h[' '] = 'blank string'
137
+ h[''] = 'empty string'
138
+ end
139
+
140
+ test_stub = get_test_stub
141
+ test_stub['client']['authorization_code'] = 'authorization_code'
142
+ test_stub['client']['redirect_URI'] = 'redirect_URI'
143
+
144
+ ['web', 'server'].each do |app_type|
145
+ [nil, ' ', ''].each do |exception_raiser|
146
+ ['id', 'secret'].each do |under_test_prop|
147
+
148
+ it "#{app_type} app with #{exception_raisers[exception_raiser]} #{under_test_prop} raises an exception" do
149
+
150
+ test_stub['client']['application_type'] = app_type
151
+ test_stub['client'][under_test_prop] = exception_raiser
152
+
153
+ expect { MarketingCloudSDK::Client.new(test_stub) }.to raise_error(expected_exception)
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ describe 'with a wsdl' do
161
+
162
+ test_stub = get_test_stub
163
+
164
+ let(:client) { MarketingCloudSDK::Client.new test_stub }
165
+
166
+ it'creates a SoapClient' do
167
+ expect(client).to be_kind_of MarketingCloudSDK::Soap
168
+ end
169
+
170
+ it'#wsdl returns default wsdl' do
171
+ expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl'
172
+ end
173
+ end
174
+ end
175
+
176
+ context 'instance can set' do
177
+
178
+ before(:each) do
179
+ allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
180
+ end
181
+
182
+ let(:client) { MarketingCloudSDK::Client.new (get_test_stub)}
183
+
184
+ it 'client id' do
185
+ client.id = 'some_id'
186
+
187
+ expect(client.id).to eq 'some_id'
188
+ end
189
+
190
+ it 'client secret' do
191
+ client.secret = 'some_secret'
192
+
193
+ expect(client.secret).to eq 'some_secret'
194
+ end
195
+
196
+ it 'refresh token' do
197
+ client.refresh_token = 'some_refresh_token'
198
+
199
+ expect(client.refresh_token).to eq 'some_refresh_token'
200
+ end
201
+
202
+ it 'debug' do
203
+ client.debug = false
204
+ expect(client.debug).to be false
205
+
206
+ client.debug = true
207
+ expect(client.debug).to be true
208
+ end
209
+ end
210
+
211
+ describe '#jwt=' do
212
+
213
+ let(:payload) {
214
+ {
215
+ 'request' => {
216
+ 'user'=> {
217
+ 'oauthToken' => 'oAuthToken',
218
+ 'expiresIn' => 3600,
219
+ 'internalOauthToken' => 'internalOauthToken',
220
+ 'refreshToken' => 'refreshToken'
221
+ },
222
+ 'application'=> {
223
+ 'package' => 'JustTesting'
224
+ }
225
+ }
226
+ }
227
+ }
228
+
229
+ let(:sig){
230
+ sig = 'signature'
231
+ }
232
+
233
+ let(:encoded) {
234
+ JWT.encode(payload, sig)
235
+ }
236
+
237
+ it 'raises an exception when signature is missing' do
238
+ test_stub = get_test_stub
239
+ test_stub['jwt'] = encoded
240
+
241
+ expect { MarketingCloudSDK::Client.new test_stub }.to raise_exception 'Require app signature to decode JWT'
242
+ end
243
+
244
+ describe 'decodes JWT' do
245
+
246
+ before(:each) do
247
+ allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
248
+ end
249
+
250
+ let(:sig){
251
+ sig = 'signature'
252
+ }
253
+
254
+ let(:encoded) {
255
+ JWT.encode(payload, sig)
256
+ }
257
+
258
+ let(:client) {
259
+ test_stub = get_test_stub
260
+ test_stub['client']['signature'] = sig
261
+ test_stub['jwt'] = encoded
262
+
263
+ MarketingCloudSDK::Client.new test_stub
264
+ }
265
+
266
+ it 'making auth token available to client' do
267
+ expect(client.auth_token).to eq payload['request']['user']['oauthToken']
268
+ end
269
+
270
+ it 'making internal token available to client' do
271
+ expect(client.internal_token).to eq payload['request']['user']['internalOauthToken']
272
+ end
273
+
274
+ it 'making refresh token available to client' do
275
+ expect(client.refresh_token).to eq payload['request']['user']['refreshToken']
276
+ end
277
+ end
278
+ end
279
+
280
+ describe '#refresh_token' do
281
+
282
+ before(:each) do
283
+ allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
284
+ end
285
+
286
+ let(:client) { MarketingCloudSDK::Client.new get_test_stub }
287
+
288
+ it 'defaults to nil' do
289
+ expect(client.refresh_token).to be_nil
290
+ end
291
+
292
+ it 'can be accessed' do
293
+ client.refresh_token = 'refresh_token'
294
+ expect(client.refresh_token).to eq 'refresh_token'
295
+ end
296
+ end
297
+
298
+ context 'authentication payload' do
299
+
300
+ before(:each) do
301
+ allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
302
+ end
303
+
304
+ it 'should have public app attributes' do
305
+ test_stub = get_test_stub
306
+ test_stub['client']['application_type'] = 'public'
307
+
308
+ client = MarketingCloudSDK::Client.new(test_stub)
309
+
310
+ payload = client.createPayload
311
+
312
+ expect(client.id).to eq payload['client_id']
313
+ expect(client.redirect_URI).to eq payload['redirect_uri']
314
+ expect(client.authorization_code).to eq payload['code']
315
+ expect('authorization_code').to eq payload['grant_type']
316
+ end
317
+
318
+ it 'should not have client secret for public app' do
319
+ test_stub = get_test_stub
320
+ test_stub['client']['application_type'] = 'public'
321
+
322
+ client = MarketingCloudSDK::Client.new(test_stub)
323
+
324
+ payload = client.createPayload
325
+
326
+ expect(payload.key?('client_secret')).to be false
327
+ end
328
+
329
+ it 'should have web app attributes' do
330
+ test_stub = get_test_stub
331
+ test_stub['client']['application_type'] = 'web'
332
+
333
+ client = MarketingCloudSDK::Client.new(test_stub)
334
+
335
+ payload = client.createPayload
336
+
337
+ expect('authorization_code').to eq payload['grant_type']
338
+ expect(client.id).to eq payload['client_id']
339
+ expect(client.secret).to eq payload['client_secret']
340
+ expect(client.redirect_URI).to eq payload['redirect_uri']
341
+ expect(client.authorization_code).to eq payload['code']
342
+ end
343
+
344
+ it 'should have server attributes' do
345
+ test_stub = get_test_stub
346
+ test_stub['client']['application_type'] = 'server'
347
+
348
+ client = MarketingCloudSDK::Client.new(test_stub)
349
+
350
+ payload = client.createPayload
351
+
352
+ expect('client_credentials').to eq payload['grant_type']
353
+ expect(client.id).to eq payload['client_id']
354
+ expect(client.secret).to eq payload['client_secret']
355
+ end
356
+
357
+ it 'should not have code and redirect_uri for server app' do
358
+ test_stub = get_test_stub
359
+ test_stub['client']['application_type'] = 'server'
360
+
361
+ client = MarketingCloudSDK::Client.new(test_stub)
362
+
363
+ payload = client.createPayload
364
+
365
+ expect(payload.key?('code')).to be false
366
+ expect(payload.key?('redirect_uri')).to be false
367
+ end
368
+
369
+ it 'should have refresh_token attribute when refresh_token is not null/blank/empty on client' do
370
+ test_stub = get_test_stub
371
+ test_stub['refresh_token'] = 'refresh_token'
372
+ test_stub['client']['application_type'] = 'public'
373
+
374
+ client = MarketingCloudSDK::Client.new(test_stub)
375
+
376
+ payload = client.createPayload
377
+
378
+ expect('refresh_token').to eq payload['grant_type']
379
+ expect(client.refresh_token).to eq payload['refresh_token']
380
+ end
381
+ end
382
+
383
+ context 'for public and web integrations, access_token and refresh_token' do
384
+ # Test expects a Public/Web App integration config in spec/public_or_web_integration_credentials.rb
385
+ it 'should differ if refresh token is enforced' do
386
+
387
+ client = MarketingCloudSDK::Client.new(auth)
388
+
389
+ auth_token1 = client.access_token
390
+ refresh_token1 = client.refresh_token
391
+
392
+ client.refreshWithOAuth2(true)
393
+
394
+ auth_token2 = client.access_token
395
+ refresh_token2 = client.refresh_token
396
+
397
+ expect(auth_token1).not_to eq(auth_token2)
398
+ expect(refresh_token1).not_to eq(refresh_token2)
399
+ end
400
+ end
401
+
402
+ describe 'includes HTTPRequest' do
403
+
404
+ before(:each) do
405
+ allow_any_instance_of(MarketingCloudSDK::Client).to receive(:refresh).and_return(true)
406
+ end
407
+
408
+ subject { MarketingCloudSDK::Client.new get_test_stub}
409
+
410
+ it { should respond_to(:get) }
411
+ it { should respond_to(:post) }
412
+ it { should respond_to(:patch) }
413
+ it { should respond_to(:delete) }
414
+
415
+ end
416
+ end