contacts 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/contacts.rb +2 -1
- data/lib/contacts/base.rb +1 -1
- data/lib/contacts/gmail.rb +11 -7
- data/lib/contacts/hotmail.rb +1 -1
- data/lib/contacts/plaxo.rb +123 -0
- metadata +5 -4
data/lib/contacts.rb
CHANGED
data/lib/contacts/base.rb
CHANGED
data/lib/contacts/gmail.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "json"
|
1
|
+
require "json/add/rails"
|
2
2
|
|
3
3
|
class Contacts
|
4
4
|
class Gmail < Base
|
@@ -53,6 +53,7 @@ class Contacts
|
|
53
53
|
data.gsub!(/^while \(true\); &&&START&&&/, '')
|
54
54
|
data.gsub!(/ &&&END&&&$/, '')
|
55
55
|
data.gsub!(/\t/, ' ') # tabs in the note field cause errors with JSON.parse
|
56
|
+
data.gsub!(/[\t\x00-\x1F]/, " ") # strip control characters
|
56
57
|
|
57
58
|
@contacts = JSON.parse(data)['Body']['Contacts'] || {}
|
58
59
|
|
@@ -63,13 +64,16 @@ class Contacts
|
|
63
64
|
|
64
65
|
# Default format.
|
65
66
|
# ['Name', 'Email1', 'Email2', ...]
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
if @contacts != nil
|
68
|
+
@contacts = @contacts.delete_if {|c| c["Emails"].nil?}.map do |c|
|
69
|
+
name, emails = c.values_at "Name", "Emails"
|
70
|
+
emails = emails.first.values
|
71
|
+
[name, emails].flatten
|
72
|
+
end
|
73
|
+
else
|
74
|
+
[]
|
70
75
|
end
|
71
|
-
end
|
72
|
-
|
76
|
+
end
|
73
77
|
end
|
74
78
|
|
75
79
|
TYPES[:gmail] = Gmail
|
data/lib/contacts/hotmail.rb
CHANGED
@@ -103,7 +103,7 @@ class Contacts
|
|
103
103
|
data = CSV.parse(data.join("\r\n").gsub('"', ''), ';')
|
104
104
|
col_names = data.shift
|
105
105
|
|
106
|
-
@contacts = data.map do |person|
|
106
|
+
@contacts = data.delete_if{|person|person[0].nil?}.map do |person|
|
107
107
|
person = person[0].split(",")
|
108
108
|
next unless (idx = person.index('SMTP'))
|
109
109
|
[[person[1], person[2], person[3]].delete_if{|i|i.empty?}.join(" "), person[idx - 1]] unless person[idx - 1].nil?
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
class Contacts
|
4
|
+
class Plaxo < Base
|
5
|
+
URL = "http://www.plaxo.com/"
|
6
|
+
LOGIN_URL = "https://www.plaxo.com/signin"
|
7
|
+
ADDRESS_BOOK_URL = "http://www.plaxo.com/po3/?module=ab&operation=viewFull&mode=normal"
|
8
|
+
CONTACT_LIST_URL = "http://www.plaxo.com/axis/soap/contact?_action=getContacts&_format=xml"
|
9
|
+
PROTOCOL_ERROR = "Plaxo has changed its protocols, please upgrade this library first. If that does not work, contact lucas@rufy.com with this error"
|
10
|
+
|
11
|
+
def real_connect
|
12
|
+
|
13
|
+
end # real_connect
|
14
|
+
|
15
|
+
def contacts
|
16
|
+
getdata = "&authInfo.authByEmail.email=%s" % CGI.escape(login)
|
17
|
+
getdata += "&authInfo.authByEmail.password=%s" % CGI.escape(password)
|
18
|
+
data, resp, cookies, forward = get(CONTACT_LIST_URL + getdata)
|
19
|
+
|
20
|
+
if resp.code_type != Net::HTTPOK
|
21
|
+
raise ConnectionError, PROTOCOL_ERROR
|
22
|
+
end
|
23
|
+
|
24
|
+
parse data
|
25
|
+
end # contacts
|
26
|
+
|
27
|
+
private
|
28
|
+
def parse(data, options={})
|
29
|
+
doc = REXML::Document.new(data)
|
30
|
+
code = doc.elements['//response/code'].text
|
31
|
+
|
32
|
+
if code == '401'
|
33
|
+
raise AuthenticationError, "Username and password do not match"
|
34
|
+
elsif code == '200'
|
35
|
+
@contacts = []
|
36
|
+
doc.elements.each('//contact') do |cont|
|
37
|
+
name = cont.elements['fullName'].text #rescue nil
|
38
|
+
email = cont.elements['email1'].text #rescue nil
|
39
|
+
@contacts << [name, email]
|
40
|
+
end.compact
|
41
|
+
@contacts
|
42
|
+
else
|
43
|
+
raise ConnectionError, PROTOCOL_ERROR
|
44
|
+
end
|
45
|
+
|
46
|
+
end # parse
|
47
|
+
|
48
|
+
end # Plaxo
|
49
|
+
|
50
|
+
TYPES[:plaxo] = Plaxo
|
51
|
+
|
52
|
+
end # Contacts
|
53
|
+
|
54
|
+
|
55
|
+
# sample contacts responses
|
56
|
+
'
|
57
|
+
Bad email
|
58
|
+
=========
|
59
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
60
|
+
<ns1:GetContactsResponse xmlns:ns1="Plaxo">
|
61
|
+
<response>
|
62
|
+
<code>401</code>
|
63
|
+
<subCode>1</subCode>
|
64
|
+
<message>User not found.</message>
|
65
|
+
</response>
|
66
|
+
</ns1:GetContactsResponse>
|
67
|
+
|
68
|
+
|
69
|
+
Bad password
|
70
|
+
============
|
71
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
72
|
+
<ns1:GetContactsResponse xmlns:ns1="Plaxo">
|
73
|
+
<response>
|
74
|
+
<code>401</code>
|
75
|
+
<subCode>4</subCode>
|
76
|
+
<message>Bad password or security token.</message>
|
77
|
+
</response>
|
78
|
+
</ns1:GetContactsResponse>
|
79
|
+
|
80
|
+
|
81
|
+
Success
|
82
|
+
=======
|
83
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
84
|
+
<ns1:GetContactsResponse xmlns:ns1="Plaxo">
|
85
|
+
|
86
|
+
<response>
|
87
|
+
<code>200</code>
|
88
|
+
<message>OK</message>
|
89
|
+
<userId>77311236242</userId>
|
90
|
+
</response>
|
91
|
+
|
92
|
+
<contacts>
|
93
|
+
|
94
|
+
<contact>
|
95
|
+
<itemId>61312569</itemId>
|
96
|
+
<displayName>Joe Blow1</displayName>
|
97
|
+
<fullName>Joe Blow1</fullName>
|
98
|
+
<firstName>Joe</firstName>
|
99
|
+
<lastName>Blow1</lastName>
|
100
|
+
<homeEmail1>joeblow1@mailinator.com</homeEmail1>
|
101
|
+
<email1>joeblow1@mailinator.com</email1>
|
102
|
+
<folderId>5291351</folderId>
|
103
|
+
</contact>
|
104
|
+
|
105
|
+
<contact>
|
106
|
+
<itemId>61313159</itemId>
|
107
|
+
<displayName>Joe Blow2</displayName>
|
108
|
+
<fullName>Joe Blow2</fullName>
|
109
|
+
<firstName>Joe</firstName>
|
110
|
+
<lastName>Blow2</lastName>
|
111
|
+
<homeEmail1>joeblow2@mailinator.com</homeEmail1>
|
112
|
+
<email1>joeblow2@mailinator.com</email1>
|
113
|
+
<folderId>5291351</folderId>
|
114
|
+
</contact>
|
115
|
+
|
116
|
+
</contacts>
|
117
|
+
|
118
|
+
<totalCount>2</totalCount>
|
119
|
+
<editCounter>3</editCounter>
|
120
|
+
|
121
|
+
</ns1:GetContactsResponse>
|
122
|
+
|
123
|
+
'
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contacts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
platform:
|
4
|
+
version: 1.0.11
|
5
|
+
platform: ""
|
6
6
|
authors:
|
7
7
|
- Lucas Carlson
|
8
8
|
autorequire: contacts
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-03-07 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/contacts/base.rb
|
35
35
|
- lib/contacts/gmail.rb
|
36
36
|
- lib/contacts/hotmail.rb
|
37
|
+
- lib/contacts/plaxo.rb
|
37
38
|
- lib/contacts/yahoo.rb
|
38
39
|
- lib/contacts.rb
|
39
40
|
- LICENSE
|
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
63
|
requirements:
|
63
64
|
- A json parser
|
64
65
|
rubyforge_project:
|
65
|
-
rubygems_version:
|
66
|
+
rubygems_version: 0.9.5
|
66
67
|
signing_key:
|
67
68
|
specification_version: 2
|
68
69
|
summary: Ridiculously easy contact list information from various providers including Yahoo, Gmail, and Hotmail
|