Class: CreateSend::Campaign

Inherits:
Object
  • Object
show all
Defined in:
lib/createsend/campaign.rb

Overview

Represents a campaign and provides associated funtionality.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(campaign_id) ⇒ Campaign

Returns a new instance of Campaign.



9
10
11
# File 'lib/createsend/campaign.rb', line 9

def initialize(campaign_id)
  @campaign_id = campaign_id
end

Instance Attribute Details

#campaign_idObject (readonly)

Returns the value of attribute campaign_id.



7
8
9
# File 'lib/createsend/campaign.rb', line 7

def campaign_id
  @campaign_id
end

Class Method Details

.create(client_id, subject, name, from_name, from_email, reply_to, html_url, text_url, list_ids, segment_ids) ⇒ Object

Creates a new campaign for a client.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/createsend/campaign.rb', line 14

def self.create(client_id, subject, name, from_name, from_email, reply_to, html_url,
  text_url, list_ids, segment_ids)
  options = { :body => { 
    :Subject => subject,
    :Name => name,
    :FromName => from_name,
    :FromEmail => from_email,
    :ReplyTo => reply_to,
    :HtmlUrl => html_url,
    :TextUrl => text_url,
    :ListIDs => list_ids,
    :SegmentIDs => segment_ids }.to_json }
  response = CreateSend.post "/campaigns/#{client_id}.json", options
  response.parsed_response
end

Instance Method Details

#bounces(page = 1, page_size = 1000, order_field = "date", order_direction = "asc") ⇒ Object

Retrieves the bounces for this campaign.



111
112
113
114
115
116
117
118
119
# File 'lib/createsend/campaign.rb', line 111

def bounces(page=1, page_size=1000, order_field="date", order_direction="asc")
  options = { :query => { 
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "bounces", options
  Hashie::Mash.new(response)
end

#clicks(date, page = 1, page_size = 1000, order_field = "date", order_direction = "asc") ⇒ Object

Retrieves the subscriber clicks for this campaign.



87
88
89
90
91
92
93
94
95
96
# File 'lib/createsend/campaign.rb', line 87

def clicks(date, page=1, page_size=1000, order_field="date", order_direction="asc")
  options = { :query => { 
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "clicks", options
  Hashie::Mash.new(response)
end

#deleteObject

Deletes this campaign.



47
48
49
# File 'lib/createsend/campaign.rb', line 47

def delete
  response = CreateSend.delete "/campaigns/#{campaign_id}.json", {}
end

#lists_and_segmentsObject

Retrieves the lists and segments to which this campaaign will be (or was) sent.



58
59
60
61
# File 'lib/createsend/campaign.rb', line 58

def lists_and_segments
  response = get "listsandsegments", {}
  Hashie::Mash.new(response)
end

#opens(date, page = 1, page_size = 1000, order_field = "date", order_direction = "asc") ⇒ Object

Retrieves the opens for this campaign.



75
76
77
78
79
80
81
82
83
84
# File 'lib/createsend/campaign.rb', line 75

def opens(date, page=1, page_size=1000, order_field="date", order_direction="asc")
  options = { :query => { 
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "opens", options
  Hashie::Mash.new(response)
end

#recipients(page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object

Retrieves the recipients of this campaign.



64
65
66
67
68
69
70
71
72
# File 'lib/createsend/campaign.rb', line 64

def recipients(page=1, page_size=1000, order_field="email", order_direction="asc")
  options = { :query => { 
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get 'recipients', options
  Hashie::Mash.new(response)
end

#send(confirmation_email, send_date = "immediately") ⇒ Object

Sends this campaign.



39
40
41
42
43
44
# File 'lib/createsend/campaign.rb', line 39

def send(confirmation_email, send_date="immediately")
  options = { :body => {
    :ConfirmationEmail => confirmation_email,
    :SendDate => send_date }.to_json }
  response = post "send", options
end

#send_preview(recipients, personalize = "fallback") ⇒ Object

Sends a preview of this campaign.



31
32
33
34
35
36
# File 'lib/createsend/campaign.rb', line 31

def send_preview(recipients, personalize="fallback")
  options = { :body => {
    :PreviewRecipients => recipients.kind_of?(String) ? [ recipients ] : recipients,
    :Personalize => personalize }.to_json }
  response = post "sendpreview", options
end

#summaryObject

Gets a summary of this campaign



52
53
54
55
# File 'lib/createsend/campaign.rb', line 52

def summary
  response = get "summary", {}
  Hashie::Mash.new(response)
end

#unsubscribes(date, page = 1, page_size = 1000, order_field = "date", order_direction = "asc") ⇒ Object

Retrieves the unsubscribes for this campaign.



99
100
101
102
103
104
105
106
107
108
# File 'lib/createsend/campaign.rb', line 99

def unsubscribes(date, page=1, page_size=1000, order_field="date", order_direction="asc")
  options = { :query => { 
    :date => date,
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get "unsubscribes", options
  Hashie::Mash.new(response)
end