contacts_19 1.2.5 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,4 +9,4 @@ require 'hotmail'
9
9
  require 'yahoo'
10
10
  require 'plaxo'
11
11
  require 'aol'
12
- require 'mailru'
12
+ #require 'mailru'
@@ -9,7 +9,7 @@ require "erb"
9
9
 
10
10
  class Contacts
11
11
  TYPES = {}
12
- VERSION = "1.2.4"
12
+ VERSION = "1.2.6"
13
13
 
14
14
  class Base
15
15
  def initialize(login, password, options={})
@@ -0,0 +1,67 @@
1
+ class Contacts
2
+ require 'csv'
3
+ class Mailru < Base
4
+ LOGIN_URL = "https://auth.mail.ru/cgi-bin/auth"
5
+ ADDRESS_BOOK_URL = "http://win.mail.ru/cgi-bin/abexport/addressbook.csv"
6
+
7
+ attr_accessor :cookies
8
+
9
+ def real_connect
10
+ username = login
11
+
12
+ postdata = "Login=%s&Domain=%s&Password=%s" % [
13
+ CGI.escape(username),
14
+ CGI.escape(domain_param(username)),
15
+ CGI.escape(password)
16
+ ]
17
+
18
+ data, resp, self.cookies, forward = post(LOGIN_URL, postdata, "")
19
+
20
+ if data.index("fail=1")
21
+ raise AuthenticationError, "Username and password do not match"
22
+ elsif cookies == "" or data == ""
23
+ raise ConnectionError, PROTOCOL_ERROR
24
+ end
25
+
26
+ data, resp, cookies, forward = get(login_token_link(data), login_cookies.join(';'))
27
+ end
28
+
29
+ def contacts
30
+ postdata = "confirm=1&abtype=6"
31
+ data, resp, cookies, forward = post(ADDRESS_BOOK_URL, postdata, login_cookies.join(';'))
32
+
33
+ @contacts = []
34
+ CSV.parse(data) do |row|
35
+ @contacts << [row[0], row[4]] unless header_row?(row)
36
+ end
37
+
38
+ @contacts
39
+ end
40
+
41
+ def skip_gzip?
42
+ true
43
+ end
44
+
45
+ private
46
+ def login_token_link(data)
47
+ data.match(/url=(.+)\">/)[1]
48
+ end
49
+
50
+ def login_cookies
51
+ self.cookies.split(';').collect{|c| c if (c.include?('t=') or c.include?('Mpop='))}.compact.collect{|c| c.strip}
52
+ end
53
+
54
+ def header_row?(row)
55
+ row[0] == 'AB-Name'
56
+ end
57
+
58
+ def domain_param(login)
59
+ login.include?('@') ?
60
+ login.match(/.+@(.+)/)[1] :
61
+ 'mail.ru'
62
+ end
63
+
64
+ end
65
+
66
+ TYPES[:mailru] = Mailru
67
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: contacts_19
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.2.5
5
+ version: 1.2.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Lucas Carlson
@@ -57,6 +57,7 @@ files:
57
57
  - lib/contacts/hotmail.rb
58
58
  - lib/contacts/plaxo.rb
59
59
  - lib/contacts/yahoo.rb
60
+ - lib/contacts/mailru.rb
60
61
  has_rdoc: true
61
62
  homepage: http://github.com/bimbiero/contacts
62
63
  licenses: []