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,52 @@
1
+ require '../ET_Client.rb'
2
+
3
+ begin
4
+ stubObj = ET_Client.new(false, false)
5
+
6
+ NewListName = "RubySDKList"
7
+
8
+ ## Example using AddSubscriberToList() method
9
+ ## Typically this method will be used with a pre-existing list but for testing purposes one is being created.
10
+
11
+ # Create List
12
+ p '>>> Create List'
13
+ postList = ET_List.new
14
+ postList.authStub = stubObj
15
+ postList.props = {"ListName" => NewListName, "Description" => "This list was created with the RubySDK", "Type" => "Private" }
16
+ postResponse = postList.post
17
+ p 'Post Status: ' + postResponse.status.to_s
18
+ p 'Code: ' + postResponse.code.to_s
19
+ p 'Message: ' + postResponse.message.to_s
20
+ p 'Result Count: ' + postResponse.results.length.to_s
21
+ p 'Results: ' + postResponse.results.inspect
22
+
23
+ if postResponse.status then
24
+
25
+ newListID = postResponse.results[0][:new_id]
26
+ # Adding Subscriber To a List
27
+ p '>>> Add Subscriber To a List'
28
+ AddSubResponse = stubObj.AddSubscriberToList("AddSubTesting@bh.exacttarget.com", [newListID])
29
+ p 'AddSubResponse Status: ' + AddSubResponse.status.to_s
30
+ p 'Code: ' + AddSubResponse.code.to_s
31
+ p 'Message: ' + AddSubResponse.message.to_s
32
+ p 'Result Count: ' + AddSubResponse.results.length.to_s
33
+ p 'Results: ' + AddSubResponse.results.inspect
34
+
35
+ # Delete List
36
+ p '>>> Delete List'
37
+ deleteSub = ET_List.new()
38
+ deleteSub.authStub = stubObj
39
+ deleteSub.props = {"ID" => newListID}
40
+ deleteResponse = deleteSub.delete
41
+ p 'Delete Status: ' + deleteResponse.status.to_s
42
+ p 'Code: ' + deleteResponse.code.to_s
43
+ p 'Message: ' + deleteResponse.message.to_s
44
+ p 'Results Length: ' + deleteResponse.results.length.to_s
45
+ p 'Results: ' + deleteResponse.results.to_s
46
+ end
47
+
48
+ rescue => e
49
+ p "Caught exception: #{e.message}"
50
+ p e.backtrace
51
+ end
52
+
@@ -0,0 +1,51 @@
1
+ require '../ET_Client.rb'
2
+
3
+ begin
4
+ myclient = ET_Client.new(false, false)
5
+
6
+ ## Example using CreateDataExtensions() method
7
+
8
+ # Declare a Ruby Hash which contain all of the details for a DataExtension
9
+ deOne = {"Name" => "HelperDEOne","CustomerKey" => "HelperDEOne"}
10
+ deOne['columns'] = [{"Name" => "Name", "FieldType" => "Text", "IsPrimaryKey" => "true", "MaxLength" => "100", "IsRequired" => "true"},{"Name" => "OtherField", "FieldType" => "Text"}]
11
+
12
+ # Declare a 2nd Ruby Hash which contain all of the details for a DataExtension
13
+ deTwo = {"Name" => "HelperDETwo","CustomerKey" => "HelperDETwo"}
14
+ deTwo['columns'] = [{"Name" => "Name", "FieldType" => "Text", "IsPrimaryKey" => "true", "MaxLength" => "100", "IsRequired" => "true"},{"Name" => "OtherField", "FieldType" => "Text"}]
15
+
16
+ # Call CreateDataExtensions passing in both DataExtension Hashes as an Array
17
+ createDEResponse = myclient.CreateDataExtensions([deOne, deTwo])
18
+ p 'CreateDataExtensions Status: ' + createDEResponse.status.to_s
19
+ p 'Code: ' + createDEResponse.code.to_s
20
+ p 'Message: ' + createDEResponse.message.to_s
21
+ p 'Results Length: ' + createDEResponse.results.length.to_s
22
+ p 'Results: ' + createDEResponse.results.to_s
23
+
24
+ # Cleaning up the newly created DEs
25
+ # Delete deOne
26
+ p '>>> Delete deOne'
27
+ de5 = ET_DataExtension.new
28
+ de5.authStub = myclient
29
+ de5.props = {"CustomerKey" => "HelperDEOne"}
30
+ delResponse = de5.delete
31
+ p 'Delete Status: ' + delResponse.status.to_s
32
+ p 'Code: ' + delResponse.code.to_s
33
+ p 'Message: ' + delResponse.message.to_s
34
+ p 'Results: ' + delResponse.results.inspect
35
+
36
+ # Delete deTwo
37
+ p '>>> Delete deTwo'
38
+ de5 = ET_DataExtension.new
39
+ de5.authStub = myclient
40
+ de5.props = {"CustomerKey" => "HelperDETwo"}
41
+ delResponse = de5.delete
42
+ p 'Delete Status: ' + delResponse.status.to_s
43
+ p 'Code: ' + delResponse.code.to_s
44
+ p 'Message: ' + delResponse.message.to_s
45
+ p 'Results: ' + delResponse.results.inspect
46
+
47
+ rescue => e
48
+ p "Caught exception: #{e.message}"
49
+ p e.backtrace
50
+ end
51
+
@@ -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 = '2011-01-15T13:00:00.000'
9
+
10
+ p '>>> Retrieve Filtered BounceEvents with GetMoreResults'
11
+ getBounceEvent = ET_BounceEvent.new()
12
+ getBounceEvent.authStub = stubObj
13
+ getBounceEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
14
+ getBounceEvent.filter = {'Property' => 'EventDate','SimpleOperator' => 'greaterThan','DateValue' => retrieveDate}
15
+ getResponse = getBounceEvent.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 BounceEvents with GetMoreResults'
27
+ getResponse = getBounceEvent.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 BounceEvents with GetMoreResults'
39
+ getBounceEvent = ET_BounceEvent.new()
40
+ getBounceEvent.authStub = stubObj
41
+ getBounceEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
42
+ getResponse = getBounceEvent.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 BounceEvents with GetMoreResults'
54
+ getResponse = getBounceEvent.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,212 @@
1
+ require 'fuelsdk'
2
+ require_relative 'sample_helper'
3
+ require 'pry'
4
+
5
+
6
+ begin
7
+ stubObj = FuelSDK::ET_Client.new auth
8
+
9
+ # Create List
10
+ p '>>> Create List'
11
+ postList = FuelSDK::ET_List.new
12
+ postList.authStub = stubObj
13
+ postList.props = {"ListName" => 'RubyAssetList', "Description" => "This list was created with the RubySDK", "Type" => "Private" }
14
+ postResponse = postList.post
15
+ p 'Post Status: ' + postResponse.status.to_s
16
+ p 'Code: ' + postResponse.code.to_s
17
+ p 'Message: ' + postResponse.message.to_s
18
+ p 'Result Count: ' + postResponse.results.length.to_s
19
+ p 'Results: ' + postResponse.results.inspect
20
+
21
+ raise 'Failure creating list for asset' unless postResponse.success?
22
+
23
+ # In order for this sample to run, it needs to have an asset that it can associate the campaign to
24
+ ExampleAssetType = "LIST"
25
+ ExampleAssetItemID = postResponse.results[0][:new_id]
26
+
27
+ # Retrieve all Campaigns
28
+ p '>>> Retrieve all Campaigns'
29
+ getCamp = FuelSDK::ET_Campaign.new
30
+ getCamp.authStub = stubObj
31
+ getResponse = getCamp.get
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 "Results: #{getResponse.results}"
37
+ p 'Results(Items) Length: ' + getResponse.results['items'].length.to_s
38
+ p '-----------------------------'
39
+
40
+ raise 'Failure retrieving campaigns' unless getResponse.success?
41
+
42
+ while getResponse.more? do
43
+ p '>>> Continue Retrieve all Campaigns with GetMoreResults'
44
+ getResponse = getCamp.continue
45
+ p 'Retrieve Status: ' + getResponse.status.to_s
46
+ p 'Code: ' + getResponse.code.to_s
47
+ p 'Message: ' + getResponse.message.to_s
48
+ p 'MoreResults: ' + getResponse.more?.to_s
49
+ p 'Results(Items) Length: ' + getResponse.results['items'].length.to_s
50
+ end
51
+
52
+ # Create a new Campaign
53
+ p '>>> Create a new Campaign'
54
+ postCamp = FuelSDK::ET_Campaign.new
55
+ postCamp.authStub = stubObj
56
+ postCamp.props = {"name" => "RubySDKCreatedForTest1", "description"=> "RubySDKCreatedForTest", "color"=>"FF9933", "favorite"=>"false"}
57
+ postResponse = postCamp.post
58
+ p 'Post Status: ' + postResponse.status.to_s
59
+ p 'Code: ' + postResponse.code.to_s
60
+ p 'Message: ' + postResponse.message.to_s
61
+ p 'Results: ' + postResponse.results.to_json
62
+ p '-----------------------------'
63
+
64
+ raise 'Failure creating campaign' unless postResponse.success?
65
+
66
+ IDOfpostCampaign = postResponse.results['id']
67
+
68
+ # Retrieve the new Campaign
69
+ p '>>> Retrieve the new Campaign'
70
+ getCamp = FuelSDK::ET_Campaign.new
71
+ getCamp.authStub = stubObj
72
+ getCamp.props = {"id" => IDOfpostCampaign}
73
+ getResponse = getCamp.get
74
+ p 'Retrieve Status: ' + getResponse.status.to_s
75
+ p 'Code: ' + getResponse.code.to_s
76
+ p 'Message: ' + getResponse.message.to_s
77
+ p 'Results: ' + getResponse.results.to_json
78
+ p '-----------------------------'
79
+
80
+ raise 'Failure retrieving campaign' unless getResponse.success?
81
+
82
+ # Update the new Campaign
83
+ p '>>> Update the new Campaign'
84
+ patchCamp = FuelSDK::ET_Campaign.new
85
+ patchCamp.authStub = stubObj
86
+ patchCamp.props = {"id"=> IDOfpostCampaign, "name" => "RubySDKCreated-Updated!"}
87
+ patchResponse = patchCamp.patch
88
+ p 'Patch Status: ' + patchResponse.status.to_s
89
+ p 'Code: ' + patchResponse.code.to_s
90
+ p 'Message: ' + patchResponse.message.to_s
91
+ p 'Results: ' + patchResponse.results.to_json
92
+ p '-----------------------------'
93
+
94
+ raise 'Failure updating campaign' unless patchResponse.success?
95
+
96
+ # Retrieve the updated Campaign
97
+ p '>>> Retrieve the updated Campaign'
98
+ getCamp = FuelSDK::ET_Campaign.new
99
+ getCamp.authStub = stubObj
100
+ getCamp.props = {"id" => IDOfpostCampaign}
101
+ getResponse = getCamp.get
102
+ p 'Retrieve Status: ' + getResponse.status.to_s
103
+ p 'Code: ' + getResponse.code.to_s
104
+ p 'Message: ' + getResponse.message.to_s
105
+ p 'Results: ' + getResponse.results.to_json
106
+ p '-----------------------------'
107
+
108
+ raise 'Failure retrieving campaign' unless getResponse.success?
109
+
110
+ # Create a new Campaign Asset
111
+ p '>>> Create a new Campaign Asset'
112
+ postCampAsset = FuelSDK::ET_Campaign::Asset.new
113
+ postCampAsset.authStub = stubObj
114
+ postCampAsset.props = {"id" => IDOfpostCampaign, "ids"=> [ExampleAssetItemID], "type"=> ExampleAssetType}
115
+ postResponse = postCampAsset.post
116
+ p 'Post Status: ' + postResponse.status.to_s
117
+ p 'Code: ' + postResponse.code.to_s
118
+ p 'Message: ' + postResponse.message.to_s
119
+ p 'Results: ' + postResponse.results.to_json
120
+ p '-----------------------------'
121
+
122
+ raise 'Failure creating campaign assets' unless postResponse.success?
123
+
124
+ IDOfpostCampaignAsset = postResponse.results[0]['id']
125
+
126
+ # Retrieve all Campaign Asset for a campaign
127
+ p '>>> Retrieve all Campaign Asset for a Campaign'
128
+ getCampAsset = FuelSDK::ET_Campaign::Asset.new
129
+ getCampAsset.authStub = stubObj
130
+ getCampAsset.props = {"id" => IDOfpostCampaign}
131
+ getResponse = getCampAsset.get
132
+ p 'Retrieve Status: ' + getResponse.status.to_s
133
+ p 'Code: ' + getResponse.code.to_s
134
+ p 'Message: ' + getResponse.message.to_s
135
+ p 'Results: ' + getResponse.results.inspect
136
+ p '-----------------------------'
137
+
138
+ raise 'Failure retrieving campaign assets' unless getResponse.success?
139
+
140
+ # Retrieve a single new Campaign Asset
141
+ p '>>> Retrieve a single new Campaign Asset'
142
+ getCampAsset = FuelSDK::ET_Campaign::Asset.new
143
+ getCampAsset.authStub = stubObj
144
+ getCampAsset.props = {"id" => IDOfpostCampaign, "assetId" => IDOfpostCampaignAsset}
145
+ getResponse = getCampAsset.get
146
+ p 'Retrieve Status: ' + getResponse.status.to_s
147
+ p 'Code: ' + getResponse.code.to_s
148
+ p 'Message: ' + getResponse.message.to_s
149
+ p 'Results: ' + getResponse.results.inspect
150
+ p '-----------------------------'
151
+
152
+ raise 'Failure retrieving campaign asset' unless getResponse.success?
153
+
154
+ # Delete the new Campaign Asset
155
+ p '>>> Delete the new Campaign Asset'
156
+ deleteCampAsset = FuelSDK::ET_Campaign::Asset.new
157
+ deleteCampAsset.authStub = stubObj
158
+ deleteCampAsset.props = {"id" => IDOfpostCampaign, "assetId"=> IDOfpostCampaignAsset}
159
+ deleteResponse = deleteCampAsset.delete
160
+ p 'Delete Status: ' + deleteResponse.status.to_s
161
+ p 'Code: ' + deleteResponse.code.to_s
162
+ p 'Message: ' + deleteResponse.message.to_s
163
+ p 'Results: ' + deleteResponse.results.to_json
164
+ p '-----------------------------'
165
+
166
+ raise 'Failure deleting campaign asset' unless deleteResponse.success?
167
+
168
+ # Get a single a new Campaign Asset to confirm deletion
169
+ p '>>> Get a single a new Campaign Asset to confirm deletion'
170
+ getCampAsset = FuelSDK::ET_Campaign::Asset.new
171
+ getCampAsset.authStub = stubObj
172
+ getCampAsset.props = {"id" => IDOfpostCampaign}
173
+ getResponse = getCampAsset.get
174
+ p 'Retrieve Status: ' + getResponse.status.to_s
175
+ p 'Code: ' + getResponse.code.to_s
176
+ p 'Message: ' + getResponse.message.to_s
177
+ p 'Results: ' + getResponse.results.inspect
178
+ p '-----------------------------'
179
+
180
+ raise 'Failure retrieving campaign asset' unless getResponse.success?
181
+ raise 'Failure retrieving campaign asset' unless getResponse.results['totalCount'] == 0
182
+
183
+ rescue => e
184
+ p "Caught exception: #{e.message}"
185
+ p e.backtrace
186
+
187
+ ensure
188
+ # Delete the new Campaign
189
+ p '>>> Delete the new Campaign'
190
+ deleteCamp = FuelSDK::ET_Campaign.new
191
+ deleteCamp.authStub = stubObj
192
+ deleteCamp.props = {"id"=> IDOfpostCampaign}
193
+ deleteResponse = deleteCamp.delete
194
+ p 'Delete Status: ' + deleteResponse.status.to_s
195
+ p 'Code: ' + deleteResponse.code.to_s
196
+ p 'Message: ' + deleteResponse.message.to_s
197
+ p 'Results: ' + deleteResponse.results.to_json
198
+ p '-----------------------------'
199
+
200
+ raise 'Failure deleting campaign asset' unless deleteResponse.success?
201
+
202
+ p '>>> Delete List'
203
+ deleteSub = FuelSDK::ET_List.new()
204
+ deleteSub.authStub = stubObj
205
+ deleteSub.props = {"ID" => ExampleAssetItemID}
206
+ deleteResponse = deleteSub.delete
207
+ p 'Delete Status: ' + deleteResponse.status.to_s
208
+ p 'Code: ' + deleteResponse.code.to_s
209
+ p 'Message: ' + deleteResponse.message.to_s
210
+ p 'Results Length: ' + deleteResponse.results.length.to_s
211
+ p 'Results: ' + deleteResponse.results.to_s
212
+ end
@@ -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 ClickEvents with GetMoreResults'
11
+ getClickEvent = ET_ClickEvent.new()
12
+ getClickEvent.authStub = stubObj
13
+ getClickEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
14
+ getClickEvent.filter = {'Property' => 'EventDate','SimpleOperator' => 'greaterThan','DateValue' => retrieveDate}
15
+ getResponse = getClickEvent.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 ClickEvents with GetMoreResults'
27
+ getResponse = getClickEvent.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 ClickEvents with GetMoreResults'
39
+ getClickEvent = ET_ClickEvent.new()
40
+ getClickEvent.authStub = stubObj
41
+ getClickEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
42
+ getResponse = getClickEvent.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 ClickEvents with GetMoreResults'
54
+ getResponse = getClickEvent.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
+