Class: CakeMail::User

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, args) ⇒ User

Returns a new instance of User.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
# File 'lib/cakemail/user.rb', line 23

def initialize(session, args)
  raise ArgumentError if session.nil? or args[:id].nil?
  @session = session
  @client_id = args[:client_id].to_i
  @client_key = args[:client_key]
  @id = args[:id].to_i
  @user_key = args[:user_key]
  get_info
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



20
21
22
# File 'lib/cakemail/user.rb', line 20

def client_id
  @client_id
end

#created_onObject (readonly)

Returns the value of attribute created_on.



20
21
22
# File 'lib/cakemail/user.rb', line 20

def created_on
  @created_on
end

#emailObject

Returns the value of attribute email.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def first_name
  @first_name
end

#groupsObject (readonly)

Returns the value of attribute groups.



20
21
22
# File 'lib/cakemail/user.rb', line 20

def groups
  @groups
end

#languageObject

Returns the value of attribute language.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def language
  @language
end

#last_activityObject (readonly)

Returns the value of attribute last_activity.



20
21
22
# File 'lib/cakemail/user.rb', line 20

def last_activity
  @last_activity
end

#last_nameObject

Returns the value of attribute last_name.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def last_name
  @last_name
end

#mobile_phoneObject

Returns the value of attribute mobile_phone.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def mobile_phone
  @mobile_phone
end

#office_phoneObject

Returns the value of attribute office_phone.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def office_phone
  @office_phone
end

#passwordObject

Returns the value of attribute password.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def password
  @password
end

#sessionObject (readonly)

Returns the value of attribute session.



20
21
22
# File 'lib/cakemail/user.rb', line 20

def session
  @session
end

#statusObject

Returns the value of attribute status.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def status
  @status
end

#timezoneObject (readonly)

Returns the value of attribute timezone.



20
21
22
# File 'lib/cakemail/user.rb', line 20

def timezone
  @timezone
end

#timezone_idObject (readonly)

Returns the value of attribute timezone_id.



20
21
22
# File 'lib/cakemail/user.rb', line 20

def timezone_id
  @timezone_id
end

#titleObject

Returns the value of attribute title.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def title
  @title
end

#user_idObject (readonly)

Returns the value of attribute user_id.



20
21
22
# File 'lib/cakemail/user.rb', line 20

def user_id
  @user_id
end

#user_keyObject

Returns the value of attribute user_key.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def user_key
  @user_key
end

#wysiwygObject

Returns the value of attribute wysiwyg.



21
22
23
# File 'lib/cakemail/user.rb', line 21

def wysiwyg
  @wysiwyg
end

Class Method Details

.login(session, email, password) ⇒ Object

Returns a logged in user object.



168
169
170
171
172
# File 'lib/cakemail/user.rb', line 168

def (session, email, password)
  res = session.request("CakeMail::API::ClassUser", "Login", { :email => email, :password => password })
  User.new(session, { :client_id => res['client_id'].first, :client_key => res['client_key'].first, 
    :id => res['user_id'].first, :user_key => res['user_key'].first })
end

.password_recovery(email, subject = "CakeMail Password Recovery", text = "Your password is: ") ⇒ Object

Sends by email the user’s password.



174
175
176
# File 'lib/cakemail/user.rb', line 174

def password_recovery(email, subject = "CakeMail Password Recovery", text = "Your password is: ")
  session.request("CakeMail::API::ClassUser", "PasswordRecovery", { :email => email, :subject => subject, :text => text })
end

Instance Method Details

#campaign(id) ⇒ Object

Returns campaign object.



66
67
68
# File 'lib/cakemail/user.rb', line 66

def campaign(id)
  return CakeMail::Campaign.new(id, self)
end

#campaign_new(name) ⇒ Object

Creates new campaign.



70
71
72
# File 'lib/cakemail/user.rb', line 70

def campaign_new(name)
  return CakeMail::Campaign.create(name, self)
end

#client(id) ⇒ Object

Returns client object.



74
75
76
# File 'lib/cakemail/user.rb', line 74

def client(id)
  return CakeMail::Client.new(id, self)
end

#client_new(args) ⇒ Object

Creates a new client.

Arguments :

  • args = { :company_name => required, :admin_email => required, :admin_first_name => required, :admin_last_name => required, :admin_password => required, :contact_email => required, :contact_first_name => required, :contact_last_name => required, :contact_password => required, :parent_id => optional, :currency => optional, :address1 => optional, :address2 => optionall, :city => optional, :province_id => optional, :country_id => optional, :postal_code => optional, :website => optional, :phone => optional, :fax => optional, :admin_title => optional, :admin_office_phone => required, :admin_mobile_phone => optional, :admin_language => optional, :contact_title => optional, :contact_language => optional, :contact_timezone_id => optional, :contact_office_phone => optional, :contact_mobile_phone => optional }

Raises:

  • (ArgumentError)


87
88
89
90
91
92
93
# File 'lib/cakemail/user.rb', line 87

def client_new(args)
  raise ArgumentError if args.nil? or args[:user].nil? or args[:company_name].nil? or args[:admin_email].nil? or 
    args[:admin_first_name].nil? or args[:admin_last_name].nil? or args[:admin_password].nil? or args[:contact_email].nil? or
    args[:contact_first_name].nil? or args[:contact_last_name].nil? or args[:contact_password].nil?
  args[:user] = self
  return CakeMail::Client.create(args)
