Class: Campaigning::Campaign

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/campaigning/soap/generated/default.rb,
lib/campaigning/types/campaign.rb

Overview

/Campaign

campaignID - SOAP::SOAPString
subject - SOAP::SOAPString
sentDate - SOAP::SOAPString
totalRecipients - SOAP::SOAPInt

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#handle_request, handle_request

Constructor Details

#initialize(campaignID = nil, subject = nil, sentDate = nil, totalRecipients = nil) ⇒ Campaign



15
16
17
18
19
20
21
# File 'lib/campaigning/types/campaign.rb', line 15

def initialize(campaignID = nil, subject = nil, sentDate = nil, totalRecipients = nil)
  @campaignID = campaignID
  @subject = subject
  @sentDate = sentDate
  @totalRecipients = totalRecipients
  @soap = Campaigning::SOAPDriver.instance.get_driver
end

Instance Attribute Details

#campaignIDObject

Returns the value of attribute campaignID.



10
11
12
# File 'lib/campaigning/types/campaign.rb', line 10

def campaignID
  @campaignID
end

#sentDateObject

Returns the value of attribute sentDate.



12
13
14
# File 'lib/campaigning/types/campaign.rb', line 12

def sentDate
  @sentDate
end

#subjectObject

Returns the value of attribute subject.



11
12
13
# File 'lib/campaigning/types/campaign.rb', line 11

def subject
  @subject
end

#totalRecipientsObject

Returns the value of attribute totalRecipients.



13
14
15
# File 'lib/campaigning/types/campaign.rb', line 13

def totalRecipients
  @totalRecipients
end

Class Method Details

.create(params) ⇒ Object

Creates a campaign for an existing client. This campaign will be imported and ready to send to the subscribers in the specified lists and segments. The campaign must have both HTML and plain text content, imported from the internet. Styling for the HTML content will be automatically brought inline.

Available params argument are:

* :clientID - The ID of the Client you want to create a campaign
* :campaignName - The name of the new campaign. This must be unique across all draft campaigns for the client.
* :campaignSubject - The subject of the new campaign.
* :fromName - The name to appear in the From field in the recipients email client when they receive the new campaign.
* :fromEmail - The email address that the new campaign will come from.
* :replyTo - The email address that any replies to the new campaign will be sent to.
* :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
             the campaign will be automatically brought inline. If your URL has querystring values, you will need to encode them.
* :textUrl - The URL of the Text content for the new campaign. If no unsubscribe link is found then one will be added automatically.
* :subscriberListIDs - An array of lists to send the campaign to. See http://www.campaignmonitor.com/api/required/#listid for more details.
* :listSegments - An array of Segment Names and their appropriate List ID s to send the campaign to.

Return:

Success: Upon a successful call, this method will return a Campaigning::Campaign object which was recently created.

Error: An Exception containing the cause of the error will be raised.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/campaigning/types/campaign.rb', line 46

def self.create(params)  
    response = Campaigning::SOAPDriver.instance.get_driver.createCampaign(
       :apiKey => CAMPAIGN_MONITOR_API_KEY,
       :clientID => params[:clientID],
       :campaignName => params[:campaignName],
       :campaignSubject => params[:campaignSubject],
       :fromName => params[:fromName],
       :fromEmail => params[:fromEmail],
       :replyTo => params[:replyTo],
       :htmlUrl => params[:htmlUrl],
       :textUrl => params[:textUrl],
       :subscriberListIDs => params[:subscriberListIDs],
       :listSegments => params[:listSegments]
      )

    campaign_id = Helpers.handle_request response.campaign_CreateResult
    Campaign.new campaign_id
end

Instance Method Details

#bouncesObject

Gets a list of all subscribers who bounced for a given campaign, and the type of bounce (H=Hard Bounce, S=Soft Bounce).

Return:

Success: Upon a successful call, this method will return a collection of SubscriberBounce objects, each of which consists of the subscribers :emailAddress, the listID they belong to, and the bounceType of bounce they experienced, whether hard or soft.

Error: An Exception containing the cause of the error will be raised.



74
75
76
77
# File 'lib/campaigning/types/campaign.rb', line 74

