fuelsdk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/Gemfile +3 -0
- data/Guardfile +8 -0
- data/README.md +117 -0
- data/Rakefile +1 -0
- data/fuelsdk.gemspec +30 -0
- data/lib/fuelsdk.rb +572 -0
- data/lib/fuelsdk/client.rb +142 -0
- data/lib/fuelsdk/http_request.rb +79 -0
- data/lib/fuelsdk/objects.rb +143 -0
- data/lib/fuelsdk/rest.rb +84 -0
- data/lib/fuelsdk/soap.rb +177 -0
- data/lib/fuelsdk/targeting.rb +22 -0
- data/lib/fuelsdk/version.rb +3 -0
- data/lib/new.rb +1204 -0
- data/samples/sample-AddSubscriberToList.rb +52 -0
- data/samples/sample-CreateDataExtensions.rb +51 -0
- data/samples/sample-bounceevent.rb +68 -0
- data/samples/sample-campaign.rb +212 -0
- data/samples/sample-clickevent.rb +68 -0
- data/samples/sample-contentarea.rb +114 -0
- data/samples/sample-dataextension.rb +192 -0
- data/samples/sample-email.rb +114 -0
- data/samples/sample-folder.rb +143 -0
- data/samples/sample-list.rb +105 -0
- data/samples/sample-list.subscriber.rb +97 -0
- data/samples/sample-openevent.rb +68 -0
- data/samples/sample-sentevent.rb +69 -0
- data/samples/sample-subscriber.rb +136 -0
- data/samples/sample-triggeredsend.rb +122 -0
- data/samples/sample-unsubevent.rb +68 -0
- data/samples/sample_helper.rb +8 -0
- data/spec/fuelsdk/client_spec.rb +21 -0
- data/spec/fuelsdk_spec.rb +197 -0
- data/spec/helper_funcs_spec.rb +11 -0
- data/spec/http_request_spec.rb +36 -0
- data/spec/rest_spec.rb +48 -0
- data/spec/soap_spec.rb +44 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/targeting_spec.rb +39 -0
- metadata +239 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'fuelsdk'
|
2
|
+
require_relative 'sample_helper'
|
3
|
+
|
4
|
+
begin
|
5
|
+
stubObj = FuelSDK::ET_Client.new auth
|
6
|
+
|
7
|
+
NewListName = "RubySDKList"
|
8
|
+
|
9
|
+
# Create List
|
10
|
+
p '>>> Create List'
|
11
|
+
postList = FuelSDK::ET_List.new
|
12
|
+
postList.authStub = stubObj
|
13
|
+
postList.props = {"ListName" => NewListName, "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
|
+
raise 'Failure creating list' unless postResponse.success?
|
21
|
+
|
22
|
+
|
23
|
+
# Make sure the list created correctly before
|
24
|
+
if postResponse.success? then
|
25
|
+
|
26
|
+
newListID = postResponse.results[0][:new_id]
|
27
|
+
|
28
|
+
# Retrieve newly created List by ID
|
29
|
+
p '>>> Retrieve newly created List'
|
30
|
+
getList = FuelSDK::ET_List.new()
|
31
|
+
getList.authStub = stubObj
|
32
|
+
getList.props = ["ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Client.PartnerClientKey","ListName","Description","Category","Type","CustomerKey","ListClassification","AutomatedEmail.ID"]
|
33
|
+
getList.filter = {'Property' => 'ID','SimpleOperator' => 'equals','Value' => newListID}
|
34
|
+
getResponse = getList.get
|
35
|
+
p 'Retrieve Status: ' + getResponse.status.to_s
|
36
|
+
p 'Code: ' + getResponse.code.to_s
|
37
|
+
p 'Message: ' + getResponse.message.to_s
|
38
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
39
|
+
p 'Results Length: ' + getResponse.results.length.to_s
|
40
|
+
p 'Results: ' + getResponse.results.to_s
|
41
|
+
raise 'Failure retrieving list' unless getResponse.success?
|
42
|
+
|
43
|
+
# Update List
|
44
|
+
p '>>> Update List'
|
45
|
+
patchSub = FuelSDK::ET_List.new
|
46
|
+
patchSub.authStub = stubObj
|
47
|
+
patchSub.props = {"ID" => newListID, "Description" => "I updated the description"}
|
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
|
+
raise 'Failure updating list' unless patchResponse.success?
|
55
|
+
raise 'Failure updating list' unless patchResponse.results.first[:object][:description] == "I updated the description"
|
56
|
+
|
57
|
+
# Retrieve List that should have description updated
|
58
|
+
p '>>> Retrieve List that should have description updated '
|
59
|
+
getList = FuelSDK::ET_List.new()
|
60
|
+
getList.authStub = stubObj
|
61
|
+
getList.props = ["ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Client.PartnerClientKey","ListName","Description","Category","Type","CustomerKey","ListClassification","AutomatedEmail.ID"]
|
62
|
+
getList.filter = {'Property' => 'ID','SimpleOperator' => 'equals','Value' => newListID}
|
63
|
+
getResponse = getList.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
|
+
raise 'Failure retrieving list' unless getResponse.success?
|
71
|
+
|
72
|
+
# Delete List
|
73
|
+
p '>>> Delete List'
|
74
|
+
deleteSub = FuelSDK::ET_List.new()
|
75
|
+
deleteSub.authStub = stubObj
|
76
|
+
deleteSub.props = {"ID" => newListID}
|
77
|
+
deleteResponse = deleteSub.delete
|
78
|
+
p 'Delete Status: ' + deleteResponse.status.to_s
|
79
|
+
p 'Code: ' + deleteResponse.code.to_s
|
80
|
+
p 'Message: ' + deleteResponse.message.to_s
|
81
|
+
p 'Results Length: ' + deleteResponse.results.length.to_s
|
82
|
+
p 'Results: ' + deleteResponse.results.to_s
|
83
|
+
raise 'Failure deleting list' unless deleteResponse.success?
|
84
|
+
|
85
|
+
# Retrieve List to confirm deletion
|
86
|
+
p '>>> Retrieve List to confirm deletion'
|
87
|
+
getList = FuelSDK::ET_List.new()
|
88
|
+
getList.authStub = stubObj
|
89
|
+
getList.props = ["ID","PartnerKey","CreatedDate","ModifiedDate","Client.ID","Client.PartnerClientKey","ListName","Description","Category","Type","CustomerKey","ListClassification","AutomatedEmail.ID"]
|
90
|
+
getList.filter = {'Property' => 'ID','SimpleOperator' => 'equals','Value' => newListID}
|
91
|
+
getResponse = getList.get
|
92
|
+
p 'Retrieve Status: ' + getResponse.status.to_s
|
93
|
+
p 'Code: ' + getResponse.code.to_s
|
94
|
+
p 'Message: ' + getResponse.message.to_s
|
95
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
96
|
+
p 'Results Length: ' + getResponse.results.length.to_s
|
97
|
+
p 'Results: ' + getResponse.results.to_s
|
98
|
+
raise 'Failure retrieving list' unless getResponse.success?
|
99
|
+
end
|
100
|
+
|
101
|
+
rescue => e
|
102
|
+
p "Caught exception: #{e.message}"
|
103
|
+
p e.backtrace
|
104
|
+
end
|
105
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'fuelsdk'
|
2
|
+
require_relative 'sample_helper'
|
3
|
+
|
4
|
+
begin
|
5
|
+
stubObj = FuelSDK::ET_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
|
+
NewListName = "RubySDKListSubscriber"
|
11
|
+
SubscriberTestEmail = "RubySDKListSubscriber@bh.exacttarget.com"
|
12
|
+
|
13
|
+
# Create List
|
14
|
+
p '>>> Create List'
|
15
|
+
postList = FuelSDK::ET_List.new
|
16
|
+
postList.authStub = stubObj
|
17
|
+
postList.props = {"ListName" => NewListName, "Description" => "This list was created with the RubySDK", "Type" => "Private" }
|
18
|
+
postResponse = postList.post
|
19
|
+
p 'Post Status: ' + postResponse.status.to_s
|
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 posting list' unless postResponse.success?
|
26
|
+
|
27
|
+
|
28
|
+
# Make sure the list created correctly before
|
29
|
+
if postResponse.success? then
|
30
|
+
|
31
|
+
newListID = postResponse.results[0][:new_id]
|
32
|
+
|
33
|
+
# Create Subscriber On List
|
34
|
+
p '>>> Create Subscriber On List'
|
35
|
+
postSub = FuelSDK::ET_Subscriber.new
|
36
|
+
postSub.authStub = stubObj
|
37
|
+
postSub.props = {"EmailAddress" => SubscriberTestEmail, "Lists" =>[{"ID" => newListID}]}
|
38
|
+
postResponse = postSub.post
|
39
|
+
p 'Post Status: ' + postResponse.status.to_s
|
40
|
+
p 'Code: ' + postResponse.code.to_s
|
41
|
+
p 'Message: ' + postResponse.message.to_s
|
42
|
+
p 'Result Count: ' + postResponse.results.length.to_s
|
43
|
+
p 'Results: ' + postResponse.results.inspect
|
44
|
+
|
45
|
+
if postResponse.success? == false then
|
46
|
+
# If the subscriber already exists in the account then we need to do an update.
|
47
|
+
# Update Subscriber On List
|
48
|
+
if postResponse.results[0][:error_code] == "12014" then
|
49
|
+
# Update Subscriber to add to List
|
50
|
+
p '>>> Update Subscriber to add to List'
|
51
|
+
patchSub = FuelSDK::ET_Subscriber.new
|
52
|
+
patchSub.authStub = stubObj
|
53
|
+
patchSub.props = {"EmailAddress" => SubscriberTestEmail, "Lists" =>[{"ID" => newListID}]}
|
54
|
+
patchResponse = patchSub.patch
|
55
|
+
p 'Patch Status: ' + patchResponse.status.to_s
|
56
|
+
p 'Code: ' + patchResponse.code.to_s
|
57
|
+
p 'Message: ' + patchResponse.message.to_s
|
58
|
+
p 'Result Count: ' + patchResponse.results.length.to_s
|
59
|
+
p 'Results: ' + patchResponse.results.inspect
|
60
|
+
raise 'Failure updating subscriber' unless patchResponse.success?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
# Retrieve all Subscribers on the List
|
66
|
+
p '>>> Retrieve all Subscribers on the List'
|
67
|
+
getListSubs = FuelSDK::ET_List::Subscriber.new
|
68
|
+
getListSubs.authStub = stubObj
|
69
|
+
getListSubs.props = ["ObjectID","SubscriberKey","CreatedDate","Client.ID","Client.PartnerClientKey","ListID","Status"]
|
70
|
+
getListSubs.filter = {'Property' => 'ListID','SimpleOperator' => 'equals','Value' => newListID}
|
71
|
+
getResponse = getListSubs.get
|
72
|
+
p 'Retrieve Status: ' + getResponse.status.to_s
|
73
|
+
p 'Code: ' + getResponse.code.to_s
|
74
|
+
p 'Message: ' + getResponse.message.to_s
|
75
|
+
p 'MoreResults: ' + getResponse.more?.to_s
|
76
|
+
p 'Results Length: ' + getResponse.results.length.to_s
|
77
|
+
p 'Results: ' + getResponse.results.to_s
|
78
|
+
raise 'Failure retrieving subscirbers on list' unless getResponse.success?
|
79
|
+
|
80
|
+
# Delete List
|
81
|
+
p '>>> Delete List'
|
82
|
+
deleteSub = FuelSDK::ET_List.new()
|
83
|
+
deleteSub.authStub = stubObj
|
84
|
+
deleteSub.props = {"ID" => newListID}
|
85
|
+
deleteResponse = deleteSub.delete
|
86
|
+
p 'Delete Status: ' + deleteResponse.status.to_s
|
87
|
+
p 'Code: ' + deleteResponse.code.to_s
|
88
|
+
p 'Message: ' + deleteResponse.message.to_s
|
89
|
+
p 'Results Length: ' + deleteResponse.results.length.to_s
|
90
|
+
p 'Results: ' + deleteResponse.results.to_s
|
91
|
+
raise 'Failure deleting list' unless deleteResponse.success?
|
92
|
+
end
|
93
|
+
rescue => e
|
94
|
+
p "Caught exception: #{e.message}"
|
95
|
+
p e.backtrace
|
96
|
+
end
|
97
|
+
|
@@ -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 OpenEvents with GetMoreResults'
|
11
|
+
getOpenEvent = ET_OpenEvent.new()
|
12
|
+
getOpenEvent.authStub = stubObj
|
13
|
+
getOpenEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
|
14
|
+
getOpenEvent.filter = {'Property' => 'EventDate','SimpleOperator' => 'greaterThan','DateValue' => retrieveDate}
|
15
|
+
getResponse = getOpenEvent.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 OpenEvents with GetMoreResults'
|
27
|
+
getResponse = getOpenEvent.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 OpenEvents with GetMoreResults'
|
39
|
+
getOpenEvent = ET_OpenEvent.new()
|
40
|
+
getOpenEvent.authStub = stubObj
|
41
|
+
getOpenEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","PartnerKey"]
|
42
|
+
getResponse = getOpenEvent.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 OpenEvents with GetMoreResults'
|
54
|
+
getResponse = getOpenEvent.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,69 @@
|
|
1
|
+
require '../ET_Client.rb'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
begin
|
5
|
+
stubObj = ET_Client.new(false, false)
|
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 SentEvents with GetMoreResults'
|
12
|
+
getSentEvent = ET_SentEvent.new()
|
13
|
+
getSentEvent.authStub = stubObj
|
14
|
+
getSentEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","ListID","PartnerKey","SubscriberID"]
|
15
|
+
getSentEvent.filter = {'Property' => 'EventDate','SimpleOperator' => 'greaterThan','DateValue' => retrieveDate}
|
16
|
+
getResponse = getSentEvent.get
|
17
|
+
p 'Retrieve Status: ' + getResponse.status.to_s
|
18
|
+
p 'Code: ' + getResponse.code.to_s
|
19
|
+
p 'Message: ' + getResponse.message.to_s
|
20
|
+
p 'MoreResults: ' + getResponse.moreResults.to_s
|
21
|
+
p 'RequestID: ' + getResponse.request_id.to_s
|
22
|
+
p 'Results Length: ' + getResponse.results.length.to_s
|
23
|
+
# Since this could potentially return a large number of results, we do not want to print the results
|
24
|
+
#p 'Results: ' + getResponse.results.to_s
|
25
|
+
|
26
|
+
while getResponse.moreResults do
|
27
|
+
p '>>> Continue Retrieve Filtered SentEvents with GetMoreResults'
|
28
|
+
getResponse = getSentEvent.getMoreResults
|
29
|
+
p 'Retrieve Status: ' + getResponse.status.to_s
|
30
|
+
p 'Code: ' + getResponse.code.to_s
|
31
|
+
p 'Message: ' + getResponse.message.to_s
|
32
|
+
p 'MoreResults: ' + getResponse.moreResults.to_s
|
33
|
+
p 'RequestID: ' + getResponse.request_id.to_s
|
34
|
+
p 'Results Length: ' + getResponse.results.length.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
# The following request could potentially bring back large amounts of data if run against a production account
|
38
|
+
=begin
|
39
|
+
p '>>> Retrieve All SentEvents with GetMoreResults'
|
40
|
+
getSentEvent = ET_SentEvent.new()
|
41
|
+
getSentEvent.authStub = stubObj
|
42
|
+
getSentEvent.props = ["SendID","SubscriberKey","EventDate","Client.ID","EventType","BatchID","TriggeredSendDefinitionObjectID","ListID","PartnerKey","SubscriberID"]
|
43
|
+
getResponse = getSentEvent.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 'RequestID: ' + getResponse.request_id.to_s
|
49
|
+
p 'Results Length: ' + getResponse.results.length.to_s
|
50
|
+
# Since this could potentially return a large number of results, we do not want to print the results
|
51
|
+
#p 'Results: ' + getResponse.results.to_s
|
52
|
+
|
53
|
+
while getResponse.moreResults do
|
54
|
+
p '>>> Continue Retrieve All SentEvents with GetMoreResults'
|
55
|
+
getResponse = getSentEvent.getMoreResults
|
56
|
+
p 'Retrieve Status: ' + getResponse.status.to_s
|
57
|
+
p 'Code: ' + getResponse.code.to_s
|
58
|
+
p 'Message: ' + getResponse.message.to_s
|
59
|
+
p 'MoreResults: ' + getResponse.moreResults.to_s
|
60
|
+
p 'RequestID: ' + getResponse.request_id.to_s
|
61
|
+
p 'Results Length: ' + getResponse.results.length.to_s
|
62
|
+
end
|
63
|
+
=end
|
64
|
+
|
65
|
+
rescue => e
|
66
|
+
p "Caught exception: #{e.message}"
|
67
|
+
p e.backtrace
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'fuelsdk'
|
2
|
+
require_relative 'sample_helper' # contains auth with credentials
|
3
|
+
|
4
|
+
begin
|
5
|
+
stubObj = FuelSDK::ET_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::ET_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::ET_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::ET_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::ET_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::ET_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::ET_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::ET_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
|
+
|