Class: CakeMail::Group

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, user) ⇒ Group

Returns a new instance of Group.



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

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

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



25
26
27
# File 'lib/cakemail/group.rb', line 25

def client_id
  @client_id
end

#idObject (readonly)

Returns the value of attribute id.



24
25
26
# File 'lib/cakemail/group.rb', line 24

def id
  @id
end

#nameObject

Returns the value of attribute name.



25
26
27
# File 'lib/cakemail/group.rb', line 25

def name
  @name
end

#permissionObject (readonly)

Returns the value of attribute permission.



24
25
26
# File 'lib/cakemail/group.rb', line 24

def permission
  @permission
end

Class Method Details

.create(user, name, client_id = nil) ⇒ Object

Creates a group.



78
79
80
81
82
83
# File 'lib/cakemail/group.rb', line 78

def create(user, name, client_id = nil)
  args = { :name => name, :user_key => user.user_key }
  args[:client_id] = client_id unless client_id.nil?
  res = user.session.request("CakeMail::API::ClassGroup", "Create", args)
  Group.new(user, { :id => res['id'].first })
end

.get_list(args) ⇒ Object

Retrieves the list of groups.

Arguments :

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



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cakemail/group.rb', line 88

def get_list(args)
  options = { :user_key => args[:user].user_key }
  options[:count] = args[:count] unless args[:count].nil?
  options[:client_id] = args[:client_id] unless args[:client_id].nil?
  options[:limit] = args[:limit] unless args[:limit].nil?
  options[:offset] = args[:offset] unless args[:offset].nil?
  res = args[:user].session.request("CakeMail::API::ClassCampaign", "GetList", options)
  if !args[:count].nil?
    return res['count'].first
  end
  return res['campaign']
end

Instance Method Details

#add_user(user_id, client_id = nil) ⇒ Object

Adds a user into a group.



33
34
35
36
37
# File 'lib/cakemail/group.rb', line 33

def add_user(user_id, client_id = nil)
  args = { :user_id => user_id, :group_id => @id, :user_key => @user.user_key }
  args[:client_id] = client_id unless client_id.nil?
  @user.session.request("CakeMail::API::ClassGroup", "AddUser", args)
end

#delete(client_id = nil) ⇒ Object

Deletes a group.



45
46
47
48
49
50
# File 'lib/cakemail/group.rb', line 45

def delete(client_id = nil)
  args = { :group_id => @id, :user_key => @user.user_key }
  args[:client_id] = client_id unless client_id.nil?
  @user.session.request("CakeMail::API::ClassGroup", "Delete", args)
  self.freeze
end

#get_info(id = @id, client_id = nil) ⇒ Object

Returns information about a group.



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

def get_info(id = @id, client_id = nil)
  args = { :group_id => @id, :user_key => @user.user_key }
  args[:client_id] = client_id unless client_id.nil?
  res = @user.session.request("CakeMail::API::ClassCampaign", "GetInfo", args)
  @id = res['id'].first
  @name = res['name'].first
  @permission = res['permission']
end

#remove_user(user_id, client_id = nil) ⇒ Object

Removes a user from a group.



39
40
41
42
43
# File 'lib/cakemail/group.rb', line 39

def remove_user(user_id, client_id = nil)
  args = { :user_id => user_id, :group_id => @id, :user_key => @user.user_key }
  args[:client_id] = client_id unless client_id.nil?
  @user.session.request("CakeMail::API::ClassGroup", "RemoveUser", args)
end

#saveObject



61
62
63
# File 'lib/cakemail/group.rb', line 61

def save
  self.setinfo
end

#set_info(data = nil) ⇒ Object

Modifies a group.

Custom argument:

  • data = [ { :type => “CLASS_USER_CREATE”, :value => “1” }, { :type => “CLASS_USER_SET_INFO”, :value => “0” }, … ]



68
69
70
71
72
73
74
# File 'lib/cakemail/group.rb', line 68

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