def bounces
  response = @soap.getCampaignBounces(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
  handle_request response.campaign_GetBouncesResult
end

#listsObject

Returns an array of Campaigning::List objects that a given campaign was sent to.

Return:

Success: Upon a successful call, this method will return a collection of Campaigning::List object.

Error: An Exception containing the cause of the error will be raised.



86
87
88
89
90
91
92
93
# File 'lib/campaigning/types/campaign.rb', line 86

def lists
  response = @soap.getCampaignLists(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
  lists = handle_request response.campaign_GetListsResult
  puts "LISTAS!!!!!!!!!!" + lists.inspect
  lists.collect do |list|  
    List.new(list.listID, list.name)
  end
end

#opensObject

Gets a list of all subscribers who opened a given campaign, and the number of times they opened the campaign.

Return:

Success: Upon a successful call, this method will return a collection of SubscriberOpen objects, each of which consists of the subscribers :emailAddress, the listID they belong to, and the numberOfOpens representing the number of times they opened the given campaign.

Error: An Exception containing the cause of the error will be raised.



104
105
106
107
# File 'lib/campaigning/types/campaign.rb', line 104

def opens
  response = @soap.getCampaignOpens(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
  handle_request response.campaign_GetOpensResult
end

#send(params) ⇒ Object

Schedules an existing campaign for sending.

The campaign must be imported with defined recipients. For campaigns with more than 5 recipients the user must have sufficient credits or their credit card details saved within the application for the campaign to be sent via the API. For campaigns with 5 recipients or less the user must have enough test campaigns remaining in their API account. For further information about credits for campaigns please check at: www.campaignmonitor.com/api/method/campaign-send/

Available params argument are:

* :confirmation_email - The email address that the confirmation email that the campaign has been sent will go to.
* :send_date - The date the campaign should be scheduled to be sent. To send a campaign immediately pass in "Immediately".
               This date should be in the users timezone and formatted as YYYY-MM-DD HH:MM:SS.

Return: Upon a successful call, this method will return a Result object with the newly create Campaign’s ID as the Code.

Error: An Exception containing the cause of the error will be raised.



177
178
179
180
181
182
183
184
185
# File 'lib/campaigning/types/campaign.rb', line 177

def send(params)
  response = @soap.sendCampaign(
    :apiKey => CAMPAIGN_MONITOR_API_KEY,
    :campaignID => @campaignID,
    :confirmationEmail => params[:confirmation_email],
    :sendDate => params[:send_date]
     )
  handle_request response.campaign_SendResult
end

#subscriber_clicksObject

Gets a list of all subscribers who clicked a link for a given campaign, the ID of the list they belong to, the links they clicked, and the number of times they clicked the link.

Example of usage:

campaign_obj.subscriber_clicks.each do |subscriber|

puts "Subscriber: #{subscriber.emailAddress}"
subscriber.clickedLinks.each do |clicked| 
  puts "Clicked link: #{clicked.link} - Number of clicks: #{clicked.clicks}"
end

end

Return:

Success: Upon a successful call, this method will return a collection of SubscriberClick objects, each of which consists of the subscribers emailAddress, the listID representing list they belong to, and the clickedLinksarray representing the links they have clicked and the number of times they clicked each link.

Error: An Exception containing the cause of the error will be raised.



129
130
131
132
# File 'lib/campaigning/types/campaign.rb', line 129

def subscriber_clicks
  response = @soap.getSubscriberClicks(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
  handle_request response.campaign_GetSubscriberClicksResult
end

#summaryObject

Gets a statistical summary, including number of recipients and open count, for a given campaign.

Return:

Success: Upon a successful call, this method will return summary statistical values about this particular campaign including the number of recipients, the number of total opens, the number of link clicks, the number of recipients who unsubscribed and the number who bounced.

Error: An Exception containing the cause of the error will be raised.



143
144
145
146
# File 'lib/campaigning/types/campaign.rb', line 143

def summary
  response = @soap.getCampaignSummary(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
  handle_request response.campaign_GetSummaryResult
end

#unsubscribesObject

Gets a list of all subscribers who unsubscribed for a given campaign.

Return:

Success: Upon a successful call, this method will return a collection of SubscriberUnsubscribe objects, each of which consists of the emailAddress representing subscribers email address and the listID representing the list they belong to.

Error: An Exception containing the cause of the error will be raised.



156
157
158
159
# File 'lib/campaigning/types/campaign.rb', line 156

def unsubscribes
  response = @soap.getCampaignUnsubscribes(:apiKey => CAMPAIGN_MONITOR_API_KEY, :campaignID => @campaignID )
  handle_request response.campaign_GetUnsubscribesResult
end