contacts 1.0.19 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -3
- data/Rakefile +3 -2
- data/lib/contacts.rb +3 -1
- data/lib/contacts/base.rb +1 -1
- data/lib/contacts/gmail.rb +23 -85
- data/lib/contacts/json_picker.rb +16 -0
- data/lib/contacts/yahoo.rb +2 -13
- metadata +12 -1
data/README
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
== Welcome to Contacts
|
2
2
|
|
3
|
-
Contacts is a universal interface to grab contact list information from various providers including Hotmail, Gmail and Yahoo.
|
3
|
+
Contacts is a universal interface to grab contact list information from various providers including Hotmail, AOL, Gmail and Yahoo.
|
4
4
|
|
5
5
|
== Download
|
6
6
|
|
7
7
|
* gem install contacts
|
8
|
-
* http://
|
9
|
-
*
|
8
|
+
* http://github.com/cardmagic/contacts
|
9
|
+
* git clone git://github.com/cardmagic/contacts.git
|
10
10
|
|
11
11
|
== Background
|
12
12
|
|
@@ -40,6 +40,7 @@ See the examples/ directory.
|
|
40
40
|
* Tony Targonski from GigPark (mailto:tony@gigpark.com) - http://gigpark.com
|
41
41
|
* Waheed Barghouthi from Watwet (mailto:waheed.barghouthi@gmail.com) - http://watwet.com
|
42
42
|
* Glenn Sidney from Glenn Fu (mailto:glenn@glennfu.com) - http://glennfu.com
|
43
|
+
* Brian McQuay from Onomojo (mailto:brian@onomojo.com) - http://onomojo.com
|
43
44
|
|
44
45
|
This library is released under the terms of the BSD.
|
45
46
|
|
data/Rakefile
CHANGED
@@ -43,7 +43,7 @@ spec = Gem::Specification.new do |s|
|
|
43
43
|
|
44
44
|
#### Basic information.
|
45
45
|
|
46
|
-
s.name = 'contacts'
|
46
|
+
s.name = 'adamhunter-contacts'
|
47
47
|
s.version = PKG_VERSION
|
48
48
|
s.summary = <<-EOF
|
49
49
|
Ridiculously easy contact list information from various providers including Yahoo, Gmail, and Hotmail
|
@@ -62,7 +62,8 @@ spec = Gem::Specification.new do |s|
|
|
62
62
|
s.autorequire = 'contacts'
|
63
63
|
|
64
64
|
s.add_dependency('json', '>= 0.4.1')
|
65
|
-
s.
|
65
|
+
s.add_dependency('gdata', '= 1.1.1')
|
66
|
+
s.requirements << "A json parser, the gdata ruby gem"
|
66
67
|
|
67
68
|
#### Documentation and testing.
|
68
69
|
|
data/lib/contacts.rb
CHANGED
data/lib/contacts/base.rb
CHANGED
data/lib/contacts/gmail.rb
CHANGED
@@ -1,97 +1,35 @@
|
|
1
|
-
|
2
|
-
if Object.const_defined?('ActiveSupport') && ActiveSupport.const_defined?('JSON') && ActiveSupport::JSON.is_a?(Class)
|
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
|
-
class Hash
|
13
|
-
def to_query_string
|
14
|
-
u = ERB::Util.method(:u)
|
15
|
-
map { |k, v|
|
16
|
-
u.call(k) + "=" + u.call(v)
|
17
|
-
}.join("&")
|
18
|
-
end
|
19
|
-
end
|
1
|
+
require 'gdata'
|
20
2
|
|
21
3
|
class Contacts
|
22
4
|
class Gmail < Base
|
23
|
-
URL = "https://mail.google.com/mail/"
|
24
|
-
LOGIN_URL = "https://www.google.com/accounts/ServiceLoginAuth"
|
25
|
-
LOGIN_REFERER_URL = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=zpwhtygjntrz&scc=1<mpl=default<mplcache=2"
|
26
|
-
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"
|
27
|
-
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"
|
28
5
|
|
29
|
-
|
30
|
-
|
31
|
-
"Email" => login,
|
32
|
-
"Passwd" => password,
|
33
|
-
"PersistentCookie" => "yes",
|
34
|
-
"asts" => "",
|
35
|
-
"rmShown" => "1",
|
36
|
-
"signIn" => CGI.escape("Sign in")
|
37
|
-
}
|
38
|
-
|
39
|
-
# Get this cookie and stick it in the form to confirm to Google that your cookies work
|
40
|
-
data, resp, cookies, forward = get(LOGIN_REFERER_URL)
|
41
|
-
postdata["GALX"] = cookie_hash_from_string(cookies)["GALX"]
|
42
|
-
|
43
|
-
data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata.to_query_string, cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL]
|
44
|
-
|
45
|
-
if data.index("Username and password do not match")
|
46
|
-
raise AuthenticationError, "Username and password do not match"
|
47
|
-
elsif data.index("The username or password you entered is incorrect")
|
48
|
-
raise AuthenticationError, "Username and password do not match"
|
49
|
-
elsif data.index("Required field must not be blank")
|
50
|
-
raise AuthenticationError, "Login and password must not be blank"
|
51
|
-
elsif data.index("errormsg_0_logincaptcha")
|
52
|
-
raise AuthenticationError, "Captcha error"
|
53
|
-
elsif data.index("Invalid request")
|
54
|
-
raise ConnectionError, PROTOCOL_ERROR
|
55
|
-
elsif cookies == ""
|
56
|
-
raise ConnectionError, PROTOCOL_ERROR
|
57
|
-
end
|
58
|
-
|
59
|
-
cookies = remove_cookie("LSID", cookies)
|
60
|
-
cookies = remove_cookie("GV", cookies)
|
61
|
-
|
62
|
-
@cookies = cookies
|
63
|
-
end
|
6
|
+
CONTACTS_SCOPE = 'http://www.google.com/m8/feeds/'
|
7
|
+
CONTACTS_FEED = CONTACTS_SCOPE + 'contacts/default/full/?max-results=1000'
|
64
8
|
|
65
|
-
|
9
|
+
def contacts
|
10
|
+
return @contacts if @contacts
|
11
|
+
end
|
66
12
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
-
data.gsub!(/\t/, ' ') # tabs in the note field cause errors with JSON.parse
|
71
|
-
data.gsub!(/[\t\x00-\x1F]/, " ") # strip control characters
|
13
|
+
def real_connect
|
14
|
+
@client = GData::Client::Contacts.new
|
15
|
+
@client.clientlogin(@login, @password)
|
72
16
|
|
73
|
-
|
74
|
-
|
75
|
-
# Determine in which format to return the data.
|
17
|
+
feed = @client.get(CONTACTS_FEED).to_xml
|
76
18
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
# ['Name', 'Email1', 'Email2', ...]
|
82
|
-
if @contacts != nil
|
83
|
-
@contacts = @contacts.select {|c| !c["Emails"].nil?}.map do |c|
|
84
|
-
name, emails = c.values_at "Name", "Emails"
|
85
|
-
# emails are returned in a form of
|
86
|
-
# [{"Address"=>"home.email@gmail.com"}, {"Type"=>{"Id"=>"WORK"}, "Address"=>"work.email@gmail.com"}]
|
87
|
-
emails = emails.collect{|a| a.values_at("Address")}
|
88
|
-
[name, emails].flatten
|
19
|
+
@contacts = feed.elements.to_a('entry').collect do |entry|
|
20
|
+
title, email = entry.elements['title'].text, nil
|
21
|
+
entry.elements.each('gd:email') do |e|
|
22
|
+
email = e.attribute('address').value if e.attribute('primary')
|
89
23
|
end
|
90
|
-
|
91
|
-
[]
|
24
|
+
[title, email] unless email.nil?
|
92
25
|
end
|
93
|
-
|
26
|
+
@contacts.compact!
|
27
|
+
rescue GData::Client::AuthorizationError => e
|
28
|
+
raise AuthenticationError, "Username or password are incorrect"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
TYPES[:gmail] = Gmail
|
94
34
|
end
|
95
|
-
|
96
|
-
TYPES[:gmail] = Gmail
|
97
35
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
if !Object.const_defined?('ActiveSupport')
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
|
5
|
+
class Contacts
|
6
|
+
def self.parse_json( string )
|
7
|
+
if Object.const_defined?('ActiveSupport') and
|
8
|
+
ActiveSupport.const_defined?('JSON')
|
9
|
+
ActiveSupport::JSON.decode( string )
|
10
|
+
elsif Object.const_defined?('JSON')
|
11
|
+
JSON.parse( string )
|
12
|
+
else
|
13
|
+
raise 'Contacts requires JSON or Rails (with ActiveSupport::JSON)'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/contacts/yahoo.rb
CHANGED
@@ -1,14 +1,3 @@
|
|
1
|
-
# Use ActiveSupport's version of JSON if available
|
2
|
-
if Object.const_defined?('ActiveSupport') && ActiveSupport.const_defined?('JSON') && ActiveSupport::JSON.is_a?(Class)
|
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 Yahoo < Base
|
14
3
|
URL = "http://mail.yahoo.com/"
|
@@ -106,9 +95,9 @@ class Contacts
|
|
106
95
|
def parse(data, options={})
|
107
96
|
@contacts ||= []
|
108
97
|
if data =~ /var InitialContacts = (\[.*?\])/
|
109
|
-
@contacts +=
|
98
|
+
@contacts += Contacts.parse_json($1).select{|contact|!contact["email"].to_s.empty?}.map{|contact|[contact["contactName"], contact["email"]]}
|
110
99
|
elsif data =~ /^\{"response":/
|
111
|
-
@contacts +=
|
100
|
+
@contacts += Contacts.parse_json(data)["response"]["ResultSet"]["Contacts"].to_a.select{|contact|!contact["email"].to_s.empty?}.map{|contact|[contact["contactName"], contact["email"]]}
|
112
101
|
else
|
113
102
|
@contacts
|
114
103
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contacts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Carlson
|
@@ -22,6 +22,16 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.1.1
|
24
24
|
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: gdata
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.1
|
34
|
+
version:
|
25
35
|
description: A universal interface to grab contact list information from various providers including Yahoo, Gmail, Hotmail, and Plaxo.
|
26
36
|
email: lucas@rufy.com
|
27
37
|
executables: []
|
@@ -37,6 +47,7 @@ files:
|
|
37
47
|
- examples/grab_contacts.rb
|
38
48
|
- lib/contacts.rb
|
39
49
|
- lib/contacts/base.rb
|
50
|
+
- lib/contacts/json_picker.rb
|
40
51
|
- lib/contacts/gmail.rb
|
41
52
|
- lib/contacts/aol.rb
|
42
53
|
- lib/contacts/hotmail.rb
|