Class: Contacts::Onelt

Inherits:
Base
  • Object
show all
Defined in:
lib/contacts/onelt.rb

Constant Summary collapse

DETECTED_DOMAINS =
[ /one\.lt/i ]
LOGIN_URL =
"http://w33.one.lt/logonSubsite.do?subsite=pastas"
EMAIL_URL =
"http://email.one.lt/"
ADDRESS_BOOK_URL =
"http://w33.one.lt/resinRedir.do?pane=email"
PROTOCOL_ERROR =
"One.lt has changed its protocols, please upgrade this library first. If that does not work, report this error at http://rubyforge.org/forum/?group_id=2693"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#connect, #connected?, #initialize, #login, #password, #skip_gzip?

Constructor Details

This class inherits a constructor from Contacts::Base

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



9
10
11
# File 'lib/contacts/onelt.rb', line 9

def cookies
  @cookies
end

Instance Method Details

#contactsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/contacts/onelt.rb', line 30

def contacts
  data, resp, self.cookies, forward = get(ADDRESS_BOOK_URL, self.cookies)

  doc = Nokogiri(data)
  int = nil
  
  (doc/"input[name=int]").each do |input|
    int = input['value']
  end

  postdata = "action=LoginUser&pane=contacts&int=#{int}"
  data, resp, self.cookies, forward = post(EMAIL_URL, postdata, self.cookies)

  contacts = []
  page = 1

  until page.nil? 
    url = "http://email.one.lt/index.html?pane=contacts&page-number=%d" % page

    data, resp, self.cookies, forward = get(url, self.cookies)

    doc = Nokogiri(data)

    (doc/'form[name=contacts_items]//table[2]//tr[class=whiteBg]').each do |tr|
      name = tr.at('td[2]').text.strip
      email = tr.at('td[4]').text.strip

      next if email.empty?

      contacts << [ name, email ]
    end

    page+= 1
    page = nil unless data.match("&page-number=#{page}")
  end

  contacts
end

#real_connectObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/contacts/onelt.rb', line 11

def real_connect
  data, resp, self.cookies, forward = get(LOGIN_URL)

  postdata =  "username=%s&password=%s&subsite=pastas" % [
    CGI.escape(username),
    CGI.escape(password)
  ]

  data, resp, self.cookies, forward, old_url = post(LOGIN_URL, postdata, self.cookies)

  if data.index("f-login")
    raise AuthenticationError, "Username and password do not match"
  elsif !forward.nil? && forward.match('brutecheck')
    raise AuthenticationError, "Got captcha"
  elsif forward.nil? || !forward.match('tkn')
    raise ConnectionError, PROTOCOL_ERROR
  end
end