marketingcloudsdk 1.0.0

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 (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +26 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +92 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE.md +13 -0
  7. data/README.md +130 -0
  8. data/Rakefile +1 -0
  9. data/lib/marketingcloudsdk.rb +74 -0
  10. data/lib/marketingcloudsdk/client.rb +283 -0
  11. data/lib/marketingcloudsdk/http_request.rb +113 -0
  12. data/lib/marketingcloudsdk/objects.rb +757 -0
  13. data/lib/marketingcloudsdk/rest.rb +122 -0
  14. data/lib/marketingcloudsdk/soap.rb +288 -0
  15. data/lib/marketingcloudsdk/targeting.rb +58 -0
  16. data/lib/marketingcloudsdk/utils.rb +47 -0
  17. data/lib/marketingcloudsdk/version.rb +39 -0
  18. data/lib/new.rb +1240 -0
  19. data/marketingcloudsdk.gemspec +30 -0
  20. data/samples/sample-AddSubscriberToList.rb +56 -0
  21. data/samples/sample-CreateAndStartDataExtensionImport.rb +29 -0
  22. data/samples/sample-CreateAndStartListImport.rb +27 -0
  23. data/samples/sample-CreateContentAreas.rb +48 -0
  24. data/samples/sample-CreateDataExtensions.rb +54 -0
  25. data/samples/sample-CreateProfileAttributes.rb +48 -0
  26. data/samples/sample-SendEmailToDataExtension.rb +23 -0
  27. data/samples/sample-SendEmailToList.rb +23 -0
  28. data/samples/sample-SendTriggeredSends.rb +30 -0
  29. data/samples/sample-bounceevent.rb +70 -0
  30. data/samples/sample-campaign.rb +211 -0
  31. data/samples/sample-clickevent.rb +71 -0
  32. data/samples/sample-contentarea.rb +122 -0
  33. data/samples/sample-dataextension.rb +209 -0
  34. data/samples/sample-directverb.rb +55 -0
  35. data/samples/sample-email.rb +122 -0
  36. data/samples/sample-email.senddefinition.rb +134 -0
  37. data/samples/sample-folder.rb +143 -0
  38. data/samples/sample-import.rb +104 -0
  39. data/samples/sample-list.rb +105 -0
  40. data/samples/sample-list.subscriber.rb +97 -0
  41. data/samples/sample-openevent.rb +70 -0
  42. data/samples/sample-profileattribute.rb +57 -0
  43. data/samples/sample-sentevent.rb +70 -0
  44. data/samples/sample-subscriber.rb +136 -0
  45. data/samples/sample-triggeredsend.rb +130 -0
  46. data/samples/sample-unsubevent.rb +72 -0
  47. data/samples/sample_helper.rb.template +8 -0
  48. data/spec/client_spec.rb +210 -0
  49. data/spec/helper_funcs_spec.rb +11 -0
  50. data/spec/http_request_spec.rb +36 -0
  51. data/spec/objects_helper_spec.rb +32 -0
  52. data/spec/objects_spec.rb +484 -0
  53. data/spec/rest_spec.rb +48 -0
  54. data/spec/soap_spec.rb +140 -0
  55. data/spec/spec_helper.rb +14 -0
  56. data/spec/targeting_spec.rb +39 -0
  57. metadata +260 -0
@@ -0,0 +1,136 @@
1
+ require 'fuelsdk'
2
+ require_relative 'sample_helper' # contains auth with credentials
3
+
4
+ begin
5
+ stubObj = FuelSDK::Client.new auth
6
+
7
+ # NOTE: These examples only work in accounts where the SubscriberKey functionality is not enabled
8
+ # SubscriberKey will need to be included in the props if that feature is enabled
9
+
10
+ SubscriberTestEmail = "RubySDKExample@jb.kevy.com"
11
+
12
+ # Create Subscriber
13
+ p '>>> Create Subscriber'
14
+ postSub = FuelSDK::Subscriber.new
15
+ postSub.authStub = stubObj
16
+ postSub.props = {"EmailAddress" => SubscriberTestEmail}
17
+ p '>>> Posting'
18
+ postResponse = postSub.post
19
+ p "Post Status: #{postResponse.success? ? 'Success' : 'Failure'}"
20
+ p 'Code: ' + postResponse.code.to_s
21
+ p 'Message: ' + postResponse.message.to_s
22
+ p 'Result Count: ' + postResponse.results.length.to_s
23
+ p 'Results: ' + postResponse.results.inspect
24
+
25
+ raise 'Failure creating subscriber' unless postResponse.success?
26
+
27
+ # Retrieve newly created Subscriber
28
+ p '>>> Retrieve newly created Subscriber'
29
+ getSub = FuelSDK::Subscriber.new()
30
+ getSub.authStub = stubObj
31
+ getSub.props = ["SubscriberKey", "EmailAddress", "Status"]
32
+ getSub.filter = {'Property' => 'SubscriberKey', 'SimpleOperator' => 'equals', 'Value' => SubscriberTestEmail}
33
+ getResponse = getSub.get
34
+ p "Retrieve Status: #{getResponse.success? ? 'Success' : 'Failure'}"
35
+ p 'Code: ' + getResponse.code.to_s
36
+ p 'Message: ' + getResponse.message.to_s
37
+ p 'MoreResults: ' + getResponse.more?.to_s
38
+ p 'Results Length: ' + getResponse.results.length.to_s
39
+ p 'Results: ' + getResponse.results.to_s
40
+
41
+ raise 'Failure retrieving subscriber' unless getResponse.success?
42
+
43
+ # Update Subscriber
44
+ p '>>> Update Subscriber'
45
+ patchSub = FuelSDK::Subscriber.new
46
+ patchSub.authStub = stubObj
47
+ patchSub.props = {"EmailAddress" => SubscriberTestEmail, "Status" => "Unsubscribed"}
48
+ patchResponse = patchSub.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
+
55
+ raise 'Failure updating subscriber' unless patchResponse.success?
56
+
57
+ # Retrieve Subscriber that should have status unsubscribed now
58
+ p '>>> Retrieve Subscriber that should have status unsubscribed now'
59
+ getSub = FuelSDK::Subscriber.new()
60
+ getSub.authStub = stubObj
61
+ getSub.props = ["SubscriberKey", "EmailAddress", "Status"]
62
+ getSub.filter = {'Property' => 'SubscriberKey','SimpleOperator' => 'equals','Value' => SubscriberTestEmail};
63
+ getResponse = getSub.get
64
+ p 'Retrieve Status: ' + getResponse.status.to_s
65
+ p 'Code: ' + getResponse.code.to_s
66
+ p 'Message: ' + getResponse.message.to_s
67
+ p 'MoreResults: ' + getResponse.more?.to_s
68
+ p 'Results Length: ' + getResponse.results.length.to_s
69
+ p 'Results: ' + getResponse.results.to_s
70
+
71
+ raise 'Failure retrieving subscriber' unless getResponse.success?
72
+
73
+ # Delete Subscriber
74
+ p '>>> Delete Subscriber'
75
+ deleteSub = FuelSDK::Subscriber.new()
76
+ deleteSub.authStub = stubObj
77
+ deleteSub.props = {"EmailAddress" => SubscriberTestEmail}
78
+ deleteResponse = deleteSub.delete
79
+ p 'Delete Status: ' + deleteResponse.status.to_s
80
+ p 'Code: ' + deleteResponse.code.to_s
81
+ p 'Message: ' + deleteResponse.message.to_s
82
+ p 'Results Length: ' + deleteResponse.results.length.to_s
83
+ p 'Results: ' + deleteResponse.results.to_s
84
+
85
+ raise 'Failure deleting subscriber' unless deleteResponse.success?
86
+
87
+ # Retrieve Subscriber to confirm deletion
88
+ p '>>> Retrieve Subscriber to confirm deletion'
89
+ getSub = FuelSDK::Subscriber.new()
90
+ getSub.authStub = stubObj
91
+ getSub.props = ["SubscriberKey", "EmailAddress", "Status"]
92
+ getSub.filter = {'Property' => 'SubscriberKey','SimpleOperator' => 'equals','Value' => SubscriberTestEmail};
93
+ getResponse = getSub.get
94
+ p 'Retrieve Status: ' + getResponse.status.to_s
95
+ p 'Code: ' + getResponse.code.to_s
96
+ p 'Message: ' + getResponse.message.to_s
97
+ p 'MoreResults: ' + getResponse.more?.to_s
98
+ p 'Results Length: ' + getResponse.results.length.to_s
99
+ p 'Results: ' + getResponse.results.to_s
100
+
101
+ raise 'Failure retrieving subscriber' unless getResponse.success?
102
+
103
+ =begin
104
+ # Do not run the "Retrieve All Subscribers" request for testing if you have more than 100,000 records in your account as it will take a long time to complete.
105
+
106
+ # Retrieve All Subcribers with GetMoreResults
107
+ p '>>> Retrieve All Subcribers with GetMoreResults'
108
+ getSub = FuelSDK::Subscriber.new()
109
+ getSub.authStub = stubObj
110
+ getSub.props = ["SubscriberKey", "EmailAddress", "Status"]
111
+ getResponse = getSub.get
112
+ p 'Retrieve Status: ' + getResponse.status.to_s
113
+ p 'Code: ' + getResponse.code.to_s
114
+ p 'Message: ' + getResponse.message.to_s
115
+ p 'MoreResults: ' + getResponse.more?.to_s
116
+ p 'RequestID: ' + getResponse.request_id.to_s
117
+ p 'Results Length: ' + getResponse.results.length.to_s
118
+ #p 'Results: ' + getResponse.results.to_s
119
+
120
+ while getResponse.more? do
121
+ p '>>> Continue Retrieve All Subcribers with GetMoreResults'
122
+ getResponse.continue
123
+ p 'Retrieve Status: ' + getResponse.status.to_s
124
+ p 'Code: ' + getResponse.code.to_s
125
+ p 'Message: ' + getResponse.message.to_s
126
+ p 'MoreResults: ' + getResponse.more?.to_s
127
+ p 'RequestID: ' + getResponse.request_id.to_s
128
+ p 'Results Length: ' + getResponse.results.length.to_s
129
+ end
130
+ =end
131
+
132
+ rescue => e
133
+ p "Caught exception: #{e.message}"
134
+ p e.backtrace
135
+ end
136
+
@@ -0,0 +1,130 @@
1
+ require 'fuelsdk'
2
+ require 'securerandom'
3
+ require_relative 'sample_helper'
4
+
5
+ begin
6
+ stubObj = FuelSDK::Client.new auth
7
+
8
+ # Get all TriggeredSendDefinitions
9
+ p '>>> Get all TriggeredSendDefinitions'
10
+ getTS = FuelSDK::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 = FuelSDK::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 = FuelSDK::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 = FuelSDK::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 = FuelSDK::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 = FuelSDK::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 = FuelSDK::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 = FuelSDK::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
130
+
@@ -0,0 +1,72 @@
1
+ require 'fuelsdk'
2
+ require_relative 'sample_helper'
3
+
4
+ begin
5
+ stubObj = FuelSDK::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 = FuelSDK::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 = FuelSDK::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
+
@@ -0,0 +1,8 @@
1
+ def auth
2
+ {
3
+ 'client' => {
4
+ 'id' => YOURID,
5
+ 'secret' => YOURSERET
6
+ }
7
+ }
8
+ end
@@ -0,0 +1,210 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe MarketingCloudSDK::Client do
4
+
5
+ context 'initialized' do
6
+
7
+ it 'with client parameters' do
8
+ client = MarketingCloudSDK::Client.new 'client' => { 'id' => '1234', 'secret' => 'ssssh', 'signature' => 'hancock' }
9
+ expect(client.secret).to eq 'ssssh'
10
+ expect(client.id).to eq '1234'
11
+ expect(client.signature).to eq 'hancock'
12
+ end
13
+
14
+ it 'with debug=true' do
15
+ client = MarketingCloudSDK::Client.new({}, true)
16
+ expect(client.debug).to be_true
17
+ end
18
+
19
+ it 'with debug=false' do
20
+ client = MarketingCloudSDK::Client.new({}, false)
21
+ expect(client.debug).to be_false
22
+ end
23
+
24
+ it 'sets the request_token url to parameter if it exists' do
25
+ client = MarketingCloudSDK::Client.new({'request_token_url' => 'fake/url'}, false)
26
+ expect(client.request_token_url).to eq 'fake/url'
27
+ end
28
+
29
+ it 'sets the request_token url to a default if it does not exist' do
30
+ client = MarketingCloudSDK::Client.new({}, false)
31
+ expect(client.request_token_url).to eq 'https://auth.exacttargetapis.com/v1/requestToken'
32
+ end
33
+
34
+ it 'creates SoapClient' do
35
+ client = MarketingCloudSDK::Client.new
36
+ expect(client).to be_kind_of MarketingCloudSDK::Soap
37
+ end
38
+
39
+ it '#wsdl defaults to https://webservice.exacttarget.com/etframework.wsdl' do
40
+ client = MarketingCloudSDK::Client.new
41
+ expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl'
42
+ end
43
+
44
+ it 'creates RestClient' do
45
+ client = MarketingCloudSDK::Client.new
46
+ expect(client).to be_kind_of MarketingCloudSDK::Rest
47
+ end
48
+
49
+ describe 'with a wsdl' do
50
+
51
+ let(:client) { MarketingCloudSDK::Client.new 'defaultwsdl' => 'somewsdl' }
52
+
53
+ it'creates a SoapClient' do
54
+ expect(client).to be_kind_of MarketingCloudSDK::Soap
55
+ end
56
+
57
+ it'#wsdl returns default wsdl' do
58
+ expect(client.wsdl).to eq 'somewsdl'
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'instance can set' do
64
+
65
+ let(:client) { MarketingCloudSDK::Client.new }
66
+
67
+ it 'client id' do
68
+ client.id = 123
69
+ expect(client.id).to eq 123
70
+ end
71
+
72
+ it 'client secret' do
73
+ client.secret = 'sssh'
74
+ expect(client.secret).to eq 'sssh'
75
+ end
76
+
77
+ it 'refresh token' do
78
+ client.refresh_token = 'refresh'
79
+ expect(client.refresh_token).to eq 'refresh'
80
+ end
81
+
82
+ it 'debug' do
83
+ expect(client.debug).to be_false
84
+ client.debug = true
85
+ expect(client.debug).to be_true
86
+ end
87
+ end
88
+
89
+ describe '#jwt=' do
90
+
91
+ let(:payload) {
92
+ {
93
+ 'request' => {
94
+ 'user'=> {
95
+ 'oauthToken' => 123456789,
96
+ 'expiresIn' => 3600,
97
+ 'internalOauthToken' => 987654321,
98
+ 'refreshToken' => 101010101010
99
+ },
100
+ 'application'=> {
101
+ 'package' => 'JustTesting'
102
+ }
103
+ }
104
+ }
105
+ }
106
+
107
+ let(:sig){
108
+ sig = 'hanckock'
109
+ }
110
+
111
+ let(:encoded) {
112
+ JWT.encode(payload, sig)
113
+ }
114
+
115
+ it 'raises an exception when signature is missing' do
116
+ expect { MarketingCloudSDK::Client.new.jwt = encoded }.to raise_exception 'Require app signature to decode JWT'
117
+ end
118
+
119
+ describe 'decodes JWT' do
120
+
121
+ let(:sig){
122
+ sig = 'hanckock'
123
+ }
124
+
125
+ let(:encoded) {
126
+ JWT.encode(payload, sig)
127
+ }
128
+
129
+ let(:client) {
130
+ MarketingCloudSDK::Client.new 'client' => { 'id' => '1234', 'secret' => 'ssssh', 'signature' => sig }
131
+ }
132
+
133
+ it 'making auth token available to client' do
134
+ client.jwt = encoded
135
+ expect(client.auth_token).to eq 123456789
136
+ end
137
+
138
+ it 'making internal token available to client' do
139
+ client.jwt = encoded
140
+ expect(client.internal_token).to eq 987654321
141
+ end
142
+
143
+ it 'making refresh token available to client' do
144
+ client.jwt = encoded
145
+ expect(client.refresh_token).to eq 101010101010
146
+ end
147
+ end
148
+ end
149
+
150
+ describe '#refresh_token' do
151
+ let(:client) { MarketingCloudSDK::Client.new }
152
+
153
+ it 'defaults to nil' do
154
+ expect(client.refresh_token).to be_nil
155
+ end
156
+
157
+ it 'can be accessed' do
158
+ client.refresh_token = '1234567890'
159
+ expect(client.refresh_token).to eq '1234567890'
160
+ end
161
+ end
162
+
163
+ describe '#refresh' do
164
+
165
+ let(:client) { MarketingCloudSDK::Client.new }
166
+
167
+ context 'raises an exception' do
168
+
169
+ it 'when client id and secret are missing' do
170
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
171
+ end
172
+
173
+ it 'when client id is missing' do
174
+ client.secret = 1234
175
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
176
+ end
177
+
178
+ it 'when client secret is missing' do
179
+ client.id = 1234
180
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
181
+ end
182
+ end
183
+
184
+ #context 'posts' do
185
+ # let(:client) { MarketingCloudSDK::Client.new 'client' => { 'id' => 123, 'secret' => 'sssh'} }
186
+ # it 'accessType=offline' do
187
+ # client.stub(:post)
188
+ # .with({'clientId' => 123, 'secret' => 'ssh', 'accessType' => 'offline'})
189
+ # .and_return()
190
+ #end
191
+
192
+ #context 'updates' do
193
+ # let(:client) { MarketingCloudSDK::Client.new 'client' => { 'id' => 123, 'secret' => 'sssh'} }
194
+
195
+ # it 'access_token' do
196
+ # #client.stub(:post).
197
+ # end
198
+ #end
199
+ end
200
+
201
+ describe 'includes HTTPRequest' do
202
+
203
+ subject { MarketingCloudSDK::Client.new }
204
+
205
+ it { should respond_to(:get) }
206
+ it { should respond_to(:post) }
207
+ it { should respond_to(:patch) }
208
+ it { should respond_to(:delete) }
209
+ end
210
+ end