Class: CakeMail::Campaign

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, user) ⇒ Campaign

Returns a new instance of Campaign.



21
22
23
24
25
# File 'lib/cakemail/campaign.rb', line 21

def initialize(id, user)
  @user = user
  @id = id
  get_info
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



18
19
20
# File 'lib/cakemail/campaign.rb', line 18

def client_id
  @client_id
end

#closed_onObject (readonly)

Returns the value of attribute closed_on.



18
19
20
# File 'lib/cakemail/campaign.rb', line 18

def closed_on
  @closed_on
end

#created_onObject (readonly)

Returns the value of attribute created_on.



18
19
20
# File 'lib/cakemail/campaign.rb', line 18

def created_on
  @created_on
end

#idObject (readonly)

Returns the value of attribute id.



18
19
20
# File 'lib/cakemail/campaign.rb', line 18

def id
  @id
end

#nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/cakemail/campaign.rb', line 19

def name
  @name
end

#sessionObject (readonly)

Returns the value of attribute session.



18
19
20
# File 'lib/cakemail/campaign.rb', line 18

def session
  @session
end

#statusObject

Returns the value of attribute status.



19
20
21
# File 'lib/cakemail/campaign.rb', line 19

def status
  @status
end

#userObject (readonly)

Returns the value of attribute user.



18
19
20
# File 'lib/cakemail/campaign.rb', line 18

def user
  @user
end

Class Method Details

.create(name, user) ⇒ Object

Creates a new campaign.



63
64
65
66
# File 'lib/cakemail/campaign.rb', line 63

def create(name, user)
   res = user.session.request("CakeMail::API::ClassCampaign", "Create", { :name => name, :user_key => user.user_key })
   Campaign.new(res['id'].first, user)
end

.getlist(args) ⇒ Object

Retrieves the list of campaigns.

Arguments :

  • args = { :user => required, :limit => optional, :offset => optional, :status => optional }

Raises:

  • (ArgumentError)


71
72
73
74
75
76
77
78
79
# File 'lib/cakemail/campaign.rb', line 71

def getlist(args)
  raise ArgumentError if args.nil? or args[:user].nil?
  options = { :user_key => args[:user].user_key }
  options[:limit] = args[:limit] unless args[:limit].nil?
  options[:offset] = args[:offset] unless args[:offset].nil?
  options[:status] = args[:status] unless args[:status].nil?
  res = args[:user].session.request("CakeMail::API::ClassCampaign", "GetList", options)
  res['campaign']
end

Instance Method Details

#deleteObject

Deletes a campaign.



27
28
29
30
# File 'lib/cakemail/campaign.rb', line 27

def delete
  @user.session.request("CakeMail::API::ClassCampaign", "Delete", { :campaign_id => @id, :user_key => @user.user_key })
  self.freeze
end

#get_info(id = @id) ⇒ Object

Returns information about a campaign.



32
33
34
35
36
37
38
39
40
# File 'lib/cakemail/campaign.rb', line 32

def get_info(id = @id)
  res = @user.session.request("CakeMail::API::ClassCampaign", "GetInfo", { :campaign_id => id, :user_key => @user.user_key })
  @client_id = res['client_id'].first
  @closed_on = res['closed_on'].first
  @created_on = res['created_on'].first
  @id = res['id'].first
  @name = res['name'].first
  @status = res['status'].first
end

#mailing(id) ⇒ Object

Retreives a mailing by id.



42
43
44
# File 'lib/cakemail/campaign.rb', line 42

def mailing(id)
  return CakeMail::Mailing.new(self, id)
end

#mailing_new(name) ⇒ Object

Creates a new mailing.



46
47
48
# File 'lib/cakemail/campaign.rb', line 46

def mailing_new(name)
  return CakeMail::Mailing.create(self, name)
end

#saveObject



50
51
52
# File 'lib/cakemail/campaign.rb', line 50

def save
  self.setinfo
end

#set_infoObject

Modifies a campaign.



54
55
56
57
58
59
# File 'lib/cakemail/campaign.rb', line 54

def set_info
  args = { :campaign_id => id, :user_key => @user.user_key }
  args[:name] = @name unless @name.nil?
  args[:status] = @status unless @status.nil?
  res = @user.session.request("CakeMail::API::ClassCampaign", "SetInfo", args)
end