contacts 1.0.16 → 1.0.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/README +1 -0
- data/lib/contacts/base.rb +8 -3
- data/lib/contacts/gmail.rb +25 -21
- metadata +2 -2
data/README
CHANGED
@@ -39,6 +39,7 @@ See the examples/ directory.
|
|
39
39
|
* Britt Selvitelle from Twitter (mailto:anotherbritt@gmail.com) - http://twitter.com
|
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
|
+
* Glenn Sidney from Glenn Fu (mailto:glenn@glennfu.com) - http://glennfu.com
|
42
43
|
|
43
44
|
This library is released under the terms of the BSD.
|
44
45
|
|
data/lib/contacts/base.rb
CHANGED
@@ -5,10 +5,11 @@ require "uri"
|
|
5
5
|
require "zlib"
|
6
6
|
require "stringio"
|
7
7
|
require "thread"
|
8
|
+
require "erb"
|
8
9
|
|
9
10
|
class Contacts
|
10
11
|
TYPES = {}
|
11
|
-
VERSION = "1.0.
|
12
|
+
VERSION = "1.0.17"
|
12
13
|
|
13
14
|
class Base
|
14
15
|
def initialize(login, password)
|
@@ -19,7 +20,7 @@ class Contacts
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def connect
|
22
|
-
raise AuthenticationError, "Login and password must not be nil, login: #{@login.inspect}, password: #{@password.inspect}" if @login.nil? || @password.nil?
|
23
|
+
raise AuthenticationError, "Login and password must not be nil, login: #{@login.inspect}, password: #{@password.inspect}" if @login.nil? || @login.empty? || @password.nil? || @password.empty?
|
23
24
|
real_connect
|
24
25
|
end
|
25
26
|
|
@@ -92,10 +93,14 @@ class Contacts
|
|
92
93
|
http
|
93
94
|
end
|
94
95
|
|
96
|
+
def cookie_hash_from_string(cookie_string)
|
97
|
+
cookie_string.split(";").map{|i|i.split("=", 2).map{|j|j.strip}}.inject({}){|h,i|h[i[0]]=i[1];h}
|
98
|
+
end
|
99
|
+
|
95
100
|
def parse_cookies(data, existing="")
|
96
101
|
return existing if data.nil?
|
97
102
|
|
98
|
-
cookies = existing
|
103
|
+
cookies = cookie_hash_from_string(existing)
|
99
104
|
|
100
105
|
data.gsub!(/ ?[\w]+=EXPIRED;/,'')
|
101
106
|
data.gsub!(/ ?expires=(.*?, .*?)[;,$]/i, ';')
|
data/lib/contacts/gmail.rb
CHANGED
@@ -9,36 +9,40 @@ else
|
|
9
9
|
require 'json/add/rails'
|
10
10
|
end
|
11
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
|
20
|
+
|
12
21
|
class Contacts
|
13
22
|
class Gmail < Base
|
14
23
|
URL = "https://mail.google.com/mail/"
|
15
24
|
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<mpl=
|
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"
|
17
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"
|
18
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"
|
19
28
|
|
20
29
|
def real_connect
|
21
|
-
postdata =
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
postdata += "&Passwd=%s" % CGI.escape(password)
|
30
|
-
postdata += "&rmShown=1"
|
31
|
-
postdata += "&null=Sign+in"
|
30
|
+
postdata = {
|
31
|
+
"Email" => login,
|
32
|
+
"Passwd" => password,
|
33
|
+
"PersistentCookie" => "yes",
|
34
|
+
"asts" => "",
|
35
|
+
"rmShown" => "1",
|
36
|
+
"signIn" => CGI.escape("Sign in")
|
37
|
+
}
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata, cookie, LOGIN_REFERER_URL) + [LOGIN_URL]
|
38
|
-
|
39
|
-
cookies = remove_cookie("GMAIL_LOGIN", cookies)
|
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"]
|
40
42
|
|
41
|
-
|
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")
|
42
46
|
raise AuthenticationError, "Username and password do not match"
|
43
47
|
elsif data.index("The username or password you entered is incorrect")
|
44
48
|
raise AuthenticationError, "Username and password do not match"
|
@@ -65,7 +69,7 @@ class Contacts
|
|
65
69
|
data.gsub!(/ &&&END&&&$/, '')
|
66
70
|
data.gsub!(/\t/, ' ') # tabs in the note field cause errors with JSON.parse
|
67
71
|
data.gsub!(/[\t\x00-\x1F]/, " ") # strip control characters
|
68
|
-
|
72
|
+
|
69
73
|
@contacts = JSON.parse(data)['Body']['Contacts'] || {}
|
70
74
|
|
71
75
|
# Determine in which format to return the data.
|
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.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Carlson
|
@@ -9,7 +9,7 @@ autorequire: contacts
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|