fuelsdk_json_bump 0.0.5

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 +91 -0
  5. data/Guardfile +8 -0
  6. data/LICENSE.md +13 -0
  7. data/README.md +127 -0
  8. data/Rakefile +1 -0
  9. data/fuelsdk.gemspec +30 -0
  10. data/lib/fuelsdk.rb +74 -0
  11. data/lib/fuelsdk/client.rb +282 -0
  12. data/lib/fuelsdk/http_request.rb +116 -0
  13. data/lib/fuelsdk/objects.rb +757 -0
  14. data/lib/fuelsdk/rest.rb +122 -0
  15. data/lib/fuelsdk/soap.rb +288 -0
  16. data/lib/fuelsdk/targeting.rb +58 -0
  17. data/lib/fuelsdk/utils.rb +47 -0
  18. data/lib/fuelsdk/version.rb +39 -0
  19. data/lib/new.rb +1240 -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 +200 -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 +250 -0
@@ -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,200 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe FuelSDK::Client do
4
+
5
+ context 'initialized' do
6
+
7
+ it 'with client parameters' do
8
+ client = FuelSDK::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 = FuelSDK::Client.new({}, true)
16
+ expect(client.debug).to be_true
17
+ end
18
+
19
+ it 'with debug=false' do
20
+ client = FuelSDK::Client.new({}, false)
21
+ expect(client.debug).to be_false
22
+ end
23
+
24
+ it 'creates SoapClient' do
25
+ client = FuelSDK::Client.new
26
+ expect(client).to be_kind_of FuelSDK::Soap
27
+ end
28
+
29
+ it '#wsdl defaults to https://webservice.exacttarget.com/etframework.wsdl' do
30
+ client = FuelSDK::Client.new
31
+ expect(client.wsdl).to eq 'https://webservice.exacttarget.com/etframework.wsdl'
32
+ end
33
+
34
+ it 'creates RestClient' do
35
+ client = FuelSDK::Client.new
36
+ expect(client).to be_kind_of FuelSDK::Rest
37
+ end
38
+
39
+ describe 'with a wsdl' do
40
+
41
+ let(:client) { FuelSDK::Client.new 'defaultwsdl' => 'somewsdl' }
42
+
43
+ it'creates a SoapClient' do
44
+ expect(client).to be_kind_of FuelSDK::Soap
45
+ end
46
+
47
+ it'#wsdl returns default wsdl' do
48
+ expect(client.wsdl).to eq 'somewsdl'
49
+ end
50
+ end
51
+ end
52
+
53
+ context 'instance can set' do
54
+
55
+ let(:client) { FuelSDK::Client.new }
56
+
57
+ it 'client id' do
58
+ client.id = 123
59
+ expect(client.id).to eq 123
60
+ end
61
+
62
+ it 'client secret' do
63
+ client.secret = 'sssh'
64
+ expect(client.secret).to eq 'sssh'
65
+ end
66
+
67
+ it 'refresh token' do
68
+ client.refresh_token = 'refresh'
69
+ expect(client.refresh_token).to eq 'refresh'
70
+ end
71
+
72
+ it 'debug' do
73
+ expect(client.debug).to be_false
74
+ client.debug = true
75
+ expect(client.debug).to be_true
76
+ end
77
+ end
78
+
79
+ describe '#jwt=' do
80
+
81
+ let(:payload) {
82
+ {
83
+ 'request' => {
84
+ 'user'=> {
85
+ 'oauthToken' => 123456789,
86
+ 'expiresIn' => 3600,
87
+ 'internalOauthToken' => 987654321,
88
+ 'refreshToken' => 101010101010
89
+ },
90
+ 'application'=> {
91
+ 'package' => 'JustTesting'
92
+ }
93
+ }
94
+ }
95
+ }
96
+
97
+ let(:sig){
98
+ sig = 'hanckock'
99
+ }
100
+
101
+ let(:encoded) {
102
+ JWT.encode(payload, sig)
103
+ }
104
+
105
+ it 'raises an exception when signature is missing' do
106
+ expect { FuelSDK::Client.new.jwt = encoded }.to raise_exception 'Require app signature to decode JWT'
107
+ end
108
+
109
+ describe 'decodes JWT' do
110
+
111
+ let(:sig){
112
+ sig = 'hanckock'
113
+ }
114
+
115
+ let(:encoded) {
116
+ JWT.encode(payload, sig)
117
+ }
118
+
119
+ let(:client) {
120
+ FuelSDK::Client.new 'client' => { 'id' => '1234', 'secret' => 'ssssh', 'signature' => sig }
121
+ }
122
+
123
+ it 'making auth token available to client' do
124
+ client.jwt = encoded
125
+ expect(client.auth_token).to eq 123456789
126
+ end
127
+
128
+ it 'making internal token available to client' do
129
+ client.jwt = encoded
130
+ expect(client.internal_token).to eq 987654321
131
+ end
132
+
133
+ it 'making refresh token available to client' do
134
+ client.jwt = encoded
135
+ expect(client.refresh_token).to eq 101010101010
136
+ end
137
+ end
138
+ end
139
+
140
+ describe '#refresh_token' do
141
+ let(:client) { FuelSDK::Client.new }
142
+
143
+ it 'defaults to nil' do
144
+ expect(client.refresh_token).to be_nil
145
+ end
146
+
147
+ it 'can be accessed' do
148
+ client.refresh_token = '1234567890'
149
+ expect(client.refresh_token).to eq '1234567890'
150
+ end
151
+ end
152
+
153
+ describe '#refresh' do
154
+
155
+ let(:client) { FuelSDK::Client.new }
156
+
157
+ context 'raises an exception' do
158
+
159
+ it 'when client id and secret are missing' do
160
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
161
+ end
162
+
163
+ it 'when client id is missing' do
164
+ client.secret = 1234
165
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
166
+ end
167
+
168
+ it 'when client secret is missing' do
169
+ client.id = 1234
170
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
171
+ end
172
+ end
173
+
174
+ #context 'posts' do
175
+ # let(:client) { FuelSDK::Client.new 'client' => { 'id' => 123, 'secret' => 'sssh'} }
176
+ # it 'accessType=offline' do
177
+ # client.stub(:post)
178
+ # .with({'clientId' => 123, 'secret' => 'ssh', 'accessType' => 'offline'})
179
+ # .and_return()
180
+ #end
181
+
182
+ #context 'updates' do
183
+ # let(:client) { FuelSDK::Client.new 'client' => { 'id' => 123, 'secret' => 'sssh'} }
184
+
185
+ # it 'access_token' do
186
+ # #client.stub(:post).
187
+ # end
188
+ #end
189
+ end
190
+
191
+ describe 'includes HTTPRequest' do
192
+
193
+ subject { FuelSDK::Client.new }
194
+
195
+ it { should respond_to(:get) }
196
+ it { should respond_to(:post) }
197
+ it { should respond_to(:patch) }
198
+ it { should respond_to(:delete) }
199
+ end
200
+ 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,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe FuelSDK::HTTPRequest do
4
+ let(:client) { Class.new.new.extend FuelSDK::HTTPRequest }
5
+ subject { client }
6
+ it { should respond_to(:get) }
7
+ it { should respond_to(:post) }
8
+ it { should respond_to(:patch) }
9
+ it { should respond_to(:delete) }
10
+ it { should_not respond_to(:request) } # private method
11
+
12
+ describe '#get' do
13
+ it 'makes and Net::HTTP::Get request' do
14
+ client.stub(:request).with(Net::HTTP::Get, 'http://some_url', {}).and_return({'success' => 'get'})
15
+ expect(client.get('http://some_url')).to eq 'success' => 'get'
16
+ end
17
+ end
18
+
19
+ describe '#post' do
20
+ describe 'makes and Net::HTTP::Post request' do
21
+
22
+ it 'with only url' do
23
+ Net::HTTP.any_instance.stub(:request)
24
+ client.stub(:request).with(Net::HTTP::Post, 'http://some_url', {}).and_return({'success' => 'post'})
25
+ expect(client.post('http://some_url')).to eq 'success' => 'post'
26
+ end
27
+
28
+ it 'with params' do
29
+ client.stub(:request)
30
+ .with(Net::HTTP::Post, 'http://some_url', {'params' => {'legacy' => 1}})
31
+ .and_return({'success' => 'post'})
32
+ expect(client.post('http://some_url', {'params' => {'legacy' => 1}})).to eq 'success' => 'post'
33
+ end
34
+ end
35
+ end
36
+ end