fuelsdk 0.0.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.
@@ -0,0 +1,122 @@
1
+ require '../ET_Client.rb'
2
+ require 'securerandom'
3
+
4
+ begin
5
+ stubObj = ET_Client.new(false, false)
6
+
7
+ # Get all TriggeredSendDefinitions
8
+ p '>>> Get all TriggeredSendDefinitions'
9
+ getTS = ET_TriggeredSend.new
10
+ getTS.authStub = stubObj
11
+ getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
12
+ getResponse = getTS.get
13
+ p 'Retrieve Status: ' + getResponse.status.to_s
14
+ p 'Code: ' + getResponse.code.to_s
15
+ p 'Message: ' + getResponse.message.to_s
16
+ p 'MoreResults: ' + getResponse.moreResults.to_s
17
+ p 'Results Count: ' + getResponse.results.length.to_s
18
+ #p 'Results: ' + getResponse.results.to_s
19
+
20
+ # Specify the name of a TriggeredSend that was setup for testing
21
+ # Do not use a production Triggered Send Definition
22
+
23
+ NameOfTestTS = "TEXTEXT"
24
+
25
+ # Pause a TriggeredSend
26
+ p '>>> Pause a TriggeredSend'
27
+ patchTrig = ET_TriggeredSend.new
28
+ patchTrig.authStub = stubObj
29
+ patchTrig.props = {"CustomerKey" => NameOfTestTS, "TriggeredSendStatus" =>"Inactive"}
30
+ patchResponse = patchTrig.patch
31
+ p 'Patch Status: ' + patchResponse.status.to_s
32
+ p 'Code: ' + patchResponse.code.to_s
33
+ p 'Message: ' + patchResponse.message.to_s
34
+ p 'Result Count: ' + patchResponse.results.length.to_s
35
+ p 'Results: ' + patchResponse.results.inspect
36
+
37
+ # Retrieve Single TriggeredSend
38
+ p '>>> Retrieve Single TriggeredSend'
39
+ getTS = ET_TriggeredSend.new
40
+ getTS.authStub = stubObj
41
+ getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
42
+ getTS.filter = {'Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => NameOfTestTS}
43
+ getResponse = getTS.get
44
+ p 'Retrieve Status: ' + getResponse.status.to_s
45
+ p 'Code: ' + getResponse.code.to_s
46
+ p 'Message: ' + getResponse.message.to_s
47
+ p 'MoreResults: ' + getResponse.moreResults.to_s
48
+ p 'Results Count: ' + getResponse.results.length.to_s
49
+ p 'Results: ' + getResponse.results.to_s
50
+
51
+ # Start a TriggeredSend by setting to Active
52
+ p '>>> Start a TriggeredSend by setting to Active'
53
+ patchTrig = ET_TriggeredSend.new
54
+ patchTrig.authStub = stubObj
55
+ patchTrig.props = {"CustomerKey" => NameOfTestTS, "TriggeredSendStatus" =>"Active"}
56
+ patchResponse = patchTrig.patch
57
+ p 'Patch Status: ' + patchResponse.status.to_s
58
+ p 'Code: ' + patchResponse.code.to_s
59
+ p 'Message: ' + patchResponse.message.to_s
60
+ p 'Result Count: ' + patchResponse.results.length.to_s
61
+ p 'Results: ' + patchResponse.results.inspect
62
+
63
+ # Retrieve Single TriggeredSend After setting back to active
64
+ p '>>> Retrieve Single TriggeredSend After setting back to active'
65
+ getTS = ET_TriggeredSend.new
66
+ getTS.authStub = stubObj
67
+ getTS.props = ["CustomerKey", "Name", "TriggeredSendStatus"]
68
+ getTS.filter = {'Property' => 'CustomerKey','SimpleOperator' => 'equals','Value' => NameOfTestTS}
69
+ getResponse = getTS.get
70
+ p 'Retrieve Status: ' + getResponse.status.to_s
71
+ p 'Code: ' + getResponse.code.to_s
72
+ p 'Message: ' + getResponse.message.to_s
73
+ p 'MoreResults: ' + getResponse.moreResults.to_s
74
+ p 'Results Count: ' + getResponse.results.length.to_s
75
+ p 'Results: ' + getResponse.results.to_s
76
+
77
+
78
+ # Send an email with TriggeredSend
79
+ p '>>> Send an email with TriggeredSend'
80
+ sendTrig = ET_TriggeredSend.new
81
+ sendTrig.authStub = stubObj
82
+ sendTrig.props = {"CustomerKey" => NameOfTestTS}
83
+ sendTrig.subscribers = [{"EmailAddress"=>"testing@bh.exacttarget.com", "SubscriberKey" => "testing@bh.exacttarget.com"}]
84
+ sendResponse = sendTrig.send
85
+ p 'Send Status: ' + sendResponse.status.to_s
86
+ p 'Code: ' + sendResponse.code.to_s
87
+ p 'Message: ' + sendResponse.message.to_s
88
+ p 'Result Count: ' + sendResponse.results.length.to_s
89
+ p 'Results: ' + sendResponse.results.inspect
90
+
91
+ # Generate a unique identifier for the TriggeredSend customer key since they cannot be re-used even after deleted
92
+ TSNameForCreateThenDelete = SecureRandom.uuid
93
+
94
+ # Create a TriggeredSend Definition
95
+ p '>>> Create a TriggeredSend Definition'
96
+ postTrig = ET_TriggeredSend.new
97
+ postTrig.authStub = stubObj
98
+ postTrig.props = {'CustomerKey' => TSNameForCreateThenDelete,'Name' => TSNameForCreateThenDelete, 'Email' => {"ID"=>"3113962"}, "SendClassification"=> {"CustomerKey"=> "2240"}}
99
+ postResponse = postTrig.post
100
+ p 'Post Status: ' + postResponse.status.to_s
101
+ p 'Code: ' + postResponse.code.to_s
102
+ p 'Message: ' + postResponse.message.to_s
103
+ p 'Result Count: ' + postResponse.results.length.to_s
104
+ p 'Results: ' + postResponse.results.inspect
105
+
106
+ # Delete a TriggeredSend Definition
107
+ p '>>> Delete a TriggeredSend Definition '
108
+ deleteTrig = ET_TriggeredSend.new
109
+ deleteTrig.authStub = stubObj
110
+ deleteTrig.props = {'CustomerKey' => TSNameForCreateThenDelete}
111
+ deleteResponse = deleteTrig.delete
112
+ p 'Delete Status: ' + deleteResponse.status.to_s
113
+ p 'Code: ' + deleteResponse.code.to_s
114
+ p 'Message: ' + deleteResponse.message.to_s
115
+ p 'Result Count: ' + deleteResponse.results.length.to_s
116
+ p 'Results: ' + deleteResponse.results.inspect
117
+
118
+ rescue => e
119
+ p "Caught exception: #{e.message}"
120
+ p e.backtrace
121
+ end
122
+
@@ -0,0 +1,68 @@
1
+ require '../ET_Client.rb'
2
+
3
+ begin
4
+ stubObj = ET_Client.new(false, false)
5
+
6
+ ## Modify the date below to reduce the number of results returned from the request
7
+ ## Setting this too far in the past could result in a very large response size
8
+ retrieveDate = '2013-01-15T13:00:00.000'
9
+
10
+ p '>>> Retrieve Filtered UnsubEvents with GetMoreResults'
11
+ getUnsubEvent = ET_UnsubEvent.new()
12
+ getUnsubEvent.authStub = stubObj
13
+ getUnsubEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
14
+ getUnsubEvent.filter = {'Property' => 'EventDate','SimpleOperator' => 'greaterThan','DateValue' => retrieveDate}
15
+ getResponse = getUnsubEvent.get
16
+ p 'Retrieve Status: ' + getResponse.status.to_s
17
+ p 'Code: ' + getResponse.code.to_s
18
+ p 'Message: ' + getResponse.message.to_s
19
+ p 'MoreResults: ' + getResponse.moreResults.to_s
20
+ p 'RequestID: ' + getResponse.request_id.to_s
21
+ p 'Results Length: ' + getResponse.results.length.to_s
22
+ # Since this could potentially return a large number of results, we do not want to print the results
23
+ #p 'Results: ' + getResponse.results.to_s
24
+
25
+ while getResponse.moreResults do
26
+ p '>>> Continue Retrieve Filtered UnsubEvents with GetMoreResults'
27
+ getResponse = getUnsubEvent.getMoreResults
28
+ p 'Retrieve Status: ' + getResponse.status.to_s
29
+ p 'Code: ' + getResponse.code.to_s
30
+ p 'Message: ' + getResponse.message.to_s
31
+ p 'MoreResults: ' + getResponse.moreResults.to_s
32
+ p 'RequestID: ' + getResponse.request_id.to_s
33
+ p 'Results Length: ' + getResponse.results.length.to_s
34
+ end
35
+
36
+ # The following request could potentially bring back large amounts of data if run against a production account
37
+ =begin
38
+ p '>>> Retrieve All UnsubEvents with GetMoreResults'
39
+ getUnsubEvent = ET_UnsubEvent.new()
40
+ getUnsubEvent.authStub = stubObj
41
+ getUnsubEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
42
+ getResponse = getUnsubEvent.get
43
+ p 'Retrieve Status: ' + getResponse.status.to_s
44
+ p 'Code: ' + getResponse.code.to_s
45
+ p 'Message: ' + getResponse.message.to_s
46
+ p 'MoreResults: ' + getResponse.moreResults.to_s
47
+ p 'RequestID: ' + getResponse.request_id.to_s
48
+ p 'Results Length: ' + getResponse.results.length.to_s
49
+ # Since this could potentially return a large number of results, we do not want to print the results
50
+ #p 'Results: ' + getResponse.results.to_s
51
+
52
+ while getResponse.moreResults do
53
+ p '>>> Continue Retrieve All UnsubEvents with GetMoreResults'
54
+ getResponse = getUnsubEvent.getMoreResults
55
+ p 'Retrieve Status: ' + getResponse.status.to_s
56
+ p 'Code: ' + getResponse.code.to_s
57
+ p 'Message: ' + getResponse.message.to_s
58
+ p 'MoreResults: ' + getResponse.moreResults.to_s
59
+ p 'RequestID: ' + getResponse.request_id.to_s
60
+ p 'Results Length: ' + getResponse.results.length.to_s
61
+ end
62
+ =end
63
+
64
+ rescue => e
65
+ p "Caught exception: #{e.message}"
66
+ p e.backtrace
67
+ end
68
+
@@ -0,0 +1,8 @@
1
+ def auth
2
+ {
3
+ 'client' => {
4
+ 'id' => 'b2atjsvxvr9ae4kh6hk948hu',
5
+ 'secret' => 'uAnap7jbfx6KghAxfh895YZ8'
6
+ }
7
+ }
8
+ end
@@ -0,0 +1,21 @@
1
+ #require 'spec_helper'
2
+ #
3
+ #describe FuelSDK::Client do
4
+ #
5
+ # it 'errors when instantiated with clientsecret but without clientid' do
6
+ # expect { FuelSDK::Client.new :clientid => 'id' }.to raise_error
7
+ # end
8
+ #
9
+ # it 'errors when instantiated with clientid but without clientsecret' do
10
+ # expect { FuelSDK::Client.new :clientid => 'id' }.to raise_error
11
+ # end
12
+ #
13
+ # describe '#new' do
14
+ # let(:client) { FuelSDK::Client.new :clientid => 'id', :clientsecret => 'secret' }
15
+ # subject { client }
16
+ #
17
+ # its(:id) { should eq 'id' }
18
+ # its(:secret) { should eq 'secret' }
19
+ # end
20
+ #
21
+ #end
@@ -0,0 +1,197 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe FuelSDK::ET_Client do
4
+
5
+ context 'initialized' do
6
+
7
+ it 'with client parameters' do
8
+ client = FuelSDK::ET_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::ET_Client.new({}, true)
16
+ expect(client.debug).to be_true
17
+ end
18
+
19
+ it 'with debug=false' do
20
+ client = FuelSDK::ET_Client.new({}, false)
21
+ expect(client.debug).to be_false
22
+ end
23
+
24
+ it 'creates SoapClient' do
25
+ client = FuelSDK::ET_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::ET_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::ET_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::ET_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::ET_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' => DateTime.new(2001, 01, 01),
87
+ 'internalOauthToken' => 987654321,
88
+ 'refreshToken' => 101010101010
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ let(:sig){
95
+ sig = 'hanckock'
96
+ }
97
+
98
+ let(:encoded) {
99
+ JWT.encode(payload, sig)
100
+ }
101
+
102
+ it 'raises an exception when signature is missing' do
103
+ expect { FuelSDK::ET_Client.new.jwt = encoded }.to raise_exception 'Require app signature to decode JWT'
104
+ end
105
+
106
+ describe 'decodes JWT' do
107
+
108
+ let(:sig){
109
+ sig = 'hanckock'
110
+ }
111
+
112
+ let(:encoded) {
113
+ JWT.encode(payload, sig)
114
+ }
115
+
116
+ let(:client) {
117
+ FuelSDK::ET_Client.new 'client' => { 'id' => '1234', 'secret' => 'ssssh', 'signature' => sig }
118
+ }
119
+
120
+ it 'making auth token available to client' do
121
+ client.jwt = encoded
122
+ expect(client.auth_token).to eq 123456789
123
+ end
124
+
125
+ it 'making internal token available to client' do
126
+ client.jwt = encoded
127
+ expect(client.internal_token).to eq 987654321
128
+ end
129
+
130
+ it 'making refresh token available to client' do
131
+ client.jwt = encoded
132
+ expect(client.refresh_token).to eq 101010101010
133
+ end
134
+ end
135
+ end
136
+
137
+ describe '#refresh_token' do
138
+ let(:client) { FuelSDK::ET_Client.new }
139
+
140
+ it 'defaults to nil' do
141
+ expect(client.refresh_token).to be_nil
142
+ end
143
+
144
+ it 'can be accessed' do
145
+ client.refresh_token = '1234567890'
146
+ expect(client.refresh_token).to eq '1234567890'
147
+ end
148
+ end
149
+
150
+ describe '#refresh' do
151
+
152
+ let(:client) { FuelSDK::ET_Client.new }
153
+
154
+ context 'raises an exception' do
155
+
156
+ it 'when client id and secret are missing' do
157
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
158
+ end
159
+
160
+ it 'when client id is missing' do
161
+ client.secret = 1234
162
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
163
+ end
164
+
165
+ it 'when client secret is missing' do
166
+ client.id = 1234
167
+ expect { client.refresh }.to raise_exception 'Require Client Id and Client Secret to refresh tokens'
168
+ end
169
+ end
170
+
171
+ #context 'posts' do
172
+ # let(:client) { FuelSDK::ET_Client.new 'client' => { 'id' => 123, 'secret' => 'sssh'} }
173
+ # it 'accessType=offline' do
174
+ # client.stub(:post)
175
+ # .with({'clientId' => 123, 'secret' => 'ssh', 'accessType' => 'offline'})
176
+ # .and_return()
177
+ #end
178
+
179
+ #context 'updates' do
180
+ # let(:client) { FuelSDK::ET_Client.new 'client' => { 'id' => 123, 'secret' => 'sssh'} }
181
+
182
+ # it 'access_token' do
183
+ # #client.stub(:post).
184
+ # end
185
+ #end
186
+ end
187
+
188
+ describe 'includes HTTPRequest' do
189
+
190
+ subject { FuelSDK::ET_Client.new }
191
+
192
+ it { should respond_to(:get) }
193
+ it { should respond_to(:post) }
194
+ it { should respond_to(:patch) }
195
+ it { should respond_to(:delete) }
196
+ end
197
+ 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