Class: Lita::Handlers::YandexDomains
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::YandexDomains
show all
- Includes:
- YandexHelper::Regex
- Defined in:
- lib/lita/handlers/yandex_domains.rb
Constant Summary
YandexHelper::Regex::EMAIL_PATTERN, YandexHelper::Regex::MAILLIST_PATTERN
Instance Method Summary
collapse
Instance Method Details
#add_subscriber(response) ⇒ Object
154
155
156
157
158
159
|
# File 'lib/lita/handlers/yandex_domains.rb', line 154
def add_subscriber(response)
email = response.match_data['email']
maillist = response.match_data['maillist']
message = yandex_client.subscription_add(options = { domain: config.domain, maillist: maillist, subscriber: email })
response.reply(message)
end
|
#create_email(response) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/lita/handlers/yandex_domains.rb', line 101
def create_email(response)
email = response.match_data['email']
domain = email.split('@').last
if domain == config.domain
password = generate_passwd
status = yandex_client.mailbox_add(options = { domain: config.domain, login: email, password: password })
if status['success'] == 'error'
message = status
else
message = "Email #{email} with password #{password} was successfully created. Please login to mailbox using https//mail.#{domain}"
end
else
message = error_message(domain)
end
response.reply(message)
end
|
#create_maillist(response) ⇒ Object
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/lita/handlers/yandex_domains.rb', line 128
def create_maillist(response)
email = response.match_data['maillist']
domain = email.split('@').last
if domain == config.domain
message = yandex_client.maillist_add(options = { domain: config.domain, maillist: email })
else
message = error_message(domain)
end
response.reply(message)
end
|
#delete_email(response) ⇒ Object
118
119
120
121
122
|
# File 'lib/lita/handlers/yandex_domains.rb', line 118
def delete_email(response)
email = response.match_data['email']
message = yandex_client.mailbox_delete(options = { domain: config.domain, login: email })
response.reply(message)
end
|
#delete_maillist(response) ⇒ Object
139
140
141
142
143
|
# File 'lib/lita/handlers/yandex_domains.rb', line 139
def delete_maillist(response)
email = response.match_data['maillist']
message = yandex_client.maillist_delete(options = { domain: config.domain, maillist: email })
response.reply(message)
end
|
#remove_subscriber(response) ⇒ Object
161
162
163
164
165
166
|
# File 'lib/lita/handlers/yandex_domains.rb', line 161
def remove_subscriber(response)
email = response.match_data['email']
maillist = response.match_data['maillist']
message = yandex_client.subscription_destroy(options = { domain: config.domain, maillist: maillist, subscriber: email })
response.reply(message)
end
|
#show_all_emails(response) ⇒ Object
124
125
126
|
# File 'lib/lita/handlers/yandex_domains.rb', line 124
def show_all_emails(response)
show_emails(response, maillist='no')
end
|
#show_all_maillists(response) ⇒ Object
145
146
147
148
149
150
151
152
|
# File 'lib/lita/handlers/yandex_domains.rb', line 145
def show_all_maillists(response)
emails = []
message = yandex_client.maillist_list(domain=config.domain)
message['maillists'].each do |maillist|
emails.push(maillist['maillist'])
end
response.reply(emails)
end
|
#show_subscribers(response) ⇒ Object
168
169
170
171
172
173
174
175
176
|
# File 'lib/lita/handlers/yandex_domains.rb', line 168
def show_subscribers(response)
emails = []
maillist = response.match_data['maillist']
message = yandex_client.subscription_sublist(config.domain, maillist)
message['subscribers'].each do |subscriber|
emails.push(subscriber)
end
response.reply(emails.sort)
end
|
#yandex_client ⇒ Object
10
11
12
|
# File 'lib/lita/handlers/yandex_domains.rb', line 10
def yandex_client
@yandex_client ||= Yandex::Pdd::Client.new(config.pdd_token)
end
|