campaigning 0.15.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.
@@ -0,0 +1,159 @@
1
+ require 'rubygems'
2
+ require 'campaigning'
3
+
4
+ CAMPAIGN_MONITOR_API_KEY = '__PUT__YOUR__API__KEY__HERE__'
5
+
6
+
7
+ #Here is how to create a brand new subscriber list
8
+ client = Campaigning::Client.find_by_name("Client One Company")
9
+ list = Campaigning::List.create!(
10
+ :clientID => client.clientID,
11
+ :title => "List from Sample Exec",
12
+ :unsubscribePage => "http://www.mycompany.com/campaign/ubsubscribe.html", #If not suplied or equals blank (""), default value will be used
13
+ :confirmOptIn => false,
14
+ :confirmationSuccessPage => "" #Default value will be used
15
+ )
16
+ puts "Here is the new created List: #{list.name} #{list.listID}"
17
+ #OR you can remove both optional parameters from the method call like below and default values will be used as well:
18
+ list2 = Campaigning::List.create!(
19
+ :clientID => client.clientID,
20
+ :title => "List from Sample Exec2",
21
+ :confirmOptIn => false
22
+ )
23
+ puts "Here is my second new created List (without some params): #{list.name} #{list.listID}"
24
+
25
+
26
+ # SETUP FOR THIS SAMPLE ---------------------------------------------------------------------
27
+
28
+ EMAIL_1 = "another@example.com"
29
+ EMAIL_2 = "mrgree@example.com"
30
+
31
+ #Here is how to add a subscriber (email address, name) to an existing subscriber list.
32
+ subscriber = Campaigning::Subscriber.new(EMAIL_1, "Robert Franklin Jr.")
33
+ result = subscriber.add!(list.listID)
34
+ puts "Was the subscriber add tho the list: #{result.message}"
35
+
36
+ #Here is how to add and resubscribe a Subscriber to an existing subscriber list.
37
+ subscriber = Campaigning::Subscriber.new(EMAIL_2, "Nora Green Mor")
38
+ result = subscriber.add_and_resubscribe!(list.listID)
39
+ puts "Was the subscriber add and resubscribed tho the list: #{result.message}"
40
+
41
+ # /SETUP FOR THIS SAMPLE ---------------------------------------------------------------------
42
+
43
+
44
+
45
+ #Here is how to create a new custom field for a list
46
+ client = Campaigning::Client.find_by_name("Client One Company")
47
+ puts client.inspect
48
+ list = client.find_list_by_name "List from Sample Exec"
49
+ result = list.create_custom_field!(
50
+ :fieldName => "Color" ,
51
+ :dataType => "MultiSelectOne", #This must be one of Text, Number, MultiSelectOne, or MultiSelectMany
52
+ :options => %w[Blue Red Orange]
53
+ )
54
+ #Let's create one more custom field
55
+ result1 = list.create_custom_field!(
56
+ :fieldName => "Contact Type" ,
57
+ :dataType => "MultiSelectOne",
58
+ :options => %w[email post telephone]
59
+ )
60
+ puts "Was my Color custom field created successfuly? #{result.message}"
61
+ puts "Was my Contact Type custom field created successfuly? #{result1.message}"
62
+
63
+
64
+ #Here is how to get all the Custom Fields available for a list
65
+ client = Campaigning::Client.find_by_name("Client One Company")
66
+ list = client.find_list_by_name "List from Sample Exec"
67
+ result = list.custom_fields
68
+ puts result.inspect
69
+ puts "Here is all my Custom fields from the given list: #{result.inspect}"
70
+
71
+
72
+ #How to delete a custom field from a list
73
+ client = Campaigning::Client.find_by_name("Client One Company")
74
+ list = client.find_list_by_name "List from Sample Exec"
75
+ result = list.delete_custom_field!("Color")
76
+ puts "Was my Color custom field deleted successfuly? #{result.message}"
77
+ #Deleting my Contact Type custom Field
78
+ result = list.delete_custom_field!("ContactType")
79
+ puts "Was my Contact Type custom field deleted successfuly? #{result.message}"
80
+
81
+
82
+ #Here is how to get a list of all ACTIVE subscribers for a list that have been added since the specified date.
83
+ client = Campaigning::Client.find_by_name("Client One Company")
84
+ list = client.find_list_by_name "List from Sample Exec"
85
+ subscriber_list = list.find_active_subscribers(DateTime.new(y=2009,m=5,d=01, h=01,min=00,s=00))
86
+ result = subscriber_list.inspect
87
+
88
+
89
+ #Here is how to get all ACTIVE subscribers since ever
90
+ subscriber_list = list.get_all_active_subscribers
91
+ result = subscriber_list.inspect
92
+ puts "Here is all active subscribers from the list: #{result}"
93
+
94
+
95
+ #Here is how to get a range of subscribers by regular expression
96
+ subscriber_list = list.get_all_active_subscribers
97
+ subs_list_found = subscriber_list.find_all{|subscriber| subscriber.emailAddress =~ /[\w]+@example.com/}
98
+ puts "Here is how to get a range of subscribers by regular expression: #{subs_list_found.inspect}"
99
+
100
+
101
+ #Here is how to get a range of subscribers by string matching
102
+ subscriber_list = list.get_all_active_subscribers
103
+ subs_list_found = subscriber_list.find_all{|subscriber| subscriber.name == "Robert Franklin Jr."}
104
+ puts "Here is how to get a range of subscribers by regular expression: #{subs_list_found.inspect}"
105
+
106
+
107
+ #Here is how to get a list’s configuration detail
108
+ client = Campaigning::Client.find_by_name("Client One Company")
109
+ list = client.find_list_by_name "List from Sample Exec"
110
+ result = list.details
111
+ puts "Here is my list configuration details: #{result.inspect}"
112
+
113
+
114
+ #Here is hot to update a subscriber list’s details
115
+ client = Campaigning::Client.find_by_name("Client One Company")
116
+ list = client.find_list_by_name "List from Sample Exec"
117
+ result = list.update!(
118
+ :title => "My new list created by ruby list_sample",
119
+ :unsubscribePage => "", # Default will be used
120
+ :confirmOptIn => false,
121
+ :confirmationSuccessPage => "" #Default will be used
122
+ )
123
+ puts "Was my list updated successfully? #{result.message}"
124
+
125
+
126
+ #Gets a list of all subscribers for a list that have unsubscribed since the specified date.
127
+ client = Campaigning::Client.find_by_name "Client One Company"
128
+ list = client.find_list_by_name "My new list created by ruby list_sample"
129
+ subscriber_list = list.find_unsubscribed(DateTime.new(y=2009,m=4,d=01, h=01,min=00,s=00))
130
+ puts "All subscriber that have unsubscribed from the list: #{subscriber_list.inspect}"
131
+
132
+
133
+ #This method returns all of a particular subscribers details, including email address, name, active/inactive status
134
+ #and all custom field data.
135
+ client = Campaigning::Client.find_by_name "Client One Company"
136
+ list = client.find_list_by_name "My new list created by ruby list_sample"
137
+ subscriber = list.find_single_subscriber(EMAIL_2)
138
+ puts "Subscriber details: #{subscriber.inspect}"
139
+
140
+
141
+ #Here is how to delete a list
142
+ client = Campaigning::Client.find_by_name("Client One Company")
143
+ list = client.find_list_by_name "My new list created by ruby list_sample"
144
+ result = Campaigning::List.delete!(list.listID)
145
+ puts "Was my list deleted successfully? #{result.message}"
146
+
147
+
148
+ #Deleting another list (instance method)
149
+ list = client.find_list_by_name "List from Sample Exec2"
150
+ list.delete!
151
+ puts "Was my second list deleted successfully: #{list.listID}"
152
+
153
+ #Get statistics from a List
154
+ client = Campaigning::Client.find_by_name("Client One Company")
155
+ list = client.find_list_by_name "New list to test BLA"
156
+ puts "List statistics: #{list.stats}"
157
+
158
+
159
+
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require 'campaigning'
3
+
4
+ CAMPAIGN_MONITOR_API_KEY = '__PUT__YOUR__API__KEY__HERE__'
5
+
6
+
7
+ # SETUP FOR THIS SAMPLE ---------------------------------------------------------------------
8
+ #Creating a list for sample execution
9
+ client = Campaigning::Client.find_by_name("Client One Company")
10
+ list = Campaigning::List.create!(
11
+ :clientID => client.clientID,
12
+ :title => "List for Subscriber Sample Exec",
13
+ :confirmOptIn => false
14
+ )
15
+ LIST_ID = list.listID
16
+ puts "New list created: #{list.name} #{list.listID}"
17
+ #Creating a Custom Field for sample execution
18
+ client = Campaigning::Client.find_by_name("Client One Company")
19
+ list = client.find_list_by_name "List for Subscriber Sample Exec"
20
+ result = list.create_custom_field!(:fieldName => "City Name", :dataType => "Text")
21
+ puts "Custom field City Name created successfuly?: #{result.message}"
22
+ result = list.create_custom_field!(:fieldName => "Sponsor Name", :dataType => "Text")
23
+ puts "Custom field Sponsor Name created successfuly?: #{result.message}"
24
+ # /SETUP FOR THIS SAMPLE ---------------------------------------------------------------------
25
+
26
+
27
+
28
+
29
+
30
+ EMAIL_1 = "em4@example.com"
31
+ EMAIL_2 = "em5@example.com"
32
+ EMAIL_3 = "em6@example.com"
33
+
34
+ #Here is how to add a subscriber (email address, name) to an existing subscriber list.
35
+ subscriber = Campaigning::Subscriber.new(EMAIL_1, "Robert Franklin")
36
+ result = subscriber.add!(LIST_ID)
37
+ puts "Was the subscriber add tho the list: #{result.message}"
38
+
39
+
40
+ #Here is how to add and resubscribe a Subscriber to an existing subscriber list.
41
+ subscriber = Campaigning::Subscriber.new(EMAIL_2, "Nora Green")
42
+ result = subscriber.add_and_resubscribe!(LIST_ID)
43
+ puts "Was the subscriber add and resubscribed tho the list: #{result.message}"
44
+
45
+
46
+ #Here is how to add a subscriber WITH CUSTOM FIELDS to an existing subscriber list.
47
+ subscriber = Campaigning::Subscriber.new(EMAIL_3, "Mr. Custon")
48
+ result = subscriber.add!(
49
+ LIST_ID,
50
+ :CityName => "London", :SponsorName => "Some Sponsor from London" #<-- Both Custom Fields for "City Name" and "Sponsor Name"
51
+ )
52
+ puts "Was the subscriber WITH custom fields add tho the list: #{result.message}"
53
+
54
+
55
+
56
+ #Here is how to add and resubscribe a Subscriber WITH CUSTOM FIELDS to an existing subscriber list.
57
+ subscriber = Campaigning::Subscriber.new(EMAIL_3, "Mr. Custon")
58
+ result = subscriber.add_and_resubscribe!(
59
+ LIST_ID,
60
+ :CityName => "Dublin", :SponsorName => "Some Sponsor" #<-- Both Custom Fields for "City Name" and "Sponsor Name"
61
+ )
62
+ puts "Was the subscriber WITH custom fields add and resubscribed tho the list: #{result.message}"
63
+
64
+
65
+ #Here is how to change the status of an Active Subscriber to an Unsubscribed Subscriber who will no longer
66
+ #receive campaigns sent to that Subscriber List.
67
+ result = Campaigning::Subscriber.unsubscribe!(EMAIL_2, LIST_ID)
68
+ #Or you can use a instance method like:
69
+ subscriber = Campaigning::Subscriber.new(EMAIL_1)
70
+ result = subscriber.unsubscribe!(LIST_ID)
71
+ puts "Was the subscriber unsubscribed from the list: #{result.message}"
72
+
73
+
74
+ #Returns True or False as to the existence of the given email address in the list supplied.
75
+ result = Campaigning::Subscriber.is_subscribed?(EMAIL_2, LIST_ID)
76
+ #Or you can use a instance method like:
77
+ subscriber = Campaigning::Subscriber.new(EMAIL_3)
78
+ result = subscriber.is_subscribed?(LIST_ID)
79
+ puts "Was the email subscribed in the list? #{result}"
80
+
81
+
82
+
83
+
84
+ # TEARDOWN FOR THIS SAMPLE --------------------------------------------------------------------
85
+ #Just deleting a list created for sample execution
86
+ list = client.find_list_by_name "List for Subscriber Sample Exec"
87
+ result = Campaigning::List.delete!( list.listID )
88
+ puts "Was the list deleted successfully? #{result.message}"
@@ -0,0 +1,102 @@
1
+ require 'test_helper'
2
+
3
+ # Replace this API key with your own (http://www.campaignmonitor.com/api/)
4
+ CAMPAIGN_MONITOR_API_KEY = '__PUT_YOUR_API_KEY_HERE__'
5
+
6
+ class CampaignTest < Test::Unit::TestCase
7
+
8
+
9
+ def setup
10
+ #Campaigning.set_endpoint_url "http://127.0.0.1:8088/mockapiSoap"
11
+ Campaigning.set_debug_mode(:on)
12
+ end
13
+
14
+ def test_campaign_create
15
+ client = Campaigning::Client.find_by_name("Client One Company")
16
+ response = Campaigning::Campaign.create!(
17
+ :clientID => client.clientID,
18
+ :campaignName => "Campaign by Campaigning TO DELETE - CODEE",
19
+ :campaignSubject => "Campaign by myself - OK - CODEE",
20
+ :fromName => "Mr. Gordon23",
21
+ :fromEmail => "gordon23@test.com",
22
+ :replyTo => "no-reply@test.com",
23
+ :htmlUrl => "http://gnumarcelo.github.com",
24
+ :textUrl => "http://gnumarcelo.github.com",
25
+ :subscriberListIDs => ["ac52b645c048888a44c87b5f1ecf6b7d"],
26
+ :listSegments => client.segments
27
+ )
28
+ puts response.inspect
29
+ end
30
+
31
+
32
+ def test_campaign_delete!
33
+ #client = Campaigning::Client.find_by_name("Client One Company")
34
+ response = Campaigning::Campaign.delete!("4e5952a0840869b77f05b29b9a7a292b")
35
+ puts response.inspect
36
+ end
37
+
38
+ def test_campaign_bounces
39
+ client = Campaigning::Client.find_by_name("Client One Company")
40
+ puts client.campaigns[1].bounces.inspect
41
+ end
42
+
43
+ def test_campaign_lists
44
+ client = Campaigning::Client.find_by_name("Client One Company")
45
+ client.campaigns[0].lists
46
+ end
47
+
48
+ def test_campaign_opens
49
+ client = Campaigning::Client.find_by_name("Client One Company")
50
+ puts client.campaigns[0].opens
51
+ end
52
+
53
+ def test_campaign_find_campaigns_by_subject
54
+ client = Campaigning::Client.find_by_name("Client One Company")
55
+ campaigns = client.find_campaigns_by_subject("Campaign to BOUNCE")
56
+ assert campaign.length > 0
57
+ end
58
+
59
+
60
+ def test_campaign_summary
61
+ client = Campaigning::Client.find_by_name("Client One Company")
62
+ # client.campaigns[2].subscriber_clicks.each do |subscriber|
63
+ # puts "Subscriber: #{subscriber.emailAddress}"
64
+ # subscriber.clickedLinks.each { |clicked| puts "Link: #{clicked.link} - Number of clicks: #{clicked.clicks}"}
65
+ # end
66
+ assert client.campaigns[2].subscriber_clicks != nil
67
+ assert client.campaigns[2].subscriber_clicks != []
68
+
69
+ end
70
+
71
+
72
+ def test_campaign_summary
73
+ client = Campaigning::Client.find_by_name("Client One Company")
74
+ puts client.campaigns[1].summary
75
+ end
76
+
77
+ def test_campaign_unsubscribes
78
+ client = Campaigning::Client.find_by_name("Client One Company")
79
+ puts client.campaigns[0].unsubscribes
80
+ end
81
+
82
+ def test_campaign_send
83
+ client = Campaigning::Client.find_by_name("Client One Company")
84
+ response = Campaigning::Campaign.create!(
85
+ :clientID => client.clientID,
86
+ :campaignName => "Campaign by myself RUBY NEW CREATED",
87
+ :campaignSubject => "Campaign by myself - OK",
88
+ :fromName => "Mr. Gordon2",
89
+ :fromEmail => "gordon2@test.com",
90
+ :replyTo => "no-reply@test.com",
91
+ :htmlUrl => "http://www.campaignmonitor.com/api/method/campaign-create/",
92
+ :textUrl => "http://www.google.com",
93
+ :subscriberListIDs => ["ac52b645c048888a44c87b5f1ecf6b7d"],
94
+ :listSegments => client.segments
95
+ )
96
+
97
+ puts client.campaigns[0].send!(
98
+ :confirmationEmail => "userhdhd@test.com",
99
+ :sendDate => "2009-04-30 11:55:01" # Date format YYYY-MM-DD HH:MM:SS.
100
+ )
101
+ end
102
+ end
@@ -0,0 +1,34 @@
1
+ require 'test_helper'
2
+
3
+ # Replace this API key with your own (http://www.campaignmonitor.com/api/)
4
+ CAMPAIGN_MONITOR_API_KEY = '__PUT_YOUR_API_KEY_HERE__'
5
+
6
+ class CampaigningTest < Test::Unit::TestCase
7
+
8
+
9
+ def setup
10
+ #Campaigning.set_endpoint_url "http://127.0.0.1:8088/mockapiSoap"
11
+ end
12
+
13
+ def test_campaigning_system_date
14
+ date = Campaigning.system_date
15
+ assert !date.nil?
16
+ end
17
+
18
+ def test_user_get_timezones
19
+ timezones = Campaigning.timezones
20
+ assert !timezones.nil?
21
+ end
22
+
23
+ def test_user_countries
24
+ countries = Campaigning.countries
25
+ assert !countries.nil?
26
+ end
27
+
28
+ def test_client_lists
29
+ client = Campaigning::Client.find_by_name("Client One Company")
30
+ assert client.lists.length > 0
31
+ end
32
+
33
+
34
+ end
@@ -0,0 +1,130 @@
1
+ require 'test_helper'
2
+
3
+ # Replace this API key with your own (http://www.campaignmonitor.com/api/)
4
+ CAMPAIGN_MONITOR_API_KEY = '__PUT_YOUR_API_KEY_HERE__'
5
+
6
+
7
+
8
+ class ClientTest < Test::Unit::TestCase
9
+
10
+
11
+ def setup
12
+ #Campaigning.set_endpoint_url "http://127.0.0.1:8088/mockapiSoap"
13
+ #Campaigning.set_debug_mode(:on)
14
+ end
15
+
16
+ def test_client_get_templates
17
+ client = Campaigning::Client.get_all_clients.first
18
+ puts "#{client.name} - #{client.clientID}"
19
+ puts "Templates: #{client.templates.inspect}"
20
+ end
21
+
22
+ def test_client_get_all_clients
23
+ clients = Campaigning::Client.get_all_clients
24
+ assert clients.length > 0
25
+ #clients.each{ |c| puts c.clientID + " - " + c.name }
26
+ end
27
+
28
+ def test_client_create!
29
+ client_created = Campaigning::Client.create!(
30
+ :companyName => "My test clients22",
31
+ :contactName => "Oswald Green15s25",
32
+ :emailAddress => "og1524s@example.com",
33
+ :country => "Ireland",
34
+ :timezone => Campaigning.timezones[1]
35
+ )
36
+ assert !client_created.clientID.nil?
37
+ end
38
+
39
+ def test_client_delete
40
+ response = Campaigning::Client.delete!(client_created.clientID)
41
+ assert response.code == 0
42
+ end
43
+
44
+ def test_client_delete_itself
45
+ client = Campaigning::Client.find_by_name("Orange Company 7")
46
+ client.delete!
47
+ end
48
+
49
+ def test_client_segments
50
+ client = Campaigning::Client.find_by_name("Client One Company")
51
+ assert client.segments.length > 0
52
+ end
53
+
54
+
55
+ def test_find_client_by_name
56
+ client = Campaigning::Client.find_by_name("Client One Company")
57
+ assert !client.nil? && client.name == "Client One Company"
58
+ end
59
+
60
+
61
+ def test_get_client_campaigns
62
+ client = Campaigning::Client.find_by_name("Client One Company")
63
+ puts client.campaigns.inspect
64
+ end
65
+
66
+ def test_get_client_details
67
+ client = Campaigning::Client.find_by_name("Client One Company")
68
+ client_details = client.details
69
+ basic_details = client_details.basicDetails
70
+ access_and_billing_details = client_details.accessAndBilling
71
+ puts "Basic details:"
72
+ puts "Client ID: #{basic_details.clientID} - \n
73
+ Company: #{basic_details.companyName} - \n
74
+ Contact: #{basic_details.contactName} - \n
75
+ Country: #{basic_details.country} - \n
76
+ Timezone: #{basic_details.timezone}"
77
+
78
+ puts "Access and Billing Details:"
79
+ puts "Username: #{access_and_billing_details.username} - \n
80
+ Password: #{access_and_billing_details.password} - \n
81
+ Billing Type: #{access_and_billing_details.billingType} - \n
82
+ Currency: #{access_and_billing_details.currency} - \n
83
+ Delivery Fee: #{access_and_billing_details.deliveryFee} - \n
84
+ Cost per Recipient: #{access_and_billing_details.costPerRecipient} - \n
85
+ Design and Span test Fee: #{access_and_billing_details.designAndSpamTestFee} - \n
86
+ Access Level: #{access_and_billing_details.accessLevel}"
87
+
88
+ assert !client.details.nil?
89
+
90
+ end
91
+
92
+ def test_get_client_suppression_list
93
+ client = Campaigning::Client.find_by_name("Client One Company")
94
+ puts client.suppression_list.inspect
95
+ end
96
+
97
+ def test_client_update_access_and_billing!
98
+ client = Campaigning::Client.find_by_name("Client One Company")
99
+ response = client.update_access_and_billing!(
100
+ :accessLevel => 5 ,
101
+ :username => "client_one",
102
+ :password => "1234560",
103
+ :billingType => "UserPaysOnClientsBehalf",
104
+ :currency => "USD",
105
+ :deliveryFee => 6.5,
106
+ :costPerRecipient => 1.5 ,
107
+ :designAndSpamTestFee => 5
108
+ )
109
+ assert response.code == 0
110
+ end
111
+
112
+ def test_client_update_basics!
113
+ client = Campaigning::Client.find_by_name("Client Two")
114
+ response = client.update_basics!(
115
+ :companyName => "My new Company",
116
+ :contactName => "Mr. Gordon Newman",
117
+ :emailAddress => "gordon-newman@test.com",
118
+ :country => "Ireland",
119
+ :timezone => Campaigning.timezones[1]
120
+ )
121
+ assert response.code == 0
122
+ end
123
+
124
+ def test_client_find_list_by_name
125
+ client = Campaigning::Client.find_by_name("Client One Company")
126
+ list = client.find_list_by_name "My Friends"
127
+ assert list.nil? == false
128
+ end
129
+
130
+ end