end

#create(email, password, first_name, last_name, title = nil, language = 'en_US', timezone_id = 152, office_phone = nil, mobile_phone = nil) ⇒ Object

Creates a user.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cakemail/user.rb', line 33

def create(email, password, first_name, last_name, title = nil, language = 'en_US', timezone_id = 152, office_phone = nil, 
  mobile_phone = nil)
  args = { :email => email, :password => password, :password_confirmation => password, :first_name => first_name, 
    :language => language, :last_name => last_name, 
    :timezone_id => timeezone_id, :user_key => @user_key }
  args[:title] = title unless title.nil?
  args[:office_phone] = office_phone unless office_phone.nil?
  args[:mobile_phone] = mobile_phone unless mobile_phone.nil?
  res = @session.request("CakeMail::API::ClassUser", "Create", args)
  user = getinfo(res['user_id'].first.to_i)
  user.user_key = res['user_key'].first
  return user
end

#get_info(id = @id) ⇒ Object

Retrieves informations about a user.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cakemail/user.rb', line 47

def get_info(id = @id)
  res = @session.request("CakeMail::API::ClassUser", "GetInfo", { :user_id => id, :user_key => @user_key })
  email = res['email'].first
  password = res['password'].first
  status = res['status'].first
  created_on = res['created_on'].first
  last_activity = res['last_activity'].first
  first_name = res['first_name'].first
  last_name = res['last_name'].first
  title = res['title'].first
  language = res['language'].first,
  timezone = res['timezone'].first 
  timezone_id = res['timezone_id'].first,
  office_phone = res['office_phone'].first
  mobile_phone = res['mobile_phone'].first
  wysiwyg = res['wysiwyg'].first
  group_ids = res['group_id']
end

#group(id) ⇒ Object

Returns a group.



110
111
112
# File 'lib/cakemail/user.rb', line 110

def group(id)
  return CakeMail::Group.new(id, self)
end

#group_new(name, client_id = nil) ⇒ Object

Creates a new group.



114
115
116
117
118
# File 'lib/cakemail/user.rb', line 114

def group_new(name, client_id = nil)
  args = { :user => self, :name => name }
  args[:client_id] = client_id unless client_id.nil?
  return CakeMail::Group.create(args)
end

#list(id) ⇒ Object

Returns a list.



95
96
97
# File 'lib/cakemail/user.rb', line 95

def list(id)
  return CakeMail::List.new(id, self)
end

#list_new(args) ⇒ Object

Creates a list.

Arguments :

  • args = { :name => required, :sender_name => required, :sender_email, :data => optional/custom }

Custom argument:

  • :data => [ { :type => “text”, :value => “city” }, { :type => “integer”, :value => “age” }, … ]

Raises:

  • (ArgumentError)


104
105
106
107
108
# File 'lib/cakemail/user.rb', line 104

def list_new(args)
  raise ArgumentError if args.nil? or args[:name].nil? or args[:sender_email].nil? or args[:sender_name].nil?
  args[:user] = self
  return CakeMail::List.create(args)
end

#saveObject



145
146
147
# File 'lib/cakemail/user.rb', line 145

def save
  self.setinfo
end

#set_infoObject

Modifies a user.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/cakemail/user.rb', line 149

def set_info
  args = { :user_id => @id, :user_key => @user_key }
  args[:email] = @email unless @email.nil?
  args[:password] = @password unless @password.nil?
  args[:password_confirmation] = @password unless @password.nil?
  args[:status] = @status unless @status.nil?
  args[:first_name] = @first_name unless @first_name.nil?
  args[:last_name] = @last_name unless @last_name.nil?
  args[:title] = @title unless @title.nil?
  args[:language] = @language unless @language.nil?
  args[:timezone_id] = @timezone_id unless @timezone_id.nil?
  args[:office_phone] = @office_phone unless @office_phone.nil?
  args[:mobile_phone] = @mobile_phone unless @mobile_phone.nil?
  args[:wysiwyg] = @wysiwyg unless @wysiwyg.nil?
  @session.request("CakeMail::API::ClassUser", "SetInfo", args )
end

#template(id) ⇒ Object

Returns a template.



120
121
122
# File 'lib/cakemail/user.rb', line 120

def template(id)
  return CakeMail::Template.new(id, self)
end

#template_new(args) ⇒ Object

Creates a new template.

Arguments :

  • options = { :name => required, :type => optional, :message => optional }



127
128
129
130
# File 'lib/cakemail/user.rb', line 127

def template_new(args)
  args[:user] = self
  return CakeMail::Template.create(args)
end

#trigger(id) ⇒ Object

Returns a trigger.



132
133
134
# File 'lib/cakemail/user.rb', line 132

def trigger(id)
  return CakeMail::Trigger.new(id, self)
end

#trigger_new(args) ⇒ Object

Creates a new trigger

Arguments :

  • args = { :name => required, :list_id => required, :encoding => optional, :description => optional }

Raises:

  • (ArgumentError)


139
140
141
142
143
# File 'lib/cakemail/user.rb', line 139

def trigger_new(args)
  raise ArgumentError if args.nil? or args[:name].nil? or args[:list_id]
  args[:user] = self
  return CakeMail::Trigger.create(args)
end