sfmc-fuelsdk-ruby 1.1.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 (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +90 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE.md +13 -0
  7. data/README.md +143 -0
  8. data/Rakefile +1 -0
  9. data/lib/marketingcloudsdk/client.rb +296 -0
  10. data/lib/marketingcloudsdk/http_request.rb +118 -0
  11. data/lib/marketingcloudsdk/objects.rb +757 -0
  12. data/lib/marketingcloudsdk/rest.rb +118 -0
  13. data/lib/marketingcloudsdk/soap.rb +282 -0
  14. data/lib/marketingcloudsdk/targeting.rb +99 -0
  15. data/lib/marketingcloudsdk/utils.rb +47 -0
  16. data/lib/marketingcloudsdk/version.rb +39 -0
  17. data/lib/marketingcloudsdk.rb +74 -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 +54 -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 +103 -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 +56 -0
  43. data/samples/sample-sentevent.rb +70 -0
  44. data/samples/sample-subscriber.rb +135 -0
  45. data/samples/sample-triggeredsend.rb +129 -0
  46. data/samples/sample-unsubevent.rb +72 -0
  47. data/samples/sample_helper.rb.template +10 -0
  48. data/spec/client_spec.rb +218 -0
  49. data/spec/default_values_fallback_spec.rb +30 -0
  50. data/spec/helper_funcs_spec.rb +11 -0
  51. data/spec/http_request_spec.rb +61 -0
  52. data/spec/objects_helper_spec.rb +32 -0
  53. data/spec/objects_spec.rb +484 -0
  54. data/spec/rest_spec.rb +48 -0
  55. data/spec/soap_spec.rb +140 -0
  56. data/spec/spec_helper.rb +14 -0
  57. data/spec/targeting_spec.rb +44 -0
  58. metadata +262 -0
@@ -0,0 +1,218 @@
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
+ 'base_api_url' => 'http://getapis', 'request_token_url' => 'http://authapi'}
10
+ expect(client.secret).to eq 'ssssh'
11
+ expect(client.id).to eq '1234'
12
+ expect(client.signature).to eq 'hancock'
13
+ expect(client.base_api_url).to eq 'http://getapis'
14
+ expect(client.request_token_url).to eq 'http://authapi'
15
+ end
16
+
17
+ it 'with debug=true' do
18
+ client = MarketingCloudSDK::Client.new({}, true)
19
+ expect(client.debug).to be true
20
+ end
21
+
22
+ it 'with debug=false' do
23
+ client = MarketingCloudSDK::Client.new({}, false)
24
+ expect(client.debug).to be false
25
+ end
26
+
27
+ it 'sets the request_token url to parameter if it exists' do
28
+ client = MarketingCloudSDK::Client.new({'request_token_url' => 'fake/url'}, false)
29
+ expect(client.request_token_url).to eq 'fake/url'
30
+ end
31
+
32
+ it 'sets the base_api_url url to a default if it does not exist' do
33
+ client = MarketingCloudSDK::Client.new({}, false)
34
+ expect(client.base_api_url).to eq 'https://www.exacttargetapis.com'
35
+ end
36
+
37
+ it 'sets the request_token url to a default if it does not exist' do
38
+ client = MarketingCloudSDK::Client.new({}, false)
39
+ expect(client.request_token_url).to eq 'https://auth.exacttargetapis.com/v1/requestToken'
40
+ end
41
+
42
+ it 'creates SoapClient' do
43
+ client = MarketingCloudSDK::Client.new
44
+ expect(client).to be_kind_of MarketingCloudSDK::Soap
45
+ end
46
+
47
+ it '#wsdl defaults to https://webservice.exacttarget.com/etframework.wsdl' do
48
+ client = MarketingCloudSDK::Client.new
49
+ expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl'
50
+ end
51
+
52
+ it 'creates RestClient' do
53
+ client = MarketingCloudSDK::Client.new
54
+ expect(client).to be_kind_of MarketingCloudSDK::Rest
55
+ end
56
+
57
+ describe 'with a wsdl' do
58
+
59
+ let(:client) { MarketingCloudSDK::Client.new 'defaultwsdl' => 'somewsdl' }
60
+
61
+ it'creates a SoapClient' do
62
+ expect(client).to be_kind_of MarketingCloudSDK::Soap
63
+ end
64
+
65
+ it'#wsdl returns default wsdl' do
66
+ expect(client.wsdl).to eq 'somewsdl'
67
+ end
68
+ end
69
+ end
70
+
71
+ context 'instance can set' do
72
+
73
+ let(:client) { MarketingCloudSDK::Client.new }
74
+
75
+ it 'client id' do
76
+ client.id = 123
77
+ expect(client.id).to eq 123
78
+ end
79
+
80
+ it 'client secret' do
81
+ client.secret = 'sssh'
82
+ expect(client.secret).to eq 'sssh'
83
+ end
84
+
85
+ it 'refresh token' do
86
+ client.refresh_token = 'refresh'
87
+ expect(client.refresh_token).to eq 'refresh'
88
+ end
89
+
90
+ it 'debug' do
91
+ expect(client.debug).to be false
92
+ client.debug = true
93
+ expect(client.debug).to be true
94
+ end
95
+ end
96
+
97
+ describe '#jwt=' do
98
+
99
+ let(:payload) {
100
+ {
101
+ 'request' => {
102
+ 'user'=> {
103
+ 'oauthToken' => 123456789,
104
+ 'expiresIn' => 3600,
105
+ 'internalOauthToken' => 987654321,
106
+ 'refreshToken' => 101010101010
107
+ },
108
+ 'application'=> {
109
+ 'package' => 'JustTesting'
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ let(:sig){
116
+ sig = 'hanckock'
117
+ }
118
+
119
+ let(:encoded) {
120
+ JWT.encode(payload, sig)
121
+ }
122
+
123
+ it 'raises an exception when signature is missing' do
124
+ expect { MarketingCloudSDK::Client.new.jwt = encoded }.to raise_exception 'Require app signature to decode JWT'
125
+ end
126
+
127
+ describe 'decodes JWT' do
128
+
129
+ let(:sig){
130
+ sig = 'hanckock'
131
+ }
132
+
133
+ let(:encoded) {
134
+ JWT.encode(payload, sig)
135
+ }
136
+
137
+ let(:client) {
138
+ MarketingCloudSDK::Client.new 'client' => { 'id' => '1234', 'secret' => 'ssssh', 'signature' => sig }
139
+ }
140
+
141
+ it 'making auth token available to client' do
142
+ client.jwt = encoded
143
+ expect(client.auth_token).to eq 123456789
144
+ end
145
+
146
+ it 'making internal token available to client' do
147
+ client.jwt = encoded
148
+ expect(client.internal_token).to eq 987654321
149
+ end
150
+
151
+ it 'making refresh token available to client' do
152
+ client.jwt = encoded
153
+ expect(client.refresh_token).to eq 101010101010
154
+ end
155
+ end
156
+ end
157
+
158
+ describe '#refresh_token' do
159
+ let(:client) { MarketingCloudSDK::Client.new }
160
+
161
+ it 'defaults to nil' do
162
+ expect(client.refresh_token).to be_nil
163
+ end
164
+
165
+ it 'can be accessed' do
166
+ client.refresh_token = '1234567890'
167
+ expect(client.refresh_token).to eq '1234567890'
168
+ end
169
+ end
170
+
171
+ describe '#refresh' do
172
+
173
+ let(:client) { MarketingCloudSDK::Client.new }
174
+
175
+ context 'raises an exception' do
176
+
177
+ it 'when client id and secret are missing' do
178
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
179
+ end
180
+
181
+ it 'when client id is missing' do
182
+ client.secret = 1234
183
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
184
+ end
185
+
186
+ it 'when client secret is missing' do
187
+ client.id = 1234
188
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
189
+ end
190
+ end
191
+
192
+ #context 'posts' do
193
+ # let(:client) { MarketingCloudSDK::Client.new 'client' => { 'id' => 123, 'secret' => 'sssh'} }
194
+ # it 'accessType=offline' do
195
+ # client.stub(:post)
196
+ # .with({'clientId' => 123, 'secret' => 'ssh', 'accessType' => 'offline'})
197
+ # .and_return()
198
+ #end
199
+
200
+ #context 'updates' do
201
+ # let(:client) { MarketingCloudSDK::Client.new 'client' => { 'id' => 123, 'secret' => 'sssh'} }
202
+
203
+ # it 'access_token' do
204
+ # #client.stub(:post).
205
+ # end
206
+ #end
207
+ end
208
+
209
+ describe 'includes HTTPRequest' do
210
+
211
+ subject { MarketingCloudSDK::Client.new }
212
+
213
+ it { should respond_to(:get) }
214
+ it { should respond_to(:post) }
215
+ it { should respond_to(:patch) }
216
+ it { should respond_to(:delete) }
217
+ end
218
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe MarketingCloudSDK::Client do
4
+
5
+ context 'Empty string REST endpoint, no Auth attribute' do
6
+
7
+ client1 = MarketingCloudSDK::Client.new 'client' => {'id' => '1234', 'secret' => 'ssssh',
8
+ 'base_api_url' => ''}
9
+
10
+ it 'Should use REST endpoint default value if base_api_url endpoint is an empty string in config' do
11
+ expect(client1.base_api_url).to eq 'https://www.exacttargetapis.com'
12
+ end
13
+
14
+ it 'Should use Auth endpoint default value if request_token_url attribute is not in config' do
15
+ expect(client1.request_token_url).to eq 'https://auth.exacttargetapis.com/v1/requestToken'
16
+ end
17
+ end
18
+
19
+ context 'Blank string REST endpoint' do
20
+
21
+ client2 = MarketingCloudSDK::Client.new 'client' => {'id' => '1234', 'secret' => 'ssssh',
22
+ 'base_api_url' => ' '}
23
+
24
+ it 'Should use REST endpoint default value if REST endpoint is a blank string in config' do
25
+ expect(client2.base_api_url).to eq 'https://www.exacttargetapis.com'
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,11 @@
1
+ #require 'spec_helper'
2
+ #
3
+ #describe 'indifferent_access' do
4
+ #
5
+ # it 'returns value when symbol is used to access a string key' do
6
+ # expect( indifferent_access :key, 'key' => true).to be_true
7
+ # end
8
+ # it 'returns value when string is used to access a symbol key' do
9
+ # expect( indifferent_access 'key', :key => true).to be_true
10
+ # end
11
+ #end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'marketingcloudsdk/version'
3
+
4
+ describe MarketingCloudSDK::HTTPRequest do
5
+ let(:client) { Class.new.new.extend MarketingCloudSDK::HTTPRequest }
6
+ subject { client }
7
+ it { should respond_to(:get) }
8
+ it { should respond_to(:post) }
9
+ it { should respond_to(:patch) }
10
+ it { should respond_to(:delete) }
11
+ it { should respond_to(:request) }
12
+
13
+ describe '#get' do
14
+ it 'makes and Net::HTTP::Get request' do
15
+ client.stub(:request).with(Net::HTTP::Get, 'http://some_url', {}).and_return({'success' => 'get'})
16
+ expect(client.get('http://some_url')).to eq 'success' => 'get'
17
+ end
18
+ end
19
+
20
+ describe '#post' do
21
+ describe 'makes and Net::HTTP::Post request' do
22
+
23
+ it 'with only url' do
24
+ Net::HTTP.any_instance.stub(:request)
25
+ client.stub(:request).with(Net::HTTP::Post, 'http://some_url', {}).and_return({'success' => 'post'})
26
+ expect(client.post('http://some_url')).to eq 'success' => 'post'
27
+ end
28
+
29
+ it 'with params' do
30
+ client.stub(:request)
31
+ .with(Net::HTTP::Post, 'http://some_url', {'params' => {'legacy' => 1}})
32
+ .and_return({'success' => 'post'})
33
+ expect(client.post('http://some_url', {'params' => {'legacy' => 1}})).to eq 'success' => 'post'
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '#request' do
39
+ it 'should set Authorization header' do
40
+ params = {'access_token' => 'token'}
41
+ Net::HTTP.any_instance.stub(:request)
42
+ get = double("get")
43
+ get.should_receive(:add_field).with('User-Agent', 'FuelSDK-Ruby-v' + MarketingCloudSDK::VERSION)
44
+ get.should_receive(:add_field).with('Authorization', 'Bearer ' + params['access_token'])
45
+ net = double(Net::HTTP::Get)
46
+ net.stub(:new).with(any_args()).and_return(get)
47
+ client.request(net, 'http://some_url', params)
48
+ end
49
+
50
+ it 'should skip setting Authorization header' do
51
+ params = {}
52
+ Net::HTTP.any_instance.stub(:request)
53
+ get = double("get")
54
+ get.should_receive(:add_field).with('User-Agent', 'FuelSDK-Ruby-v' + MarketingCloudSDK::VERSION)
55
+ get.should_not_receive(:add_field).with('Authorization', any_args())
56
+ net = double(Net::HTTP::Get)
57
+ net.stub(:new).with(any_args()).and_return(get)
58
+ client.request(net, 'http://some_url', params)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,32 @@
1
+
2
+ # Everything will be readable so test for shared from Read behavior
3
+ shared_examples_for 'Soap Read Object' do
4
+ # begin backwards compat
5
+ it { should respond_to :props= }
6
+ it { should respond_to :authStub= }
7
+ # end
8
+ it { should respond_to :id }
9
+ it { should respond_to :properties }
10
+ it { should respond_to :client }
11
+ it { should respond_to :filter }
12
+ it { should respond_to :info }
13
+ it { should respond_to :get }
14
+ end
15
+
16
+ shared_examples_for 'Soap CUD Object' do
17
+ it { should respond_to :post }
18
+ it { should respond_to :patch }
19
+ it { should respond_to :delete }
20
+ end
21
+
22
+ shared_examples_for 'Soap Object' do
23
+ it_behaves_like 'Soap Read Object'
24
+ it_behaves_like 'Soap CUD Object'
25
+ end
26
+
27
+ shared_examples_for 'Soap Read Only Object' do
28
+ it_behaves_like 'Soap Read Object'
29
+ it { should_not respond_to :post }
30
+ it { should_not respond_to :patch }
31
+ it { should_not respond_to :delete }
32
+ end