Class: Mailroute::EmailAccount
- Inherits:
-
Base
- Object
- ActiveResource::Base
- Base
- Mailroute::EmailAccount
show all
- Defined in:
- lib/mailroute/models/email_account.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
bulk_create, delete, has_admins, has_many, has_one, headers, #initialize, instantiate_collection, instantiate_collection_without_meta, list, #load, meta, #reload, #to_json, total_count
included
Class Method Details
.create(*args) ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/mailroute/models/email_account.rb', line 83
def create(*args)
if args.size == 1 && args.first.is_a?(String)
localpart, domain_name = *args.first.split('@')
domain = Domain.get(domain_name)
raise ActiveResource::ResourceNotFound, "Domain with name #{domain_name} not found" unless domain
create_by_attributes(:localpart => localpart, :domain => domain, :create_opt => 'generate_pwd')
else
create_by_attributes(*args)
end
end
|
.create_by_attributes ⇒ Object
82
|
# File 'lib/mailroute/models/email_account.rb', line 82
alias_method :create_by_attributes, :create
|
.get(*args) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/mailroute/models/email_account.rb', line 64
def get(*args)
if args.size == 1
get_by_id(*args)
else
localpart, domain = *args
case domain
when Domain
get(localpart, domain.id)
when String
get(localpart, Domain.get(domain))
when Integer
EmailAccount.filter(:domain => domain, :localpart => localpart).first or raise ActiveResource::ResourceNotFound
else
raise 'Unknown argument type'
end
end
end
|
.get_by_id ⇒ Object
63
|
# File 'lib/mailroute/models/email_account.rb', line 63
alias_method :get_by_id, :get
|
Instance Method Details
#active_notification_tasks ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/mailroute/models/email_account.rb', line 46
def active_notification_tasks
if use_domain_notifications
domain.notification_tasks
else
notification_tasks
end
end
|
#add_alias(localpart) ⇒ Object
37
38
39
|
# File 'lib/mailroute/models/email_account.rb', line 37
def add_alias(localpart)
LocalpartAlias.create(:email_account => self, :localpart => localpart)
end
|
#add_to_blacklist(address) ⇒ Object
19
20
21
|
# File 'lib/mailroute/models/email_account.rb', line 19
def add_to_blacklist(address)
create_wblist(:wb => 'b', :email => address)
end
|
#add_to_whitelist(address) ⇒ Object
23
24
25
|
# File 'lib/mailroute/models/email_account.rb', line 23
def add_to_whitelist(address)
create_wblist(:wb => 'w', :email => address)
end
|
#blacklist ⇒ Object
11
12
13
|
# File 'lib/mailroute/models/email_account.rb', line 11
def blacklist
WBList.filter(:email_account => id, :wb => 'b').map(&:email)
end
|
#bulk_add_aliases(localparts) ⇒ Object
41
42
43
44
|
# File 'lib/mailroute/models/email_account.rb', line 41
def bulk_add_aliases(localparts)
request_body = self.class.format.encode(:aliases => localparts)
connection.post(element_path(prefix_options) + 'mass_add_aliases/', request_body, self.class.)
end
|
#regenerate_api_key ⇒ Object
32
33
34
35
|
# File 'lib/mailroute/models/email_account.rb', line 32
def regenerate_api_key
response = connection.post(element_path(prefix_options) + 'regenerate_api_key/', nil, self.class.)
self.class.format.decode(response.body)['api_key']
end
|
#set_password(new_password) ⇒ Object
27
28
29
30
|
# File 'lib/mailroute/models/email_account.rb', line 27
def set_password(new_password)
self.password = self.confirm_password = new_password
save!
end
|
#use_domain_notifications! ⇒ Object
54
55
56
|
# File 'lib/mailroute/models/email_account.rb', line 54
def use_domain_notifications!
update_attribute(:use_domain_notifications, true)
end
|
#use_self_notifications! ⇒ Object
58
59
60
|
# File 'lib/mailroute/models/email_account.rb', line 58
def use_self_notifications!
update_attribute(:use_domain_notifications, false)
end
|
#whitelist ⇒ Object
15
16
17
|
# File 'lib/mailroute/models/email_account.rb', line 15
def whitelist
WBList.filter(:email_account => id, :wb => 'w').map(&:email)
end
|