Class: Yandex::Pdd
- Inherits:
-
Object
- Object
- Yandex::Pdd
- Defined in:
- lib/yandex/pdd.rb
Constant Summary collapse
- API_URL =
'https://pddimp.yandex.ru/'
- TIMEOUT =
10
- POP3_PORT =
110
- IMAP_PORT =
143
- POP3 =
'pop3'
- IMAP =
'imap'
- IMPORT_METHOD =
POP3
- HTTP_ERROR =
'HTTP_ERROR'
- NOT_AUTHORIZED =
'NOT_AUTHORIZED'
- INVALID_RESPONSE =
'INVALID_RESPONSE'
- REQUEST_FAILED =
'REQUEST_FAILED'
- USER_NOT_FOUND =
'USER_NOT_FOUND'
- LOGIN_OCCUPIED =
'LOGIN_OCCUPIED'
- LOGIN_TOO_SHORT =
'LOGIN_TOO_SHORT'
- LOGIN_TOO_LONG =
'LOGIN_TOO_LONG'
- INVALID_LOGIN =
'INVALID_LOGIN'
- INVALID_PASSWORD =
'INVALID_PASSWORD'
- PASSWORD_TOO_SHORT =
'PASSWORD_TOO_SHORT'
- PASSWORD_TOO_LONG =
'PASSWORD_TOO_LONG'
- CANT_CREATE_ACCOUNT =
'CANT_CREATE_ACCOUNT'
- USER_LIMIT_EXCEEDED =
'USER_LIMIT_EXCEEDED'
- NO_IMPORT_SETTINGS =
'NO_IMPORT_SETTINGS'
- SERVICE_ERROR =
'SERVICE_ERROR'
- UNKNOWN_ERROR =
'UNKNOWN_ERROR'
- ERR_R =
{ 'not authenticated' => NOT_AUTHORIZED, 'not_authorized' => NOT_AUTHORIZED, 'no_login' => INVALID_LOGIN, 'bad_login' => INVALID_LOGIN, 'no_user' => USER_NOT_FOUND, 'not_found' => USER_NOT_FOUND, 'user_not_found' => USER_NOT_FOUND, 'no such user registered' => USER_NOT_FOUND, 'occupied' => LOGIN_OCCUPIED, 'login_short' => LOGIN_TOO_SHORT, 'badlogin_length' => LOGIN_TOO_LONG, 'passwd-badpasswd' => INVALID_PASSWORD, 'passwd-tooshort' => PASSWORD_TOO_SHORT, 'passwd-toolong' => PASSWORD_TOO_LONG, 'hundred_users_limit' => USER_LIMIT_EXCEEDED, 'no-passwd_cryptpasswd' => INVALID_PASSWORD, 'cant_create_account' => CANT_CREATE_ACCOUNT, 'no_import_settings' => NO_IMPORT_SETTINGS, 'no import info on this user' => USER_NOT_FOUND, 'unknown' => REQUEST_FAILED, }
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#http_error ⇒ Object
readonly
Returns the value of attribute http_error.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #create_user(login, password, is_encrypted = false) ⇒ Object
- #create_user_encryped(login, password) ⇒ Object
- #delete_user(login) ⇒ Object
- #get_import_status(login) ⇒ Object
- #get_unread_count(login) ⇒ Object
- #get_user(login) ⇒ Object
- #get_user_list(page = 1, per_page = 100) ⇒ Object
- #import_user(login, password, data) ⇒ Object
-
#initialize(token, cert_file = nil) ⇒ Pdd
constructor
A new instance of Pdd.
- #is_user_exists(login) ⇒ Object (also: #is_user_exists?)
- #prepare_import(server, data = {}) ⇒ Object
- #set_forward(login, email, save_copy = 'no') ⇒ Object
- #start_import(login, data) ⇒ Object
-
#stop_import(login) ⇒ Object
# fails for registered users def import_imap_folder(login, data).
- #update_user(login, data) ⇒ Object
Constructor Details
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
60 61 62 |
# File 'lib/yandex/pdd.rb', line 60 def error @error end |
#http_error ⇒ Object (readonly)
Returns the value of attribute http_error.
60 61 62 |
# File 'lib/yandex/pdd.rb', line 60 def http_error @http_error end |
#request ⇒ Object
Returns the value of attribute request.
59 60 61 |
# File 'lib/yandex/pdd.rb', line 59 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
59 60 61 |
# File 'lib/yandex/pdd.rb', line 59 def response @response end |
Instance Method Details
#create_user(login, password, is_encrypted = false) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/yandex/pdd.rb', line 80 def create_user(login, password, is_encrypted=false) url = API_URL if (is_encrypted) url += 'reg_user_crypto.xml?token=' + @token + '&login=' + quote_encode(login) + '&password=' + quote_encode(password) else url += 'reg_user_token.xml?token=' + @token + '&u_login=' + quote_encode(login) + '&u_password=' + quote_encode(password) end return nil unless make_request(url) if ( uid = get_node_attr('/page/ok/@uid') ) return uid end return unknown_error() end |
#create_user_encryped(login, password) ⇒ Object
96 97 98 |
# File 'lib/yandex/pdd.rb', line 96 def create_user_encryped(login, password) return create_user(login, password, true) end |
#delete_user(login) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/yandex/pdd.rb', line 117 def delete_user(login) url = API_URL + 'delete_user.xml?token=' + @token + '&login=' + quote_encode(login) return nil unless make_request(url) return true if is_response_ok return unknown_error() end |
#get_import_status(login) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/yandex/pdd.rb', line 231 def get_import_status(login) url = API_URL + 'check_import.xml?token=' + @token + '&login=' + quote_encode(login) return nil unless make_request(url) data = { :last_check => get_node_attr('/page/ok/@last_check'), :imported => get_node_attr('/page/ok/@imported'), :state => get_node_attr('/page/ok/@state'), } return data end |
#get_unread_count(login) ⇒ Object
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/yandex/pdd.rb', line 124 def get_unread_count(login) url = API_URL + 'get_mail_info.xml?token=' + @token + '&login=' + quote_encode(login) return nil unless make_request(url) if ( count = get_node_attr('/page/ok/@new_messages') ) return count end return unknown_error() end |
#get_user(login) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/yandex/pdd.rb', line 147 def get_user(login) url = API_URL + 'get_user_info.xml?token=' + @token + '&login=' + quote_encode(login) return nil unless make_request(url) user = { :domain => get_node_text('/page/domain/name'), :login => get_node_text('/page/domain/user/login'), :birth_date => get_node_text('/page/domain/user/birth_date'), :fname => get_node_text('/page/domain/user/fname'), :iname => get_node_text('/page/domain/user/iname'), :hinta => get_node_text('/page/domain/user/hinta'), :hintq => get_node_text('/page/domain/user/hintq'), :mail_format => get_node_text('/page/domain/user/mail_format'), :charset => get_node_text('/page/domain/user/charset'), :nickname => get_node_text('/page/domain/user/nickname'), :sex => get_node_text('/page/domain/user/sex'), :enabled => get_node_text('/page/domain/user/enabled'), :signed_eula => get_node_text('/page/domain/user/signed_eula'), } return user end |
#get_user_list(page = 1, per_page = 100) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/yandex/pdd.rb', line 169 def get_user_list(page=1, per_page=100) url = API_URL + 'get_domain_users.xml?token=' + @token + '&page=%20' + quote_encode(page) + # HACK XXX '&per_page=' + quote_encode(per_page) return nil unless make_request(url) emails = [] get_node('/page/domains/domain/emails/email/name').each do |n| emails.push(n.inner_xml) unless n.nil? end data = { :action_status => get_node_text('/page/domains/domain/emails/action-status'), :found => get_node_text('/page/domains/domain/emails/found'), :total => get_node_text('/page/domains/domain/emails/total'), :domain => get_node_text('/page/domains/domain/name'), :status => get_node_text('/page/domains/domain/status'), :emails_max_count => get_node_text('/page/domains/domain/emails-max-count'), :emails => emails, } return data end |
#import_user(login, password, data) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/yandex/pdd.rb', line 215 def import_user(login, password, data) data[:login] ||= login data[:save_copy] = ( data[:save_copy] ) ? 'yes' : '0' url = API_URL + 'reg_and_imp.xml?token=' + @token + '&login=' + quote_encode(login) + '&inn_password=' + quote_encode(password) + '&ext_login=' + quote_encode(data[:login]) + '&ext_password=' + quote_encode(data[:password]) + '&fwd_email=' + quote_encode(data[:forward_to]) + '&fwd_copy=' + quote_encode(data[:save_copy]) return nil unless make_request(url) return true if is_response_ok return unknown_error() end |
#is_user_exists(login) ⇒ Object Also known as: is_user_exists?
68 69 70 71 72 73 74 75 76 |
# File 'lib/yandex/pdd.rb', line 68 def is_user_exists(login) url = API_URL + 'check_user.xml?token=' + @token + '&login=' + quote_encode(login) return nil unless make_request(url) if ( result = get_node_text('/page/result') ) return true if ( 'exists' == result ) return false if ( 'nouser' == result ) end return unknown_error() end |
#prepare_import(server, data = {}) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/yandex/pdd.rb', line 193 def prepare_import(server, data={}) data[:method] = 'pop3' unless ( data[:method] and data[:method] !~ /^pop3|imap$/i ) url = API_URL + 'set_domain.xml?token=' + @token + '&ext_serv=' + server + '&method=' + data[:method] url += '&ext_port=' + data[:port] if ( data[:port] ) url += '&callback=' + data[:callback] if ( data[:callback] ) url += '&isssl=no' unless ( data[:use_ssl] ) return nil unless make_request(url) return true if is_response_ok return unknown_error() end |
#set_forward(login, email, save_copy = 'no') ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/yandex/pdd.rb', line 135 def set_forward(login, email, save_copy='no') save_copy = (save_copy and not 'no' == save_copy) ? 'yes' : 'no' url = API_URL + 'set_forward.xml?token=' + @token + '&login=' + quote_encode(login) + '&address=' + quote_encode(address) + '©=' + save_copy return nil unless make_request(url) return true if is_response_ok return unknown_error() end |
#start_import(login, data) ⇒ Object
207 208 209 210 211 212 213 |
# File 'lib/yandex/pdd.rb', line 207 def start_import(login, data) url = API_URL + 'start_import.xml?token=' + @token + '&login=' + quote_encode(login) + '&ext_login=' + quote_encode(data[:login]) + '&password=' + quote_encode(data[:password]) return nil unless make_request(url) return true end |
#stop_import(login) ⇒ Object
# fails for registered users def import_imap_folder(login, data)
data ||= login
my $url = API_URL + ‘import_imap.xml?token=’ + @token + ‘&login=’ + quote_encode(login) + ‘&ext_login=’ + quote_encode(data) + ‘&int_password=’ + quote_encode(password) + ‘&ext_password=’ + quote_encode(data) + ‘©_one_folder=’ + quote_encode(data) return nil unless make_request(url)
return true if is_response_ok return unknown_error() end
259 260 261 262 263 264 265 |
# File 'lib/yandex/pdd.rb', line 259 def stop_import(login) return nil unless (login) url = API_URL + 'stop_import.xml?token=' + @token + '&login=' + quote_encode(login) return nil unless make_request(url) return true if is_response_ok return unknown_error() end |
#update_user(login, data) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/yandex/pdd.rb', line 100 def update_user(login, data) url = API_URL + 'edit_user.xml?token=' + @token + '&login=' + quote_encode(login) + '&password=' + quote_encode(data[:password]) + '&iname=' + quote_encode(data[:iname] ) + '&fname=' + quote_encode(data[:fname] ) + '&sex=' + quote_encode(data[:sex] ) + '&hintq=' + quote_encode(data[:hintq] ) + '&hinta=' + quote_encode(data[:hinta] ) return nil unless make_request(url) if ( uid = get_node_attr('/page/ok/@uid') ) return uid end return unknown_error() end |