gnumarcelo-campaigning 0.7.0 → 0.8.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.
- data/README.rdoc +36 -5
- data/Rakefile +2 -0
- data/VERSION.yml +1 -1
- data/lib/campaigning/campaigning.rb +17 -25
- data/lib/campaigning/helpers/helpers.rb +18 -13
- data/lib/campaigning/soap/soap_driver.rb +6 -0
- data/lib/campaigning/types/campaign.rb +106 -1
- data/lib/campaigning/types/client.rb +207 -18
- data/lib/campaigning/types/list.rb +154 -1
- data/lib/campaigning/types/subscriber.rb +78 -30
- data/test/campaigning_test.rb +96 -54
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,16 +1,47 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
= campaigning
|
1
|
+
= Campaigning
|
4
2
|
|
5
3
|
This RubyGem provides access to the CampaignMonitor API(www.campaignmonitor.com/api) using SOAP.
|
6
4
|
|
7
|
-
|
8
|
-
|
5
|
+
|
6
|
+
== Pre-requisites
|
7
|
+
An account with Campaign Monitor and the API Key (www.campaignmonitor.com).
|
8
|
+
|
9
|
+
|
10
|
+
== Resources
|
11
|
+
|
12
|
+
=== Dependencies
|
13
|
+
|
14
|
+
This gem requires the following gems:
|
9
15
|
|
10
16
|
Soap4r (1.5.8)
|
11
17
|
|
12
18
|
Jeweler (http://technicalpickles.com/posts/craft-the-perfect-gem-with-jeweler)
|
13
19
|
|
20
|
+
=== Installing
|
21
|
+
|
22
|
+
sudo gem install gnumarcelo-campaigning -s http://gems.github.com
|
23
|
+
|
24
|
+
|
25
|
+
== How to play
|
26
|
+
|
27
|
+
Just set a constant named *CAMPAIGN_MONITOR_API_KEY* with your Campaign monitor API key and start to play like the examples below:
|
28
|
+
|
29
|
+
Sample use of the Client class:
|
30
|
+
|
31
|
+
#Here is how to get a list of all clients...
|
32
|
+
clients = Campaigning::Client.get_all_clients
|
33
|
+
|
34
|
+
|
35
|
+
#Here is how to create a brand new subscriber list for an Client
|
36
|
+
client = Campaigning::Client.find_by_name("Client One Company")
|
37
|
+
list = Campaigning::List.create(
|
38
|
+
:client_id => client.clientID,
|
39
|
+
:title => "List of people from Brazil",
|
40
|
+
:comfirm_opt_in => false
|
41
|
+
)
|
42
|
+
|
43
|
+
For further examples please check at the *sample* directory.
|
44
|
+
|
14
45
|
|
15
46
|
== Copyright
|
16
47
|
|
data/Rakefile
CHANGED
data/VERSION.yml
CHANGED
@@ -7,37 +7,29 @@ require File.expand_path(File.dirname(__FILE__)) + '/types/list.rb'
|
|
7
7
|
require File.expand_path(File.dirname(__FILE__)) + '/helpers/helpers.rb'
|
8
8
|
|
9
9
|
module Campaigning
|
10
|
-
class Base
|
11
10
|
include Helpers
|
12
|
-
attr_reader :api_key
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@soap = Campaigning::SOAPDriver.instance.get_driver
|
21
|
-
setup_debug_mode options[:debug]
|
12
|
+
#Gets the server system time for your time zone.
|
13
|
+
#This is handy for when you are syncing your {Campaign Monitor}[http://www.campaignmonitor.com] lists with some other in-house list,
|
14
|
+
#allowing you accurately determine the time on our server when you carry out the synchronization.
|
15
|
+
def self.system_date
|
16
|
+
response = Campaigning::SOAPDriver.instance.get_driver.getSystemDate(:apiKey => CAMPAIGN_MONITOR_API_KEY)
|
17
|
+
dateTime = Helpers.handle_request response.user_GetSystemDateResult
|
22
18
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
clients.collect {|client| Client.new(client.clientID, client.name)}
|
28
|
-
end
|
29
|
-
|
30
|
-
def system_date
|
31
|
-
handle_request @soap.getSystemDate(:apiKey => @api_key).user_GetSystemDateResult
|
19
|
+
|
20
|
+
#This method returns an Array of Strings representing all the available timezones.
|
21
|
+
def self.time_zones
|
22
|
+
Helpers.handle_request Campaigning::SOAPDriver.instance.get_driver.getTimezones(:apiKey => CAMPAIGN_MONITOR_API_KEY).user_GetTimezonesResult
|
32
23
|
end
|
33
24
|
|
34
|
-
|
35
|
-
|
25
|
+
#This method returns an Array of Strings representing all the available countries.
|
26
|
+
def self.countries
|
27
|
+
response = Campaigning::SOAPDriver.instance.get_driver.getCountries(:apiKey => CAMPAIGN_MONITOR_API_KEY)
|
28
|
+
dateTime = Helpers.handle_request response.user_GetCountriesResult
|
36
29
|
end
|
37
30
|
|
38
|
-
|
31
|
+
#This method turns on and off the API debug mode, which will display at the console all SOAP requests made to the API server.
|
32
|
+
def self.setup_debug_mode(dev)
|
39
33
|
Campaigning::SOAPDriver.instance.setup_debug_mode dev
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
34
|
+
end
|
43
35
|
end
|
@@ -1,14 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Campaigning
|
2
|
+
module Helpers
|
3
|
+
#Method responsable to handle all response from the API server and raising an exception when
|
4
|
+
#the API returns an error code (different from 0 (zero) ).
|
5
|
+
def handle_request(response)
|
6
|
+
Helpers.handle_request response
|
7
|
+
end
|
8
|
+
|
9
|
+
#Method responsable to handle all response from the API server and raising an exception when
|
10
|
+
#the API returns an error code (different from 0 (zero) ).
|
11
|
+
def Helpers.handle_request(response)
|
12
|
+
if (response.class == Campaigning::Result && response.code != 0)
|
13
|
+
raise response.code.to_s + " - " + response.message
|
5
14
|
end
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
response
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
+
response
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -2,14 +2,20 @@ require File.expand_path(File.dirname(__FILE__)) + '/generated/defaultDriver.rb'
|
|
2
2
|
require 'singleton'
|
3
3
|
|
4
4
|
module Campaigning
|
5
|
+
#A SOAPDriver is a singleton object responsable to supply a way to interact with the SOAP::RPC::Driver object.
|
5
6
|
class SOAPDriver #It could be a module
|
6
7
|
include Singleton
|
7
8
|
DefaultEndpointUrl = "http://api.createsend.com/api/api.asmx"
|
8
9
|
|
10
|
+
#Return a unique Campaigning::SOAP::ApiSoap instance for the whole API client, which provides access to
|
11
|
+
#all the Campaign Monitor API methods.
|
9
12
|
def get_driver
|
10
13
|
@driver ||= Campaigning::ApiSoap.new(DefaultEndpointUrl)
|
11
14
|
end
|
12
15
|
|
16
|
+
#This method turns the API debug mode to _on_ and _off_.
|
17
|
+
#When method called with _true_ argument, it will switch to _on_ mode, the API will display at the console all
|
18
|
+
#SOAP requests made to the API server.
|
13
19
|
def setup_debug_mode(dev)
|
14
20
|
dev = STDERR if dev == true
|
15
21
|
@driver.wiredump_dev = dev
|
@@ -20,6 +20,29 @@ module Campaigning
|
|
20
20
|
@soap = Campaigning::SOAPDriver.instance.get_driver
|
21
21
|
end
|
22
22
|
|
23
|
+
#Creates a campaign for an existing client. This campaign will be imported and ready to send to the subscribers in
|
24
|
+
#the specified lists and segments.
|
25
|
+
#The campaign must have both HTML and plain text content, imported from the internet. Styling for the HTML content
|
26
|
+
#will be automatically brought inline.
|
27
|
+
#
|
28
|
+
#Available _params_ argument are:
|
29
|
+
# * :clientID - The ID of the Client you want to create a campaign
|
30
|
+
# * :campaignName - The name of the new campaign. This must be unique across all draft campaigns for the client.
|
31
|
+
# * :campaignSubject - The subject of the new campaign.
|
32
|
+
# * :fromName - The name to appear in the From field in the recipients email client when they receive the new campaign.
|
33
|
+
# * :fromEmail - The email address that the new campaign will come from.
|
34
|
+
# * :replyTo - The email address that any replies to the new campaign will be sent to.
|
35
|
+
# * :htmlUrl - The URL of the HTML content for the new campaign. If no unsubscribe link is found then one will be added automatically. Styling in
|
36
|
+
# the campaign will be automatically brought inline. If your URL has querystring values, you will need to encode them.
|
37
|
+
# * :textUrl - The URL of the Text content for the new campaign. If no unsubscribe link is found then one will be added automatically.
|
38
|
+
# * :subscriberListIDs - An array of lists to send the campaign to. See http://www.campaignmonitor.com/api/required/#listid for more details.
|
39
|
+
# * :listSegments - An array of Segment Names and their appropriate List ID s to send the campaign to.
|
40
|
+
#
|
41
|
+
#*Return*:
|
42
|
+
#
|
43
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Campaign object which was recently created.
|
44
|
+
#
|
45
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
23
46
|
def self.create(params)
|
24
47
|
response = Campaigning::SOAPDriver.instance.get_driver.createCampaign(
|
25
48
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -39,36 +62,118 @@ module Campaigning
|
|
39
62
|
Campaign.new campaign_id
|
40
63
|
end
|
41
64
|
|
65
|
+
#Gets a list of all subscribers who bounced for a given campaign, and the type of bounce (H=Hard Bounce, S=Soft Bounce).
|
66
|
+
#
|
67
|
+
#*Return*:
|
68
|
+
#
|
69
|
+
#*Success*: Upon a successful call, this method will return a collection of <code>SubscriberBounce</code> objects, each of
|
70
|
+
#which consists of the subscribers <code>:emailAddress</code>, the <code>listID</code> they belong to, and the <code>bounceType</code>
|
71
|
+
#of bounce they experienced, whether hard or soft.
|
72
|
+
#
|
73
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
42
74
|
def bounces
|
43
75
|
response = @soap.getCampaignBounces(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
|
44
76
|
handle_request response.campaign_GetBouncesResult
|
45
77
|
end
|
46
78
|
|
79
|
+
#Returns an array of Campaigning::List objects that a given campaign was sent to.
|
80
|
+
#
|
81
|
+
#*Return*:
|
82
|
+
#
|
83
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::List object.
|
84
|
+
#
|
85
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
47
86
|
def lists
|
48
87
|
response = @soap.getCampaignLists(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
|
49
|
-
handle_request response.campaign_GetListsResult
|
88
|
+
lists = handle_request response.campaign_GetListsResult
|
89
|
+
puts "LISTAS!!!!!!!!!!" + lists.inspect
|
90
|
+
lists.collect do |list|
|
91
|
+
List.new(list.listID, list.name)
|
92
|
+
end
|
50
93
|
end
|
51
94
|
|
95
|
+
#Gets a list of all subscribers who opened a given campaign, and the number of times they opened the campaign.
|
96
|
+
#
|
97
|
+
#*Return*:
|
98
|
+
#
|
99
|
+
#*Success*: Upon a successful call, this method will return a collection of <code>SubscriberOpen</code> objects, each of
|
100
|
+
#which consists of the subscribers <code>:emailAddress</code>, the <code>listID</code> they belong to, and the <code>numberOfOpens</code>
|
101
|
+
#representing the number of times they opened the given campaign.
|
102
|
+
#
|
103
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
52
104
|
def opens
|
53
105
|
response = @soap.getCampaignOpens(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
|
54
106
|
handle_request response.campaign_GetOpensResult
|
55
107
|
end
|
56
108
|
|
109
|
+
#Gets a list of all subscribers who clicked a link for a given campaign, the ID of the list they belong to,
|
110
|
+
#the links they clicked, and the number of times they clicked the link.
|
111
|
+
#
|
112
|
+
#Example of usage:
|
113
|
+
#
|
114
|
+
# campaign_obj.subscriber_clicks.each do |subscriber|
|
115
|
+
# puts "Subscriber: #{subscriber.emailAddress}"
|
116
|
+
# subscriber.clickedLinks.each do |clicked|
|
117
|
+
# puts "Clicked link: #{clicked.link} - Number of clicks: #{clicked.clicks}"
|
118
|
+
# end
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
#
|
122
|
+
#*Return*:
|
123
|
+
#
|
124
|
+
#*Success*: Upon a successful call, this method will return a collection of <code>SubscriberClick</code> objects, each of which consists of
|
125
|
+
#the subscribers <code>emailAddress</code>, the <code>listID</code> representing list they belong to, and the <code>clickedLinks</code>array
|
126
|
+
#representing the links they have clicked and the number of times they clicked each link.
|
127
|
+
#
|
128
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
57
129
|
def subscriber_clicks
|
58
130
|
response = @soap.getSubscriberClicks(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
|
59
131
|
handle_request response.campaign_GetSubscriberClicksResult
|
60
132
|
end
|
61
133
|
|
134
|
+
#Gets a statistical summary, including number of recipients and open count, for a given campaign.
|
135
|
+
#
|
136
|
+
#*Return*:
|
137
|
+
#
|
138
|
+
#*Success*: Upon a successful call, this method will return summary statistical values about this particular campaign
|
139
|
+
#including the number of recipients, the number of total opens, the number of link clicks, the number of recipients
|
140
|
+
#who unsubscribed and the number who bounced.
|
141
|
+
#
|
142
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
62
143
|
def summary
|
63
144
|
response = @soap.getCampaignSummary(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
|
64
145
|
handle_request response.campaign_GetSummaryResult
|
65
146
|
end
|
66
147
|
|
148
|
+
#Gets a list of all subscribers who unsubscribed for a given campaign.
|
149
|
+
#
|
150
|
+
#*Return*:
|
151
|
+
#
|
152
|
+
#*Success*: Upon a successful call, this method will return a collection of SubscriberUnsubscribe objects, each of which consists
|
153
|
+
#of the <code>emailAddress</code> representing subscribers email address and the <code>listID</code> representing the list they belong to.
|
154
|
+
#
|
155
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
67
156
|
def unsubscribes
|
68
157
|
response = @soap.getCampaignUnsubscribes(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
|
69
158
|
handle_request response.campaign_GetUnsubscribesResult
|
70
159
|
end
|
71
160
|
|
161
|
+
#Schedules an existing campaign for sending.
|
162
|
+
#
|
163
|
+
#The campaign must be imported with defined recipients. For campaigns with more than 5 recipients the user must have
|
164
|
+
#sufficient credits or their credit card details saved within the application for the campaign to be sent via the API.
|
165
|
+
#For campaigns with 5 recipients or less the user must have enough test campaigns remaining in their API account.
|
166
|
+
#For further information about credits for campaigns please check at: http://www.campaignmonitor.com/api/method/campaign-send/
|
167
|
+
#
|
168
|
+
#Available _params_ argument are:
|
169
|
+
# * :confirmation_email - The email address that the confirmation email that the campaign has been sent will go to.
|
170
|
+
# * :send_date - The date the campaign should be scheduled to be sent. To send a campaign immediately pass in "Immediately".
|
171
|
+
# This date should be in the users timezone and formatted as YYYY-MM-DD HH:MM:SS.
|
172
|
+
#
|
173
|
+
#*Return*:
|
174
|
+
#Upon a successful call, this method will return a Result object with the newly create Campaign's ID as the Code.
|
175
|
+
#
|
176
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
72
177
|
def send(params)
|
73
178
|
response = @soap.sendCampaign(
|
74
179
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -12,28 +12,84 @@ class Client
|
|
12
12
|
def initialize(clientID = nil, name = nil)
|
13
13
|
@clientID = clientID
|
14
14
|
@name = name
|
15
|
-
#@cm = Campaigning::Base.new
|
16
15
|
@soap = Campaigning::SOAPDriver.instance.get_driver
|
17
16
|
end
|
18
17
|
|
18
|
+
#Gets a list of all subscriber lists for a client.
|
19
|
+
#
|
20
|
+
#*Return*:
|
21
|
+
#
|
22
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::List objects.
|
23
|
+
#
|
24
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
19
25
|
def lists
|
20
26
|
response = @soap.getClientLists(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID)
|
21
27
|
lists = handle_request response.client_GetListsResult
|
22
28
|
lists.collect {|list| List.new(list.listID, list.name)}
|
23
29
|
end
|
24
30
|
|
31
|
+
#This method find a List by a given name
|
32
|
+
#
|
33
|
+
#*Return*:
|
34
|
+
#
|
35
|
+
#*Success*:
|
36
|
+
#
|
37
|
+
#List FOUND: If it found any client with the given name it will return a Campaigning::List object containing the found list.
|
38
|
+
#
|
39
|
+
#List NOT FOUND: If it doesn't found a list with the given name it will return +nil+ .
|
40
|
+
#
|
41
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
25
42
|
def find_list_by_name(list_name)
|
26
43
|
lists.find {|list| list_name == list.name}
|
27
44
|
end
|
28
45
|
|
29
|
-
#
|
30
|
-
#
|
46
|
+
#This method find a Client by a given name
|
47
|
+
#
|
48
|
+
#*Return*:
|
49
|
+
#
|
50
|
+
#Client FOUND: If it found any client with the given name it will return a Campaigning::Client object containing the found client.
|
51
|
+
#
|
52
|
+
#Client NOT FOUND: If it doesn't found a client with the given name it will return +nil+ .
|
53
|
+
#
|
54
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
55
|
+
#-- TODO: Refactor this method and increase performance?
|
56
|
+
#-- TODO: Tha campaign monitor permit two users with the same name, what to do?
|
31
57
|
def self.find_by_name(name)
|
32
|
-
client_list =
|
58
|
+
client_list = Client.get_all_clients
|
33
59
|
client_found = client_list.find {|client| name == client.name}
|
34
60
|
Client.new(client_found.clientID, client_found.name) if client_found
|
35
61
|
end
|
36
62
|
|
63
|
+
#Gets all clients for a given user (CAMPAIGN_MONITOR_API_KEY).
|
64
|
+
#
|
65
|
+
#*Return*:
|
66
|
+
#
|
67
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::Client objects.
|
68
|
+
#
|
69
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
70
|
+
def self.get_all_clients
|
71
|
+
response = Campaigning::SOAPDriver.instance.get_driver.getClients(:apiKey => CAMPAIGN_MONITOR_API_KEY)
|
72
|
+
clients = Helpers.handle_request response.user_GetClientsResult
|
73
|
+
clients.collect {|client| Client.new(client.clientID, client.name)}
|
74
|
+
end
|
75
|
+
|
76
|
+
#This method creates a brand new client with no access to the application.
|
77
|
+
#By default a new client has no direct access to the application. Access and billing settings (if needed) must be set by
|
78
|
+
#means of a subsequent call to Campaigning::Client#update_access_and_billing.
|
79
|
+
#
|
80
|
+
#Available _params_ argument are:
|
81
|
+
# * :company_name - The client company name.
|
82
|
+
# * :contact_name - The personal name of the principle contact for this client.
|
83
|
+
# * :email_address - An email address to which this client will be sent application-related emails.
|
84
|
+
# * :country - This client's country. A valid country list is available in http://www.campaignmonitor.com/api/countries/ or by
|
85
|
+
# using the API procedure Campaigning.countries
|
86
|
+
# * :time_zone - Client timezone for tracking and reporting data. A valid timezone list is available here or by using the API
|
87
|
+
# procedure Campaigning.time_zones.
|
88
|
+
#*Return*:
|
89
|
+
#
|
90
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Client object representing the newly created client.
|
91
|
+
#
|
92
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
37
93
|
def self.create(params)
|
38
94
|
response = Campaigning::SOAPDriver.instance.get_driver.createClient(
|
39
95
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -43,33 +99,75 @@ class Client
|
|
43
99
|
:country => params[:country],
|
44
100
|
:timezone => params[:time_zone]
|
45
101
|
)
|
46
|
-
Client.new( Helpers.handle_request(response.client_CreateResult) )
|
102
|
+
Client.new( Helpers.handle_request(response.client_CreateResult), params[:company_name] )
|
47
103
|
end
|
48
104
|
|
105
|
+
#Deletes a client from your account.
|
106
|
+
#
|
107
|
+
#*Return*:
|
108
|
+
#
|
109
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
110
|
+
#containing a successful message.
|
111
|
+
#
|
112
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
49
113
|
def delete
|
50
|
-
Client.delete(@clientID)
|
51
|
-
self.clientID = nil
|
52
|
-
|
114
|
+
response = Client.delete(@clientID)
|
115
|
+
self.clientID, self.name = nil
|
116
|
+
response
|
53
117
|
end
|
54
118
|
|
119
|
+
#Deletes a client from your account.
|
120
|
+
#
|
121
|
+
#*Return*:
|
122
|
+
#
|
123
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
124
|
+
#containing a successful message.
|
125
|
+
#
|
126
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
55
127
|
def self.delete(client_id)
|
56
128
|
response = Campaigning::SOAPDriver.instance.get_driver.deleteClient(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => client_id)
|
57
129
|
Helpers.handle_request response.client_DeleteResult
|
58
130
|
end
|
59
131
|
|
60
|
-
|
132
|
+
#Gets a list of all subscriber segments for a client.
|
133
|
+
#
|
134
|
+
#*Return*:
|
135
|
+
#
|
136
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::List objects, each of which consists of the ListID
|
137
|
+
#for the parent list and Segment Name for each segment for a client.
|
138
|
+
#
|
139
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
140
|
+
def segments # TODO: Verify the type return for this method.
|
61
141
|
response = @soap.getClientSegments(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID )
|
62
142
|
handle_request response.client_GetSegmentsResult
|
63
143
|
end
|
64
144
|
|
65
|
-
#
|
66
|
-
|
145
|
+
#This method finds campaigns by a given subject, since the subject isn't unique, it returns an collection of
|
146
|
+
#Campaigning::Campaign object.
|
147
|
+
#
|
148
|
+
#*Return*:
|
149
|
+
#
|
150
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::Campaign objects.
|
151
|
+
#
|
152
|
+
#Campaign FOUND: If it found any campaign with the given subject it will return a collection of Campaigning::Campaign that match the criteria.
|
153
|
+
#
|
154
|
+
#Campaign NOT FOUND: If it doesn't found a campaign with the given subject it will return an empty array.
|
155
|
+
#
|
156
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
157
|
+
def find_campaigns_by_subject(subject)#-- TODO: Refactor this method
|
67
158
|
arr = []
|
68
159
|
#return campaigns.find {|campaign| subject == campaign.subject} if params[:single]
|
69
160
|
campaigns.each { |campaign| arr << campaign if campaign.subject == subject }
|
70
161
|
arr
|
71
162
|
end
|
72
163
|
|
164
|
+
#Gets a list of all campaigns that have been sent for a client.
|
165
|
+
#
|
166
|
+
#*Return*:
|
167
|
+
#
|
168
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::Campaign objects.
|
169
|
+
#
|
170
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
73
171
|
def campaigns
|
74
172
|
response = @soap.getClientCampaigns(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID )
|
75
173
|
campaign_list = handle_request response.client_GetCampaignsResult
|
@@ -78,32 +176,123 @@ class Client
|
|
78
176
|
end
|
79
177
|
end
|
80
178
|
|
179
|
+
#This method gets the complete account and billing details for a particular client.
|
180
|
+
#
|
181
|
+
#Example of usage:
|
182
|
+
# client_details = client_obj.details
|
183
|
+
# basic_details = client_details.basicDetails
|
184
|
+
# access_and_billing_details = client_details.accessAndBilling
|
185
|
+
# puts "Basic details:"
|
186
|
+
# puts "Client ID: #{basic_details.clientID}\n
|
187
|
+
# Company: #{basic_details.companyName}\n
|
188
|
+
# Contact: #{basic_details.contactName}\n
|
189
|
+
# Country: #{basic_details.country}\n
|
190
|
+
# Timezone: #{basic_details.timezone}"
|
191
|
+
#
|
192
|
+
# puts "Access and Billing Details:"
|
193
|
+
# puts "Username: #{access_and_billing_details.username}\n
|
194
|
+
# Password: #{access_and_billing_details.password}\n
|
195
|
+
# Billing Type: #{access_and_billing_details.billingType}\n
|
196
|
+
# Currency: #{access_and_billing_details.currency}\n
|
197
|
+
# Delivery Fee: #{access_and_billing_details.deliveryFee}\n
|
198
|
+
# Cost per Recipient: #{access_and_billing_details.costPerRecipient}\n
|
199
|
+
# Design and Span test Fee: #{access_and_billing_details.designAndSpamTestFee}\n
|
200
|
+
# Access Level: #{access_and_billing_details.accessLevel}"
|
201
|
+
#
|
202
|
+
#*Return*:
|
203
|
+
#
|
204
|
+
#*Success*: A successful call to this method will return a ClientDetail object, comprised of ClientBasicDetails
|
205
|
+
#and ClientAccessAndBilling.
|
206
|
+
#
|
207
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
81
208
|
def details
|
82
209
|
response = @soap.getClientDetail(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID )
|
83
210
|
handle_request response.client_GetDetailResult
|
84
211
|
end
|
85
212
|
|
213
|
+
#Gets all subscribers in the client-wide suppression list.
|
214
|
+
#
|
215
|
+
#*Return*:
|
216
|
+
#
|
217
|
+
#*Success*: Upon a successful call, this method will return a collection of Subscriber objects.
|
218
|
+
#
|
219
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
86
220
|
def suppression_list
|
87
221
|
response = @soap.getClientSuppressionList(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID )
|
88
222
|
handle_request response.client_GetSuppressionListResult
|
89
223
|
end
|
90
224
|
|
225
|
+
#Update the access and billing settings of an existing client, leaving the basic details untouched.
|
226
|
+
#
|
227
|
+
#Here's a list of all the parameters you'll need to pass to the Campaigning::Client#update_access_and_billing method. Only the :+access_level+ parameter
|
228
|
+
#is required for all calls. The relevance and necessity of the other parameters depends on the chosen AccessLevel (and BillingType),
|
229
|
+
#and will be fully described along with each parameter.
|
230
|
+
#
|
231
|
+
#Available _params_ argument are:
|
232
|
+
# * :access_level - An integer describing the client's ability to access different areas of the application. Influences the significance
|
233
|
+
# and requirements of the following parameters. See http://www.campaignmonitor.com/api/method/client-updateaccessandbilling/#accesslevels
|
234
|
+
# for a full description of available levels.
|
235
|
+
# * :username - Client login username. Not required and ignored if AccessLevel is set to 0.
|
236
|
+
# * :password - Client login password. Not required and ignored if AccessLevel is set to 0.
|
237
|
+
# * :billing_type - Client billing type, only required if :access_level is set to allow the client to create and send campaigns
|
238
|
+
# * :currency - Billing currency for this client, only required if :billing_type is set to either ClientPaysAtStandardRate or
|
239
|
+
# ClientPaysWithMarkup. See full details: http://www.campaignmonitor.com/api/method/client-updateaccessandbilling/#currencies.
|
240
|
+
# * :delivery_fee - Flat rate delivery fee to be charged to the client for each campaign sent, expressed in the chosen currency's
|
241
|
+
# major unit, but without the currency symbol (for example, sending "6.5" means "$6.50" if USD is used). Only
|
242
|
+
# required if BillingType is set to ClientPaysWithMarkup, in which case it should be at least equal to the standard rate.
|
243
|
+
# Further detail is available at http://help.campaignmonitor.com/topic.aspx?t=118.
|
244
|
+
# * :cost_per_recipient - Additional cost added to the campaign for each email address the campaign is sent to, expressed in the chosen
|
245
|
+
# currency's minor unit (for example, sending "1.5" means 1.5 cents per email address if USD is used). Only required
|
246
|
+
# if BillingType is set to ClientPaysWithMarkup, in which case it should be at least equal to the standard cost/recipient
|
247
|
+
# rate. Further detail is available at http://help.campaignmonitor.com/topic.aspx?t=118.
|
248
|
+
# * :design_and_spam_test_fee - Expressed in the chosen currency's major unit (for example, sending "10" means "$10" if USD is used). Only required
|
249
|
+
# if BillingType is set to ClientPaysWithMarkup and client has access to design and spam tests, in which case the fee
|
250
|
+
# should be equal to or higher than the standard rate (identical to the standard DeliveryFee for that currency).
|
251
|
+
#
|
252
|
+
#
|
253
|
+
#
|
254
|
+
#Please note that for reasons of security there is no way to set a client's credit card details via the API. It will have to be done in the application.
|
255
|
+
#
|
256
|
+
#*Return*:
|
257
|
+
#
|
258
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
259
|
+
#containing a successful message.
|
260
|
+
#
|
261
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
91
262
|
def update_access_and_billing(params)
|
92
263
|
response = @soap.updateClientAccessAndBilling(
|
93
264
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
94
265
|
:clientID => @clientID,
|
95
266
|
:accessLevel => params[:access_level],
|
96
|
-
:username => params
|
97
|
-
:password => params
|
98
|
-
:billingType => params
|
99
|
-
:currency => params
|
100
|
-
:deliveryFee => params
|
101
|
-
:costPerRecipient => params
|
102
|
-
:designAndSpamTestFee => params
|
267
|
+
:username => params.fetch(:username, ""),
|
268
|
+
:password => params.fetch(:password, ""),
|
269
|
+
:billingType => params.fetch(:billing_type, ""),
|
270
|
+
:currency => params.fetch(:currency, ""),
|
271
|
+
:deliveryFee => params.fetch(:delivery_fee, ""),
|
272
|
+
:costPerRecipient => params.fetch(:cost_per_recipient, ""),
|
273
|
+
:designAndSpamTestFee => params.fetch(:design_and_spam_test_fee, "")
|
103
274
|
)
|
104
275
|
handle_request response.client_UpdateAccessAndBillingResult
|
105
276
|
end
|
106
277
|
|
278
|
+
#Updates the basic details of an existing client.
|
279
|
+
#If you wish to change only some details, the others must be included as they currently are. Please note that the client's existing
|
280
|
+
#access and billing details will remain unchanged by a call to this method.
|
281
|
+
#
|
282
|
+
#Available _params_ argument are:
|
283
|
+
# * :company_name - The client company name.
|
284
|
+
# * :contact_name - The personal name of the principle contact for this client.
|
285
|
+
# * :email_address - An email address to which this client will be sent application-related emails.
|
286
|
+
# * :country - This client's country.
|
287
|
+
# * :time_zone - Client timezone for tracking and reporting data. Valid timezone strings are obtainable by means of the
|
288
|
+
# API procedure Campaigning.time_zones.
|
289
|
+
#
|
290
|
+
#*Return*:
|
291
|
+
#
|
292
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
293
|
+
#containing a successful message.
|
294
|
+
#
|
295
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
107
296
|
def update_basics(params)
|
108
297
|
response = @soap.updateClientBasics(
|
109
298
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -16,6 +16,22 @@ module Campaigning
|
|
16
16
|
@soap = Campaigning::SOAPDriver.instance.get_driver
|
17
17
|
end
|
18
18
|
|
19
|
+
#Creates a brand new subscriber list
|
20
|
+
#
|
21
|
+
#Available _params_ argument are:
|
22
|
+
# * :client_id - The ID of the client who will owner of the list.
|
23
|
+
# * :title - The list title. Must be unique for this client.
|
24
|
+
# * :unsubscribe_page - The URL to which subscribers will be directed when unsubscribing from the list.
|
25
|
+
# If left blank or omitted a generic unsubscribe page is used.
|
26
|
+
# * :comfirm_opt_in - Either true or false depending on whether the list requires email confirmation or not. Please see
|
27
|
+
# the help documentation for more details of what this means.
|
28
|
+
# * :confirmation_success_page - Successful email confirmations will be redirected to this URL. Ignored if ConfirmOptIn
|
29
|
+
# is false. If left blank or omitted a generic confirmation page is used.
|
30
|
+
#*Return*:
|
31
|
+
#
|
32
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::List object representing the newly created list.
|
33
|
+
#
|
34
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
19
35
|
def self.create(params)
|
20
36
|
response = Campaigning::SOAPDriver.instance.get_driver.createList(
|
21
37
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -29,6 +45,20 @@ module Campaigning
|
|
29
45
|
List.new(new_list_id, params[:title])
|
30
46
|
end
|
31
47
|
|
48
|
+
#Creates a new custom field for a list
|
49
|
+
#
|
50
|
+
#Available _params_ argument are:
|
51
|
+
# * :field_name - The Name for the new Custom Field. This will be used to generate the custom fields Key.
|
52
|
+
# * :data_type - The Data Type for the new Custom Field. This must be one of Text, Number, MultiSelectOne, or MultiSelectMany
|
53
|
+
# * :options - The available options for a multi-valued custom field. Options should be an Array of Strings, like: %w[Brazil Ireland England].
|
54
|
+
# You can't pass this field for Text and Number custom fields
|
55
|
+
#
|
56
|
+
#*Return*:
|
57
|
+
#
|
58
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
59
|
+
#containing a successful message.
|
60
|
+
#
|
61
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
32
62
|
def create_custom_field(params)
|
33
63
|
response = @soap.createListCustomField(
|
34
64
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -40,32 +70,155 @@ module Campaigning
|
|
40
70
|
handle_request response.list_CreateCustomFieldResult
|
41
71
|
end
|
42
72
|
|
73
|
+
#Deletes a list
|
74
|
+
#
|
75
|
+
#*Return*:
|
76
|
+
#
|
77
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
78
|
+
#containing a successful message.
|
79
|
+
#
|
80
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
43
81
|
def delete
|
44
82
|
List.delete(@listID)
|
45
83
|
self.listID, self.name = nil, nil
|
46
84
|
end
|
47
85
|
|
86
|
+
#Deletes a list
|
87
|
+
#
|
88
|
+
#*Return*:
|
89
|
+
#
|
90
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
91
|
+
#containing a successful message.
|
92
|
+
#
|
93
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
48
94
|
def self.delete(list_id)
|
49
95
|
response = Campaigning::SOAPDriver.instance.get_driver.deleteList(:apiKey => CAMPAIGN_MONITOR_API_KEY, :listID => list_id)
|
50
96
|
Helpers.handle_request response.list_DeleteResult
|
51
97
|
end
|
52
98
|
|
99
|
+
#Deletes a custom field from a list
|
100
|
+
#
|
101
|
+
#*Return*:
|
102
|
+
#
|
103
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
104
|
+
#containing a successful message.
|
105
|
+
#
|
106
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
53
107
|
def delete_custom_field(key)
|
54
108
|
response = @soap.deleteListCustomField(:apiKey => CAMPAIGN_MONITOR_API_KEY, :listID => @listID, :key => '['+key+']')
|
55
109
|
handle_request response.list_DeleteCustomFieldResult
|
56
110
|
end
|
57
111
|
|
112
|
+
#Gets all the Custom Fields available for a list
|
113
|
+
#
|
114
|
+
#*Return*:
|
115
|
+
#
|
116
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::ListCustomField complex types. The individual ListCustomField
|
117
|
+
#record consists of a +fieldName+, +key+, +dataType+ and a +fieldOptions+ containing a list of possible options for multi-valued custom fields.
|
118
|
+
#
|
119
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
58
120
|
def custom_fields
|
59
121
|
response = @soap.getListCustomFields(:apiKey => CAMPAIGN_MONITOR_API_KEY, :listID => @listID)
|
60
122
|
handle_request response.list_GetCustomFieldsResult
|
61
123
|
end
|
62
124
|
|
125
|
+
#Gets a list's configuration detail
|
126
|
+
#
|
127
|
+
#*Return*:
|
128
|
+
#
|
129
|
+
#*Success*: A successful call to this method will return a Campaigning::ListDetail object, consisting of +listID+, +title+, +unsubscribePage+, +confirmOptIn+, and
|
130
|
+
#+confirmationSuccessPage+ (all as described in Campaigning::List#update and Campaigning::List.create).
|
131
|
+
#
|
132
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
63
133
|
def details
|
64
134
|
response = @soap.getListDetail(:apiKey => CAMPAIGN_MONITOR_API_KEY, :listID => @listID)
|
65
135
|
handle_request response.list_GetDetailResult
|
66
136
|
end
|
137
|
+
|
138
|
+
#Gets a list of all active subscribers for a list.
|
139
|
+
#
|
140
|
+
#*Return*:
|
141
|
+
#
|
142
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::Subscriber objects.
|
143
|
+
#
|
144
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
145
|
+
def get_all_active_subscribers
|
146
|
+
find_active_subscribers(DateTime.new(y=1911,m=1,d=01, h=01,min=00,s=00))
|
147
|
+
end
|
148
|
+
|
149
|
+
#Gets a list of all active subscribers for a list that have been joined since the specified date.
|
150
|
+
#The +joined_at+ param has to be a DateTime object, like:
|
151
|
+
#
|
152
|
+
# list.find_active_subscribers(DateTime.new(y=2009,m=4,d=01, h=01,min=00,s=00))
|
153
|
+
#
|
154
|
+
#*Return*:
|
155
|
+
#
|
156
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::Subscriber objects.
|
157
|
+
#
|
158
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
159
|
+
def find_active_subscribers(joined_at)
|
160
|
+
response = @soap.getSubscribers(
|
161
|
+
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
162
|
+
:listID => @listID,
|
163
|
+
:date =>joined_at.strftime('%Y-%m-%d %H:%M:%S')
|
164
|
+
)
|
165
|
+
handle_request response.subscribers_GetActiveResult
|
166
|
+
end
|
167
|
+
|
168
|
+
#Gets a list of all subscribers for a list that have unsubscribed since the specified date.
|
169
|
+
#The +unjoined_at+ param has to be a DateTime object, like:
|
170
|
+
#
|
171
|
+
# list.find_unsubscribed(DateTime.new(y=2009,m=4,d=01, h=01,min=00,s=00))
|
172
|
+
#
|
173
|
+
#*Return*:
|
174
|
+
#
|
175
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::Subscriber objects. In this case
|
176
|
+
#every returned object will contain the value "Unsubscribed" in the +state+ field.
|
177
|
+
#
|
178
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
179
|
+
def find_unsubscribed(unjoined_at)
|
180
|
+
response = @soap.getUnsubscribed(
|
181
|
+
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
182
|
+
:listID => @listID,
|
183
|
+
:date => unjoined_at.strftime('%Y-%m-%d %H:%M:%S') # TODO: Move that to a helper method
|
184
|
+
)
|
185
|
+
handle_request response.subscribers_GetUnsubscribedResult
|
186
|
+
end
|
67
187
|
|
68
|
-
|
188
|
+
#This method returns all of a particular subscribers details, including email address, name, active/inactive
|
189
|
+
#status and all custom field data. If a subscriber with that email address does not exist in that list, a +nil+ value is returned.
|
190
|
+
#
|
191
|
+
#*Return*:
|
192
|
+
#*Success*: Upon a successful call, this method will return a collection of Campaigning::Subscriber objects. In this case
|
193
|
+
#every returned object will contain the value "Unsubscribed" in the +state+ field.
|
194
|
+
#
|
195
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
196
|
+
def find_single_subscriber(email_address) # TODO: Create a mehod to handle with custom fields returned like (names from "State Name" to "state_name")
|
197
|
+
response = @soap.getSingleSubscriber(
|
198
|
+
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
199
|
+
:listID => @listID,
|
200
|
+
:emailAddress => email_address
|
201
|
+
)
|
202
|
+
handle_request response.subscribers_GetSingleSubscriberResult
|
203
|
+
end
|
204
|
+
|
205
|
+
#Update a subscriber list’s details
|
206
|
+
#
|
207
|
+
#Available _params_ argument are:
|
208
|
+
# * :title - The list title, as it will be shown in the application and through the API.
|
209
|
+
# * :unsubscribe_page - The URL to which subscribers will be directed when unsubscribing from the list.
|
210
|
+
# If left blank or omitted a generic unsubscribe page is used.
|
211
|
+
# * :comfirm_opt_in - Either true or false depending on whether the list requires email confirmation or not. Please see
|
212
|
+
# the help documentation for more details of what this means.
|
213
|
+
# * :confirmation_success_page - Successful email confirmations will be redirected to this URL. Ignored if ConfirmOptIn
|
214
|
+
# is false. If left blank or omitted a generic confirmation page is used.
|
215
|
+
#
|
216
|
+
#*Return*:
|
217
|
+
#
|
218
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
219
|
+
#containing a successful message.
|
220
|
+
#
|
221
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
69
222
|
def update(params)
|
70
223
|
response = @soap.updateList(
|
71
224
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -21,6 +21,21 @@ class Subscriber
|
|
21
21
|
@soap = Campaigning::SOAPDriver.instance.get_driver
|
22
22
|
end
|
23
23
|
|
24
|
+
#Adds a subscriber (email address, name) to an existing subscriber list. If the subscriber (email address) already exists,
|
25
|
+
#the name value is updated with whatever is passed in.
|
26
|
+
#
|
27
|
+
#If the list has been set as double opt-in, they will be sent the verification email, otherwise they will be sent the
|
28
|
+
#confirmation email you have set up for the list being subscribed to.
|
29
|
+
#
|
30
|
+
#<b>Please note</b>: If the subscriber is in an inactive state or has previously been unsubscribed, they will *not* be re-added
|
31
|
+
#to the active list. Therefore, this method should be used with caution and only where suitable.
|
32
|
+
#
|
33
|
+
#*Return*:
|
34
|
+
#
|
35
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
36
|
+
#containing a successful message.
|
37
|
+
#
|
38
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
24
39
|
def add(list_id)
|
25
40
|
response = @soap.addSubscriber(
|
26
41
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -31,6 +46,21 @@ class Subscriber
|
|
31
46
|
handle_request response.subscriber_AddResult
|
32
47
|
end
|
33
48
|
|
49
|
+
#Adds a subscriber (email address, name) to an existing subscriber list. If the subscriber (email address) already exists,
|
50
|
+
#the name value is updated with whatever is passed in.
|
51
|
+
#
|
52
|
+
#If the list has been set as double opt-in, they will be sent the verification email, otherwise they will be sent the
|
53
|
+
#confirmation email you have set up for the list being subscribed to.
|
54
|
+
#
|
55
|
+
#<b>Please note</b>: If the subscriber is in an inactive state or has previously been unsubscribed, they will be re-added to
|
56
|
+
#the active list. Therefore, this method should be used with caution and only where suitable.
|
57
|
+
#
|
58
|
+
#*Return*:
|
59
|
+
#
|
60
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
61
|
+
#containing a successful message.
|
62
|
+
#
|
63
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
34
64
|
def add_and_resubscribe(list_id)
|
35
65
|
response = @soap.addAndResubscribe(
|
36
66
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -41,6 +71,22 @@ class Subscriber
|
|
41
71
|
handle_request response.subscriber_AddAndResubscribeResult
|
42
72
|
end
|
43
73
|
|
74
|
+
|
75
|
+
#Adds a subscriber to a subscriber list, including adding custom field data for the subscriber. If the subscriber (email address)
|
76
|
+
#already exists, then the custom fields are updated with whatever is passed in.
|
77
|
+
#
|
78
|
+
#If the list has been set as double opt-in, they will be sent the verification email, otherwise they will be sent the confirmation
|
79
|
+
#email you have set up for the list being subscribed to.
|
80
|
+
#
|
81
|
+
#<b>Please note</b>: If the subscriber is in an inactive state or has previously been unsubscribed, they will be re-added to the
|
82
|
+
#active list. Therefore, this method should be used with caution and only where suitable.
|
83
|
+
#
|
84
|
+
#*Return*:
|
85
|
+
#
|
86
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
87
|
+
#containing a successful message.
|
88
|
+
#
|
89
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
44
90
|
def add_and_resubscribe_with_custom_fields(list_id, custom_fields)
|
45
91
|
response = @soap.addAndResubscribeWithCustomFields(
|
46
92
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -52,6 +98,21 @@ class Subscriber
|
|
52
98
|
handle_request response.subscriber_AddAndResubscribeWithCustomFieldsResult
|
53
99
|
end
|
54
100
|
|
101
|
+
#Adds a subscriber to a subscriber list, including adding custom field data for the subscriber. If the subscriber (email address)
|
102
|
+
#already exists, then the custom fields are updated with whatever is passed in.
|
103
|
+
#
|
104
|
+
#If the list has been set as double opt-in, they will be sent the verification email, otherwise they will be sent the confirmation
|
105
|
+
#email you have set up for the list being subscribed to.
|
106
|
+
#
|
107
|
+
#<b>Please note</b>: If the subscriber is in an inactive state or has previously been unsubscribed, they will *not* be re-added to
|
108
|
+
#the active list. Therefore, this method should be used with caution and only where suitable.
|
109
|
+
#
|
110
|
+
#*Return*:
|
111
|
+
#
|
112
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
113
|
+
#containing a successful message.
|
114
|
+
#
|
115
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
55
116
|
def add_with_custom_fields(list_id, custom_fields)
|
56
117
|
response = @soap.addSubscriberWithCustomFields(
|
57
118
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -63,10 +124,24 @@ class Subscriber
|
|
63
124
|
handle_request response.subscriber_AddWithCustomFieldsResult
|
64
125
|
end
|
65
126
|
|
127
|
+
#Changes the status of an Active Subscriber to an Unsubscribed Subscriber who will no longer receive
|
128
|
+
#campaigns sent to that Subscriber List.
|
129
|
+
#
|
130
|
+
#If the list is set to add unsubscribing subscribers to the suppression list, then the subscriber’s email address will
|
131
|
+
#also be added to the suppression list.
|
132
|
+
#
|
133
|
+
#*Return*:
|
134
|
+
#
|
135
|
+
#*Success*: Upon a successful call, this method will return a Campaigning::Result object wich consists of a +code+ and +message+ fields
|
136
|
+
#containing a successful message.
|
137
|
+
#
|
138
|
+
#*Error*: An Exception containing the cause of the error will be raised.
|
66
139
|
def unsubscribe(list_id)
|
67
140
|
Subscriber.unsubscribe(@emailAddress, list_id)
|
68
141
|
end
|
69
142
|
|
143
|
+
#Changes the status of an Active Subscriber to an Unsubscribed Subscriber who will no longer receive
|
144
|
+
#campaigns sent to that Subscriber List (Same that the instance method with the same name).
|
70
145
|
def self.unsubscribe(email, list_id)
|
71
146
|
response = Campaigning::SOAPDriver.instance.get_driver.unsubscribe(
|
72
147
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -76,30 +151,12 @@ class Subscriber
|
|
76
151
|
Helpers.handle_request response.subscriber_UnsubscribeResult
|
77
152
|
end
|
78
153
|
|
79
|
-
#
|
80
|
-
def self.active_subscribers(list_id, datetime)
|
81
|
-
response = Campaigning::SOAPDriver.instance.get_driver.getSubscribers(
|
82
|
-
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
83
|
-
:listID => list_id,
|
84
|
-
:date => datetime.strftime('%Y-%m-%d %H:%M:%S') # TODO: Move that to a helper method
|
85
|
-
)
|
86
|
-
Helpers.handle_request response.subscribers_GetActiveResult
|
87
|
-
end
|
88
|
-
|
89
|
-
# TODO: May I move this method to List type?
|
90
|
-
def self.get_unsubscribed(list_id, datetime)
|
91
|
-
response = Campaigning::SOAPDriver.instance.get_driver.getUnsubscribed(
|
92
|
-
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
93
|
-
:listID => list_id,
|
94
|
-
:date => datetime.strftime('%Y-%m-%d %H:%M:%S') # TODO: Move that to a helper method
|
95
|
-
)
|
96
|
-
Helpers.handle_request response.subscribers_GetUnsubscribedResult
|
97
|
-
end
|
98
|
-
|
154
|
+
#Returns True or False as to the existence of the given email address in the list supplied.
|
99
155
|
def is_subscribed?(list_id)
|
100
156
|
Subscriber.is_subscribed?(@emailAddress, list_id)
|
101
157
|
end
|
102
158
|
|
159
|
+
#Returns True or False as to the existence of the given email address in the list supplied.
|
103
160
|
def self.is_subscribed?(email, list_id)
|
104
161
|
response = Campaigning::SOAPDriver.instance.get_driver.getIsSubscribed(
|
105
162
|
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
@@ -109,16 +166,7 @@ class Subscriber
|
|
109
166
|
response = Helpers.handle_request response.subscribers_GetIsSubscribedResult
|
110
167
|
response == 'True' ? true : false
|
111
168
|
end
|
112
|
-
|
113
|
-
# TODO: Create a mehod to handle with custom fields returned like (names from "State Name" to "state_name")
|
114
|
-
def self.get_single_subscriber(list_id, email_address)
|
115
|
-
response = Campaigning::SOAPDriver.instance.get_driver.getSingleSubscriber(
|
116
|
-
:apiKey => CAMPAIGN_MONITOR_API_KEY,
|
117
|
-
:listID => list_id,
|
118
|
-
:emailAddress => email_address
|
119
|
-
)
|
120
|
-
Helpers.handle_request response.subscribers_GetSingleSubscriberResult
|
121
|
-
end
|
169
|
+
|
122
170
|
|
123
171
|
|
124
172
|
protected
|
data/test/campaigning_test.rb
CHANGED
@@ -1,18 +1,31 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
# Replace this API key with your own (http://www.campaignmonitor.com/api/)
|
4
|
-
CAMPAIGN_MONITOR_API_KEY = '
|
4
|
+
CAMPAIGN_MONITOR_API_KEY = '54cae7f3aa1f35cb3bb5bc41756d8b7f'
|
5
5
|
CLIENT_ID = 'd7acfd4cd2ffffc2d86b8903d18a1276'
|
6
6
|
CLIENT_TWO_ID = '730acd1e8d27d56bdb87e88685613d72'
|
7
7
|
|
8
8
|
class CampaigningTest < Test::Unit::TestCase
|
9
9
|
|
10
|
-
def setup
|
11
|
-
@cm = Campaigning::Base.new
|
12
|
-
end
|
13
10
|
|
14
|
-
|
15
|
-
|
11
|
+
# def test_campaigning_system_date
|
12
|
+
# date = Campaigning.system_date
|
13
|
+
# assert !date.nil?
|
14
|
+
# puts date
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# def test_user_get_time_zones
|
18
|
+
# time_zones = Campaigning.time_zones
|
19
|
+
# assert !time_zones.nil?
|
20
|
+
# end
|
21
|
+
|
22
|
+
# def test_user_countries
|
23
|
+
# countries = Campaigning.countries
|
24
|
+
# assert !countries.nil?
|
25
|
+
# end
|
26
|
+
|
27
|
+
# def test_client_get_all_clients
|
28
|
+
# clients = Campaigning::Client.get_all_clients
|
16
29
|
# assert clients.length > 0
|
17
30
|
# clients.each{ |c| puts c.clientID + " - " + c.name }
|
18
31
|
# end
|
@@ -22,8 +35,8 @@ class CampaigningTest < Test::Unit::TestCase
|
|
22
35
|
# client = Campaigning::Client.new(CLIENT_ID)
|
23
36
|
# assert client.lists.length > 0
|
24
37
|
# end
|
25
|
-
|
26
|
-
|
38
|
+
|
39
|
+
|
27
40
|
# def test_client_create
|
28
41
|
# client_created = Campaigning::Client.create(
|
29
42
|
# :company_name => "Orange Company 15",
|
@@ -45,36 +58,57 @@ class CampaigningTest < Test::Unit::TestCase
|
|
45
58
|
# client = Campaigning::Client.find_by_name("Orange Company 7")
|
46
59
|
# client.delete
|
47
60
|
# end
|
48
|
-
|
61
|
+
|
49
62
|
# def test_client_segments
|
50
63
|
# client = Campaigning::Client.find_by_name("Client One Company")
|
51
64
|
# assert client.segments.length > 0
|
52
65
|
# puts client.segments.inspect
|
53
66
|
# end
|
54
|
-
|
55
|
-
|
56
|
-
def test_find_client_by_name
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
|
67
|
+
|
68
|
+
|
69
|
+
# def test_find_client_by_name
|
70
|
+
# client = Campaigning::Client.find_by_name("Client One Company")
|
71
|
+
# puts client.inspect
|
72
|
+
# # assert client != nil && client.name == "Client One Company"
|
73
|
+
# end
|
74
|
+
|
75
|
+
|
63
76
|
# def test_get_client_campaigns
|
64
77
|
# client = Campaigning::Client.find_by_name("Client One Company")
|
65
78
|
# puts client.campaigns.inspect
|
66
79
|
# end
|
67
80
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
81
|
+
def test_get_client_details
|
82
|
+
client = Campaigning::Client.find_by_name("Client One Company")
|
83
|
+
# client_details = client.details
|
84
|
+
# basic_details = client_details.basicDetails
|
85
|
+
# access_and_billing_details = client_details.accessAndBilling
|
86
|
+
# puts "Basic details:"
|
87
|
+
# puts "Client ID: #{basic_details.clientID} - \n
|
88
|
+
# Company: #{basic_details.companyName} - \n
|
89
|
+
# Contact: #{basic_details.contactName} - \n
|
90
|
+
# Country: #{basic_details.country} - \n
|
91
|
+
# Timezone: #{basic_details.timezone}"
|
92
|
+
#
|
93
|
+
# puts "Access and Billing Details:"
|
94
|
+
# puts "Username: #{access_and_billing_details.username} - \n
|
95
|
+
# Password: #{access_and_billing_details.password} - \n
|
96
|
+
# Billing Type: #{access_and_billing_details.billingType} - \n
|
97
|
+
# Currency: #{access_and_billing_details.currency} - \n
|
98
|
+
# Delivery Fee: #{access_and_billing_details.deliveryFee} - \n
|
99
|
+
# Cost per Recipient: #{access_and_billing_details.costPerRecipient} - \n
|
100
|
+
# Design and Span test Fee: #{access_and_billing_details.designAndSpamTestFee} - \n
|
101
|
+
# Access Level: #{access_and_billing_details.accessLevel}"
|
102
|
+
|
103
|
+
puts client.details.inspect != nil
|
104
|
+
|
105
|
+
end
|
106
|
+
|
73
107
|
# def test_get_client_suppression_list
|
74
|
-
# client = Campaigning::Client.find_by_name("Client
|
75
|
-
# puts client.suppression_list
|
108
|
+
# client = Campaigning::Client.find_by_name("Client One Company")
|
109
|
+
# puts client.suppression_list.inspect
|
76
110
|
# end
|
77
|
-
|
111
|
+
|
78
112
|
# def test_client_update_access_and_billing
|
79
113
|
# client = Campaigning::Client.find_by_name("Client One Company")
|
80
114
|
# response = client.update_access_and_billing(
|
@@ -110,20 +144,6 @@ class CampaigningTest < Test::Unit::TestCase
|
|
110
144
|
# end
|
111
145
|
|
112
146
|
|
113
|
-
#
|
114
|
-
# def test_user_get_time_zones
|
115
|
-
# time_zones = @cm.time_zones
|
116
|
-
# assert !time_zones.nil?
|
117
|
-
# end
|
118
|
-
#
|
119
|
-
#
|
120
|
-
# def test_system_date
|
121
|
-
# sys_date = @cm.system_date
|
122
|
-
# assert !sys_date.nil?
|
123
|
-
# puts sys_date
|
124
|
-
# end
|
125
|
-
#
|
126
|
-
#
|
127
147
|
# def test_campaign_create
|
128
148
|
# client = Campaigning::Client.find_by_name("Client One Company")
|
129
149
|
# response = Campaigning::Campaign.create(
|
@@ -149,7 +169,7 @@ class CampaigningTest < Test::Unit::TestCase
|
|
149
169
|
#
|
150
170
|
# def test_campaign_lists
|
151
171
|
# client = Campaigning::Client.find_by_name("Client One Company")
|
152
|
-
#
|
172
|
+
# client.campaigns[0].lists
|
153
173
|
# end
|
154
174
|
#
|
155
175
|
# def test_campaign_opens
|
@@ -164,9 +184,15 @@ class CampaigningTest < Test::Unit::TestCase
|
|
164
184
|
# end
|
165
185
|
#
|
166
186
|
#
|
167
|
-
# def
|
187
|
+
# def test_campaign_summary
|
168
188
|
# client = Campaigning::Client.find_by_name("Client One Company")
|
169
|
-
#
|
189
|
+
# # client.campaigns[2].subscriber_clicks.each do |subscriber|
|
190
|
+
# # puts "Subscriber: #{subscriber.emailAddress}"
|
191
|
+
# # subscriber.clickedLinks.each { |clicked| puts "Link: #{clicked.link} - Number of clicks: #{clicked.clicks}"}
|
192
|
+
# # end
|
193
|
+
# assert client.campaigns[2].subscriber_clicks != nil
|
194
|
+
# assert client.campaigns[2].subscriber_clicks != []
|
195
|
+
#
|
170
196
|
# end
|
171
197
|
#
|
172
198
|
#
|
@@ -233,11 +259,6 @@ class CampaigningTest < Test::Unit::TestCase
|
|
233
259
|
# assert response.code == 0
|
234
260
|
# end
|
235
261
|
#
|
236
|
-
# def test_subscriber_actives
|
237
|
-
# subscriber_list = Campaigning::Subscriber.active_subscribers("ac52b645c048888a44c87b5f1ecf6b7d", DateTime.new(y=2009,m=5,d=01, h=01,min=00,s=00))
|
238
|
-
# puts subscriber_list.inspect
|
239
|
-
# assert subscriber_list.length > 0
|
240
|
-
# end
|
241
262
|
#
|
242
263
|
# def test_subscriber_is_subscribed
|
243
264
|
# subscriber = Campaigning::Subscriber.new("user_to_test@test.com") # TODO: Change to get the Subscriber, not to CREATE a new one
|
@@ -246,19 +267,40 @@ class CampaigningTest < Test::Unit::TestCase
|
|
246
267
|
# assert response == false
|
247
268
|
# end
|
248
269
|
#
|
249
|
-
#
|
250
|
-
#
|
270
|
+
#
|
271
|
+
# def test_list_find_single_subscriber
|
272
|
+
# client = Campaigning::Client.find_by_name("Client One Company")
|
273
|
+
# list = client.find_list_by_name "My Friends"
|
274
|
+
# subscriber = list.find_single_subscriber("user_custon2@test.com")
|
251
275
|
# puts subscriber.inspect
|
252
276
|
# assert subscriber.name != nil
|
253
|
-
# end
|
277
|
+
# end
|
254
278
|
#
|
255
|
-
# def
|
256
|
-
#
|
279
|
+
# def test_list_find_unsubscribed
|
280
|
+
# client = Campaigning::Client.find_by_name("Client One Company")
|
281
|
+
# list = client.find_list_by_name "My Friends"
|
282
|
+
# subscriber_list = list.find_unsubscribed(DateTime.new(y=2009,m=4,d=01, h=01,min=00,s=00))
|
257
283
|
# puts subscriber_list.inspect
|
258
284
|
# assert subscriber_list.length > 0
|
259
285
|
# end
|
260
286
|
#
|
261
|
-
#
|
287
|
+
# def test_list_find_active_subscribers
|
288
|
+
# client = Campaigning::Client.find_by_name("Client One Company")
|
289
|
+
# list = client.find_list_by_name "My Friends"
|
290
|
+
# subscriber_list = list.find_active_subscribers(DateTime.new(y=2009,m=5,d=01, h=01,min=00,s=00))
|
291
|
+
# assert subscriber_list.length > 0
|
292
|
+
# end
|
293
|
+
|
294
|
+
# def test_list_get_all_active_subscribers
|
295
|
+
# client = Campaigning::Client.find_by_name("Client One Company")
|
296
|
+
# list = client.find_list_by_name "My Friends"
|
297
|
+
# subscriber_list = list.get_all_active_subscribers
|
298
|
+
# puts subscriber_list.inspect
|
299
|
+
# assert subscriber_list.length > 0
|
300
|
+
# end
|
301
|
+
|
302
|
+
|
303
|
+
|
262
304
|
# def test_list_create
|
263
305
|
# client = Campaigning::Client.find_by_name("Client One Company")
|
264
306
|
# list = Campaigning::List.create(
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnumarcelo-campaigning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Menezes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|