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
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/mailroute/models/email_account.rb', line 58
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
57
|
# File 'lib/mailroute/models/email_account.rb', line 57
alias_method :create_by_attributes, :create
|
.get(*args) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/mailroute/models/email_account.rb', line 39
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
38
|
# File 'lib/mailroute/models/email_account.rb', line 38
alias_method :get_by_id, :get
|
Instance Method Details
#add_to_blacklist(address) ⇒ Object
18
19
20
|
# File 'lib/mailroute/models/email_account.rb', line 18
def add_to_blacklist(address)
create_wblist(:wb => 'b', :email => address)
end
|
#add_to_whitelist(address) ⇒ Object
22
23
24
|
# File 'lib/mailroute/models/email_account.rb', line 22
def add_to_whitelist(address)
create_wblist(:wb => 'w', :email => address)
end
|
#blacklist ⇒ Object
10
11
12
|
# File 'lib/mailroute/models/email_account.rb', line 10
def blacklist
WBList.filter(:email_account => id, :wb => 'b').map(&:email)
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
26
27
28
29
30
|
# File 'lib/mailroute/models/email_account.rb', line 26
def set_password(new_password)
self.password = new_password
save!
self
end
|
#whitelist ⇒ Object
14
15
16
|
# File 'lib/mailroute/models/email_account.rb', line 14
def whitelist
WBList.filter(:email_account => id, :wb => 'w').map(&:email)
end
|