gnumarcelo-campaigning 0.10.0 → 0.11.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.
@@ -1,312 +0,0 @@
1
- # Client is defined in default.rb which is automatically generated.
2
- # In this file we add additional methods to the Client class.
3
- require File.expand_path(File.dirname(__FILE__)) + '/../helpers/helpers'
4
-
5
- module Campaigning
6
-
7
- class Client
8
- include Helpers
9
- attr_accessor :clientID
10
- attr_accessor :name
11
-
12
- def initialize(clientID = nil, name = nil)
13
- @clientID = clientID
14
- @name = name
15
- @soap = Campaigning::SOAPDriver.instance.get_driver
16
- end
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.
25
- def lists
26
- response = @soap.getClientLists(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID)
27
- lists = handle_response response.client_GetListsResult
28
- lists.collect {|list| List.new(list.listID, list.name)}
29
- end
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.
42
- def find_list_by_name(list_name)
43
- lists.find {|list| list_name == list.name}
44
- end
45
-
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?
57
- def self.find_by_name(name)
58
- client_list = Client.get_all_clients
59
- client_found = client_list.find {|client| name == client.name}
60
- Client.new(client_found.clientID, client_found.name) if client_found
61
- end
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 = handle_response 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
- # * :companyName - The client company name.
82
- # * :contactName - The personal name of the principle contact for this client.
83
- # * :emailAddress - 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
- # * :timezone - Client timezone for tracking and reporting data. A valid timezone list is available here or by using the API
87
- # procedure Campaigning.timezones.
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.
93
- def self.create(params)
94
- response = Campaigning::SOAPDriver.instance.get_driver.createClient(
95
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
96
- :companyName => params[:companyName],
97
- :contactName => params[:contactName],
98
- :emailAddress => params[:emailAddress],
99
- :country => params[:country],
100
- :timezone => params[:timezone]
101
- )
102
- Client.new( handle_response(response.client_CreateResult), params[:companyName] )
103
- end
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.
113
- def delete
114
- response = Client.delete(@clientID)
115
- self.clientID, self.name = nil
116
- response
117
- end
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.
127
- def self.delete(client_id)
128
- response = Campaigning::SOAPDriver.instance.get_driver.deleteClient(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => client_id)
129
- handle_response response.client_DeleteResult
130
- end
131
-
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.
141
- response = @soap.getClientSegments(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID )
142
- handle_response response.client_GetSegmentsResult
143
- end
144
-
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
158
- arr = []
159
- #return campaigns.find {|campaign| subject == campaign.subject} if params[:single]
160
- campaigns.each { |campaign| arr << campaign if campaign.subject == subject }
161
- arr
162
- end
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.
171
- def campaigns
172
- response = @soap.getClientCampaigns(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID )
173
- campaign_list = handle_response response.client_GetCampaignsResult
174
- campaign_list.collect do |campaign|
175
- Campaign.new(campaign.campaignID, campaign.subject, campaign.sentDate, campaign.totalRecipients)
176
- end
177
- end
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.
208
- def details
209
- response = @soap.getClientDetail(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID )
210
- handle_response response.client_GetDetailResult
211
- end
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.
220
- def suppression_list
221
- response = @soap.getClientSuppressionList(:apiKey => CAMPAIGN_MONITOR_API_KEY, :clientID => @clientID )
222
- handle_response response.client_GetSuppressionListResult
223
- end
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
- # * :accessLevel - 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
- # * :billingType - Client billing type, only required if :accessLevel is set to allow the client to create and send campaigns
238
- # * :currency - Billing currency for this client, only required if :billingType is set to either ClientPaysAtStandardRate or
239
- # ClientPaysWithMarkup. See full details: http://www.campaignmonitor.com/api/method/client-updateaccessandbilling/#currencies.
240
- # * :deliveryFee - 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
- # * :costPerRecipient - 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
- # * :designAndSpamTestFee - 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.
262
- def update_access_and_billing(params)
263
- response = @soap.updateClientAccessAndBilling(
264
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
265
- :clientID => @clientID,
266
- :accessLevel => params[:accessLevel],
267
- :username => params.fetch(:username, ""),
268
- :password => params.fetch(:password, ""),
269
- :billingType => params.fetch(:billingType, ""),
270
- :currency => params.fetch(:currency, ""),
271
- :deliveryFee => params.fetch(:deliveryFee, ""),
272
- :costPerRecipient => params.fetch(:costPerRecipient, ""),
273
- :designAndSpamTestFee => params.fetch(:designAndSpamTestFee, "")
274
- )
275
- handle_response response.client_UpdateAccessAndBillingResult
276
- end
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
- # * :companyName - The client company name.
284
- # * :contactName - The personal name of the principle contact for this client.
285
- # * :emailAddress - An email address to which this client will be sent application-related emails.
286
- # * :country - This client's country.
287
- # * :timezone - Client timezone for tracking and reporting data. Valid timezone strings are obtainable by means of the
288
- # API procedure Campaigning.timezones.
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.
296
- def update_basics(params)
297
- response = @soap.updateClientBasics(
298
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
299
- :clientID => @clientID,
300
- :companyName => params[:companyName],
301
- :contactName => params[:contactName],
302
- :emailAddress => params[:emailAddress],
303
- :country => params[:country],
304
- :timezone => params[:timezone]
305
- )
306
- handle_response response.client_UpdateBasicsResult
307
- end
308
-
309
-
310
- end
311
-
312
- end
@@ -1,185 +0,0 @@
1
- # Subscriber is defined in default.rb which is automatically generated.
2
- # In this file we add additional methods to the Subscriber class.
3
- require File.expand_path(File.dirname(__FILE__)) + '/../helpers/helpers'
4
-
5
- module Campaigning
6
-
7
- class Subscriber
8
- include Helpers
9
- attr_accessor :emailAddress
10
- attr_accessor :name
11
- attr_accessor :date
12
- attr_accessor :state
13
- attr_accessor :customFields
14
-
15
- def initialize(emailAddress = nil, name = nil, date = nil, state = nil, customFields = nil)
16
- @emailAddress = emailAddress
17
- @name = name
18
- @date = date
19
- @state = state
20
- @customFields = customFields
21
- @soap = Campaigning::SOAPDriver.instance.get_driver
22
- end
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.
39
- def add(list_id)
40
- response = @soap.addSubscriber(
41
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
42
- :listID => list_id,
43
- :email => @emailAddress,
44
- :name => @name
45
- )
46
- handle_response response.subscriber_AddResult
47
- end
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.
64
- def add_and_resubscribe(list_id)
65
- response = @soap.addAndResubscribe(
66
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
67
- :listID => list_id,
68
- :email => @emailAddress,
69
- :name => @name
70
- )
71
- handle_response response.subscriber_AddAndResubscribeResult
72
- end
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.
90
- def add_and_resubscribe_with_custom_fields(list_id, custom_fields)
91
- response = @soap.addAndResubscribeWithCustomFields(
92
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
93
- :listID => list_id,
94
- :email => @emailAddress,
95
- :name => @name,
96
- :customFields => custom_fields_array(custom_fields)
97
- )
98
- handle_response response.subscriber_AddAndResubscribeWithCustomFieldsResult
99
- end
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.
116
- def add_with_custom_fields(list_id, custom_fields)
117
- response = @soap.addSubscriberWithCustomFields(
118
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
119
- :listID => list_id,
120
- :email => @emailAddress,
121
- :name => @name,
122
- :customFields => custom_fields_array(custom_fields)
123
- )
124
- handle_response response.subscriber_AddWithCustomFieldsResult
125
- end
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.
139
- def unsubscribe(list_id)
140
- Subscriber.unsubscribe(@emailAddress, list_id)
141
- end
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).
145
- def self.unsubscribe(email, list_id)
146
- response = Campaigning::SOAPDriver.instance.get_driver.unsubscribe(
147
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
148
- :listID => list_id,
149
- :email => email
150
- )
151
- handle_response response.subscriber_UnsubscribeResult
152
- end
153
-
154
- #Returns True or False as to the existence of the given email address in the list supplied.
155
- def is_subscribed?(list_id)
156
- Subscriber.is_subscribed?(@emailAddress, list_id)
157
- end
158
-
159
- #Returns True or False as to the existence of the given email address in the list supplied.
160
- def self.is_subscribed?(email, list_id)
161
- response = Campaigning::SOAPDriver.instance.get_driver.getIsSubscribed(
162
- :apiKey => CAMPAIGN_MONITOR_API_KEY,
163
- :listID => list_id,
164
- :email => email
165
- )
166
- response = handle_response response.subscribers_GetIsSubscribedResult
167
- response == 'True' ? true : false
168
- end
169
-
170
-
171
-
172
- protected
173
-
174
- def custom_fields_array(custom_fields) #:nodoc:
175
- arr = []
176
- custom_fields.each do |key, value|
177
- arr << { :key => key, :value => value }
178
- end
179
- arr
180
- end
181
-
182
-
183
- end
184
-
185
- end