adamhunter-contacts 1.1.16 → 1.1.17
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/contacts/base.rb +1 -1
- data/lib/contacts/gmail.rb +22 -82
- data/lib/contacts.rb +1 -3
- metadata +1 -2
- data/lib/contacts/gdatamail.rb +0 -33
data/lib/contacts/base.rb
CHANGED
data/lib/contacts/gmail.rb
CHANGED
@@ -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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
22
|
-
|
23
|
-
postdata += "<mplcache=2"
|
24
|
-
postdata += "&service=mail"
|
25
|
-
postdata += "&rm=false"
|
26
|
-
postdata += "<mpl=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
|
-
|
16
|
+
feed = @client.get(CONTACTS_FEED).to_xml
|
38
17
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
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.
|
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
|
data/lib/contacts/gdatamail.rb
DELETED
@@ -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
|