Class: Contacts::Seznam

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

Constant Summary collapse

DETECTED_DOMAINS =
[ /seznam\.cz/i, /email\.cz/i, /post\.cz/i, /spoluzaci\.cz/i, /stream\.cz/i, /firmy\.cz/i, ]
LOGIN_URL =
"https://login.szn.cz/loginProcess"
ADDRESS_BOOK_URL =
"http://email.seznam.cz/abookCsvExport?sessionId=&charset=utf-8&eof=windows&export=nameLast&export=nameFirst&export=nick&export=email"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

This class inherits a constructor from Contacts::Base

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



7
8
9
# File 'lib/contacts/seznam.rb', line 7

def cookies
  @cookies
end

Instance Method Details

#contactsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/contacts/seznam.rb', line 45

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

  CSV.parse(data, { :col_sep => ';' }) do |row|
    last_name, first_name, unknown, email = row
    
    name = "#{first_name} #{last_name}".strip
    email.strip!

    @contacts << [name, email] unless email.empty?
  end
   
  @contacts
end

#real_connectObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/contacts/seznam.rb', line 9

def real_connect
  postdata =  "disableSSL=0&domain=%s&forceRelogin=0&forceSSL=0&lang=cz&loginType=seznam&returnURL=%s&serviceId=email&username=%s&password=%s" % [
    CGI.escape(domain),
    CGI.escape('http://email.seznam.cz/ticket'),
    CGI.escape(username),
    CGI.escape(password)
  ]

  data, resp, self.cookies, forward = post(LOGIN_URL, postdata, "")
  
  if !forward.nil? && forward.match("badLogin")
    raise AuthenticationError, "Username and password do not match"
  end

  doc = Nokogiri(data)

  a = doc.at('body>a')
  forward = a['href'].to_s

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

  doc = Nokogiri(data)

  a = doc.at('body>a')
  forward = a['href'].to_s

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

  doc = Nokogiri(data)

  a = doc.at('body>a')
  forward = a['href'].to_s

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

#skip_gzip?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/contacts/seznam.rb', line 62

def skip_gzip?
  false
end