Class: AddressBook::Yandex

Inherits:
Base
  • Object
show all
Defined in:
lib/address_book/yandex.rb

Constant Summary collapse

LOGIN_URL =
"http://passport.yandex.ru/passport?mode=auth"
ADDRESS_BOOK_URL =
"https://mail.yandex.ru/neo2/handlers/handlers.jsx"

Instance Attribute Summary

Attributes inherited from Base

#contacts

Instance Method Summary collapse

Methods inherited from Base

#session

Constructor Details

#initialize(login, password) ⇒ Yandex

Returns a new instance of Yandex.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/address_book/yandex.rb', line 8

def initialize(, password)
  response = session.post , { :login => , :passwd => password }

  if response.body.index "b-login-error"
    raise AuthenticationError, "Username or password are incorrect"
  end

  response = session.post ADDRESS_BOOK_URL, { :_handlers => "abook-contacts", :all => "yes" }

  self.contacts = Nokogiri::XML.parse(response.body).css("contact").map do |contact|
    name = contact.at_css "name"
    email = contact.at_css "email"
    [name.values.join(" "), email.content]
  end
end