adamhunter-contacts 1.1.16 → 1.1.17

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.
data/lib/contacts/base.rb CHANGED
@@ -8,7 +8,7 @@ require "thread"
8
8
 
9
9
  class Contacts
10
10
  TYPES = {}
11
- VERSION = "1.1.16"
11
+ VERSION = "1.1.17"
12
12
 
13
13
  class Base
14
14
  def initialize(login, password)
@@ -1,93 +1,33 @@
1
- # Use ActiveSupport's version of JSON if available
2
- if Object.const_defined?('ActiveSupport') && ActiveSupport.const_defined?('JSON')
3
- class JSON
4
- def self.parse(i)
5
- ActiveSupport::JSON.decode(i)
6
- end
7
- end
8
- else
9
- require 'json/add/rails'
10
- end
11
-
12
1
  class Contacts
13
2
  class Gmail < Base
14
- URL = "https://mail.google.com/mail/"
15
- LOGIN_URL = "https://www.google.com/accounts/ServiceLoginAuth"
16
- LOGIN_REFERER_URL = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%3Fui%3Dhtml%26zy%3Dl&ltmpl=yj_blanco&ltmplcache=2&hl=en"
17
- CONTACT_LIST_URL = "https://mail.google.com/mail/contacts/data/contacts?thumb=true&show=ALL&enums=true&psort=Name&max=10000&out=js&rf=&jsx=true"
18
- PROTOCOL_ERROR = "Gmail has changed its protocols, please upgrade this library first. If that does not work, dive into the code and submit a patch at http://github.com/cardmagic/contacts"
3
+
4
+ CONTACTS_SCOPE = 'http://www.google.com/m8/feeds/'
5
+ CONTACTS_FEED = CONTACTS_SCOPE + 'contacts/default/full/'
6
+
7
+ def contacts
8
+ return @contacts if @contacts
9
+ real_connect
10
+ end
19
11
 
20
12
  def real_connect
21
- postdata = "ltmpl=yj_blanco"
22
- postdata += "&continue=%s" % CGI.escape(URL)
23
- postdata += "&ltmplcache=2"
24
- postdata += "&service=mail"
25
- postdata += "&rm=false"
26
- postdata += "&ltmpl=yj_blanco"
27
- postdata += "&hl=en"
28
- postdata += "&Email=%s" % CGI.escape(login)
29
- postdata += "&Passwd=%s" % CGI.escape(password)
30
- postdata += "&rmShown=1"
31
- postdata += "&null=Sign+in"
32
-
33
- time = Time.now.to_i
34
- time_past = Time.now.to_i - 8 - rand(12)
35
- cookie = "GMAIL_LOGIN=T#{time_past}/#{time_past}/#{time}"
13
+ @client = GData::Client::Contacts.new
14
+ @client.clientlogin(@login, @password)
36
15
 
37
- data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata, cookie, LOGIN_REFERER_URL) + [LOGIN_URL]
16
+ feed = @client.get(CONTACTS_FEED).to_xml
38
17
 
39
- cookies = remove_cookie("GMAIL_LOGIN", cookies)
40
-
41
- if data.index("Username and password do not match") || data.index("New to Gmail? It's free and easy")
42
- raise AuthenticationError, "Username and password do not match"
43
- elsif data.index("The username or password you entered is incorrect")
44
- raise AuthenticationError, "Username and password do not match"
45
- elsif data.index("Required field must not be blank")
46
- raise AuthenticationError, "Login and password must not be blank"
47
- elsif data.index("errormsg_0_logincaptcha")
48
- raise AuthenticationError, "Captcha error"
49
- elsif data.index("Invalid request")
50
- raise ConnectionError, PROTOCOL_ERROR
51
- elsif cookies == ""
52
- raise ConnectionError, PROTOCOL_ERROR
18
+ @contacts = []
19
+ feed.elements.each('entry') do |entry|
20
+ title = entry.elements['title'].text
21
+ email = nil
22
+ entry.elements.each('gd:email') do |e|
23
+ if e.attribute('primary')
24
+ email = e.attribute('address').value
25
+ end
26
+ end
27
+ @contacts << [title, email] unless email.nil?
53
28
  end
54
-
55
- cookies = remove_cookie("LSID", cookies)
56
- cookies = remove_cookie("GV", cookies)
57
-
58
- @cookies = cookies
29
+ @contacts
59
30
  end
60
31
 
61
- private
62
-
63
- def parse(data, options)
64
- data.gsub!(/^while \(true\); &&&START&&&/, '')
65
- data.gsub!(/ &&&END&&&$/, '')
66
- data.gsub!(/\t/, ' ') # tabs in the note field cause errors with JSON.parse
67
- data.gsub!(/[\t\x00-\x1F]/, " ") # strip control characters
68
-
69
- @contacts = JSON.parse(data)['Body']['Contacts'] || {}
70
-
71
- # Determine in which format to return the data.
72
-
73
- # Return the full JSON Hash.
74
- return @contacts if(options[:details])
75
-
76
- # Default format.
77
- # ['Name', 'Email1', 'Email2', ...]
78
- if @contacts != nil
79
- @contacts = @contacts.delete_if {|c| c["Emails"].nil?}.map do |c|
80
- name, emails = c.values_at "Name", "Emails"
81
- # emails are returned in a form of
82
- # [{"Address"=>"home.email@gmail.com"}, {"Type"=>{"Id"=>"WORK"}, "Address"=>"work.email@gmail.com"}]
83
- emails = emails.collect{|a| a.values_at("Address")}
84
- [name, emails].flatten
85
- end
86
- else
87
- []
88
- end
89
- end
90
32
  end
91
-
92
- TYPES[:gmail] = Gmail
93
33
  end
data/lib/contacts.rb CHANGED
@@ -9,6 +9,4 @@ require 'base'
9
9
  require 'gmail'
10
10
  require 'hotmail'
11
11
  require 'yahoo'
12
- require 'plaxo'
13
-
14
- require 'gdatamail'
12
+ require 'plaxo'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adamhunter-contacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.16
4
+ version: 1.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Carlson
@@ -42,7 +42,6 @@ extra_rdoc_files: []
42
42
 
43
43
  files:
44
44
  - lib/contacts/base.rb
45
- - lib/contacts/gdatamail.rb
46
45
  - lib/contacts/gmail.rb
47
46
  - lib/contacts/hotmail.rb
48
47
  - lib/contacts/plaxo.rb
@@ -1,33 +0,0 @@
1
- class Contacts
2
- class GDataMail < Base
3
-
4
- CONTACTS_SCOPE = 'http://www.google.com/m8/feeds/'
5
- CONTACTS_FEED = CONTACTS_SCOPE + 'contacts/default/full/'
6
-
7
- def contacts
8
- return @contacts if @contacts
9
- real_connect
10
- end
11
-
12
- def real_connect
13
- @client = GData::Client::Contacts.new
14
- @client.clientlogin(@login, @password)
15
-
16
- feed = @client.get(CONTACTS_FEED).to_xml
17
-
18
- @contacts = []
19
- feed.elements.each('entry') do |entry|
20
- title = entry.elements['title'].text
21
- email = nil
22
- entry.elements.each('gd:email') do |e|
23
- if e.attribute('primary')
24
- email = e.attribute('address').value
25
- end
26
- end
27
- @contacts << [title, email] unless email.nil?
28
- end
29
- @contacts
30
- end
31
-
32
- end
33
- end