erc-contacts 0.3.0

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.
@@ -0,0 +1,89 @@
1
+ require 'contacts'
2
+ require 'json'
3
+
4
+ module Contacts
5
+ class Yahoo < OAuthConsumer
6
+ CONSUMER_OPTIONS = Util.frozen_hash(
7
+ :site => "https://api.login.yahoo.com",
8
+ :request_token_path => "/oauth/v2/get_request_token",
9
+ :access_token_path => "/oauth/v2/get_token",
10
+ :authorize_path => "/oauth/v2/request_auth"
11
+ )
12
+
13
+ REQUEST_TOKEN_PARAMS = {}
14
+
15
+ def initialize(options={})
16
+ super(CONSUMER_OPTIONS, REQUEST_TOKEN_PARAMS)
17
+ end
18
+
19
+ def initialize_serialized(data)
20
+ super
21
+ if @access_token && (guid = data['guid'])
22
+ @access_token.params['xoauth_yahoo_guid'] = guid
23
+ end
24
+ end
25
+
26
+ def contacts(options={})
27
+ return nil if @access_token.nil?
28
+ params = {:limit => 200}.update(options)
29
+ yahoo_params = translate_contacts_options(params).merge('format' => 'json')
30
+ guid = @access_token.params['xoauth_yahoo_guid']
31
+ uri = URI.parse("http://social.yahooapis.com/v1/user/#{guid}/contacts")
32
+ uri.query = params_to_query(yahoo_params)
33
+ begin
34
+ response = @access_token.get(uri.to_s)
35
+ rescue OAuth::Unauthorized => error
36
+ # Token probably expired.
37
+ @error = error.message
38
+ return nil
39
+ end
40
+ parse_contacts(response.body)
41
+ end
42
+
43
+ def serializable_data
44
+ data = super
45
+ data['guid'] = @access_token.params['xoauth_yahoo_guid'] if @access_token
46
+ data
47
+ end
48
+
49
+ private
50
+
51
+ def translate_contacts_options(options)
52
+ params = {}
53
+ value = options[:limit] and
54
+ params['count'] = value
55
+ value = options[:offset] and
56
+ params['start'] = value
57
+ params['sort'] = (value = options[:descending]) ? 'desc' : 'asc'
58
+ params['sort-fields'] = 'email'
59
+ # :updated_after not supported. Yahoo! appears to support
60
+ # filtering by updated, but does not support a date comparison
61
+ # operation. Lame. TODO: filter unwanted records out of the
62
+ # response ourselves.
63
+ params
64
+ end
65
+
66
+ def parse_contacts(text)
67
+ result = JSON.parse(text)
68
+ if result['contacts']
69
+ result['contacts']['contact'].map do |contact_object|
70
+ name, emails = nil, []
71
+ contact_object['fields'].each do |field_object|
72
+ case field_object['type']
73
+ when 'nickname'
74
+ name = field_object['value']
75
+ when 'name'
76
+ name ||= field_object['value'].values_at('givenName', 'familyName').compact.join(' ')
77
+ when 'email'
78
+ emails << field_object['value']
79
+ end
80
+ end
81
+ next if emails.empty?
82
+ Contact.new(emails, name)
83
+ end.compact
84
+ else
85
+ []
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,15 @@
1
+ test:
2
+ windows_live:
3
+ application_id: app_id
4
+ secret_key: your_secret
5
+ privacy_policy_url: http://yourserver.com/you_policy_url
6
+ return_url: 'http://phaseiii.mine.nu:3000/friends/load_contacts'
7
+ yahoo:
8
+ consumer_key: your_key
9
+ consumer_secret: your_secret_key
10
+ return_url: 'http://phaseiii.mine.nu:3000/friends/load_contacts'
11
+ google:
12
+ consumer_key: your_key
13
+ consumer_secret: your_secret_key
14
+ return_url: 'http://phaseiii.mine.nu:3000/friends/load_contacts'
15
+
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'contacts'
3
+
4
+ describe Contacts::Contact do
5
+ describe 'instance' do
6
+ before do
7
+ @contact = Contacts::Contact.new('max@example.com', 'Max Power', 'maxpower')
8
+ end
9
+
10
+ it "should have email" do
11
+ @contact.email.should == 'max@example.com'
12
+ end
13
+
14
+ it "should have name" do
15
+ @contact.name.should == 'Max Power'
16
+ end
17
+
18
+ it "should support multiple emails" do
19
+ @contact.emails << 'maxpower@example.com'
20
+ @contact.email.should == 'max@example.com'
21
+ @contact.emails.should == ['max@example.com', 'maxpower@example.com']
22
+ end
23
+
24
+ it "should have username" do
25
+ @contact.username.should == 'maxpower'
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,76 @@
1
+ <feed xmlns='http://www.w3.org/2005/Atom'
2
+ xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/'
3
+ xmlns:gContact='http://schemas.google.com/contact/2008'
4
+ xmlns:batch='http://schemas.google.com/gdata/batch'
5
+ xmlns:gd='http://schemas.google.com/g/2005'
6
+ gd:etag='W/"CUMBRHo_fip7ImA9WxRbGU0."'>
7
+ <id>liz@gmail.com</id>
8
+ <updated>2008-12-10T10:04:15.446Z</updated>
9
+ <category scheme='http://schemas.google.com/g/2005#kind'
10
+ term='http://schemas.google.com/contact/2008#contact' />
11
+ <title>Elizabeth Bennet's Contacts</title>
12
+ <link rel='http://schemas.google.com/g/2005#feed'
13
+ type='application/atom+xml'
14
+ href='https://www.google.com/m8/feeds/contacts/liz%40gmail.com/full' />
15
+ <link rel='http://schemas.google.com/g/2005#post'
16
+ type='application/atom+xml'
17
+ href='https://www.google.com/m8/feeds/contacts/liz%40gmail.com/full' />
18
+ <link rel='http://schemas.google.com/g/2005#batch'
19
+ type='application/atom+xml'
20
+ href='https://www.google.com/m8/feeds/contacts/liz%40gmail.com/full/batch' />
21
+ <link rel='self' type='application/atom+xml'
22
+ href='https://www.google.com/m8/feeds/contacts/liz%40gmail.com/full?max-results=25' />
23
+ <author>
24
+ <name>Elizabeth Bennet</name>
25
+ <email>liz@gmail.com</email>
26
+ </author>
27
+ <generator version='1.0' uri='http://www.google.com/m8/feeds'>
28
+ Contacts
29
+ </generator>
30
+ <openSearch:totalResults>1</openSearch:totalResults>
31
+ <openSearch:startIndex>1</openSearch:startIndex>
32
+ <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
33
+
34
+ <entry gd:etag='"Qn04eTVSLyp7ImA9WxRbGEUORAQ."'>
35
+ <id>
36
+ http://www.google.com/m8/feeds/contacts/liz%40gmail.com/base/c9012de
37
+ </id>
38
+ <updated>2008-12-10T04:45:03.331Z</updated>
39
+ <app:edited xmlns:app='http://www.w3.org/2007/app'>2008-12-10T04:45:03.331Z</app:edited>
40
+ <category scheme='http://schemas.google.com/g/2005#kind'
41
+ term='http://schemas.google.com/contact/2008#contact' />
42
+ <title>Fitzwilliam</title>
43
+ <link rel='http://schemas.google.com/contacts/2008/rel#photo' type='image/*'
44
+ href='https://www.google.com/m8/feeds/photos/media/liz%40gmail.com/c9012de'
45
+ gd:etag='"KTlcZWs1bCp7ImBBPV43VUV4LXEZCXERZAc."' />
46
+ <link rel='self' type='application/atom+xml'
47
+ href='https://www.google.com/m8/feeds/contacts/liz%40gmail.com/full/c9012de' />
48
+ <link rel='edit' type='application/atom+xml'
49
+ href='https://www.google.com/m8/feeds/contacts/liz%40gmail.com/full/c9012de' />
50
+ <gd:phoneNumber rel='http://schemas.google.com/g/2005#home'
51
+ primary='true'>
52
+ 456
53
+ </gd:phoneNumber>
54
+ <gd:email rel='http://schemas.google.com/g/2005#work'
55
+ address='liz@gmail.com' />
56
+ <gd:extendedProperty name='pet' value='hamster' />
57
+ <gContact:groupMembershipInfo deleted='false'
58
+ href='http://www.google.com/m8/feeds/groups/liz%40gmail.com/base/270f' />
59
+ </entry>
60
+
61
+ <entry>
62
+ <title>Poor Jack</title>
63
+ <content>Poor Jack doesn't have an e-mail address</content>
64
+ </entry>
65
+
66
+ <entry>
67
+ <title>William Paginate</title>
68
+ <gd:email address='will_paginate@googlegroups.com' />
69
+ <gd:email address='will_paginate_also@googlegroups.com' />
70
+ </entry>
71
+
72
+ <entry>
73
+ <content>This guy doesn't have a name</content>
74
+ <gd:email address='anonymous@example.com' />
75
+ </entry>
76
+ </feed>
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <LiveContacts>
3
+ <Owner>
4
+ <WindowsLiveID>hugo@hotmail.com</WindowsLiveID>
5
+ </Owner>
6
+ <Contacts>
7
+ <Contact>
8
+ <Profiles>
9
+ <Personal />
10
+ </Profiles>
11
+ <PreferredEmail>froz@gmail.com</PreferredEmail>
12
+ </Contact>
13
+ <Contact>
14
+ <Profiles>
15
+ <Personal>
16
+ <FirstName>Rafael</FirstName>
17
+ <LastName>Timbo</LastName>
18
+ </Personal>
19
+ </Profiles>
20
+ <PreferredEmail>timbo@hotmail.com</PreferredEmail>
21
+ </Contact>
22
+ <Contact>
23
+ <Profiles>
24
+ <Personal />
25
+ </Profiles>
26
+ <PreferredEmail>betinho@hotmail.com</PreferredEmail>
27
+ </Contact>
28
+ </Contacts>
29
+ </LiveContacts>
@@ -0,0 +1,241 @@
1
+ {
2
+ "contacts":
3
+ {
4
+ "start": 0,
5
+ "count": 2,
6
+ "total": 2,
7
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contacts",
8
+ "contact":
9
+ [
10
+ {
11
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/2",
12
+ "created": "2008-08-28T01:07:55Z",
13
+ "updated": "2008-08-28T01:07:55Z",
14
+ "isConnection": false,
15
+ "id": 2,
16
+
17
+ "fields":
18
+ [
19
+ {
20
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/2\/nickname\/1",
21
+ "created": "2008-08-28T01:07:55Z",
22
+ "updated": "2008-08-28T01:07:55Z",
23
+ "id": 1,
24
+ "type": "nickname",
25
+ "value": "HeadClown",
26
+ "flags": []
27
+ },
28
+ {
29
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/email\/3",
30
+ "created": "2008-09-25T22:49:06Z",
31
+ "updated": "2008-09-25T22:49:06Z",
32
+ "id": 14,
33
+ "type": "email",
34
+ "value": "HeadClown@example.com",
35
+ "flags": []
36
+ },
37
+ {
38
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/2\/address\/6",
39
+ "created": "2008-08-28T01:07:55Z",
40
+ "updated": "2008-08-28T01:07:55Z",
41
+ "id": 6,
42
+ "type": "address",
43
+ "value":
44
+ {
45
+ "street": "1234",
46
+ "city": "NowheresVille",
47
+ "stateOrProvince": "ca",
48
+ "postalCode": "91234",
49
+ "country": "usa"
50
+ },
51
+ "flags":
52
+ [
53
+ "HOME"
54
+ ]
55
+ }
56
+ ],
57
+ "categories":
58
+ [
59
+ {
60
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/2\/category\/Clowns",
61
+ "created": "2008-08-28T01:05:17Z",
62
+ "updated": "2008-09-25T22:49:06Z",
63
+ "id": 1,
64
+ "name": "Clowns"
65
+ }
66
+ ]
67
+ },
68
+ {
69
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5",
70
+ "created": "2008-09-25T22:49:06Z",
71
+ "updated": "2008-09-25T22:49:06Z",
72
+ "isConnection": false,
73
+ "id": 5,
74
+ "fields":
75
+ [
76
+ {
77
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/nickname\/14",
78
+ "created": "2008-09-25T22:49:06Z",
79
+ "updated": "2008-09-25T22:49:06Z",
80
+ "id": 14,
81
+ "type": "nickname",
82
+ "value": "StarGirl",
83
+ "flags": []
84
+ },
85
+ {
86
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/email\/14",
87
+ "created": "2008-09-25T22:49:06Z",
88
+ "updated": "2008-09-25T22:49:06Z",
89
+ "id": 14,
90
+ "type": "email",
91
+ "value": "StarGirl@example.com",
92
+ "flags": []
93
+ },
94
+ {
95
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/email\/15",
96
+ "created": "2008-09-25T22:49:06Z",
97
+ "updated": "2008-09-25T22:49:06Z",
98
+ "id": 14,
99
+ "type": "email",
100
+ "value": "StarGirl1@example.com",
101
+ "flags": []
102
+ },
103
+ {
104
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/address\/21",
105
+ "created": "2008-09-25T22:49:06Z",
106
+ "updated": "2008-09-25T22:49:06Z",
107
+ "id": 21,
108
+ "type": "address",
109
+ "value":
110
+ {
111
+ "street": "0123",
112
+ "city": "NowheresVille",
113
+ "stateOrProvince": "Ca",
114
+ "postalCode": "90012",
115
+ "country": "USA"
116
+ },
117
+ "flags":
118
+ [
119
+ "HOME"
120
+ ]
121
+ }
122
+ ],
123
+ "categories":
124
+ [
125
+ {
126
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/category\/Clowns",
127
+ "created": "2008-08-28T01:05:17Z",
128
+ "updated": "2008-09-25T22:49:06Z",
129
+ "id": 1,
130
+ "name": "Clowns"
131
+ }
132
+ ]
133
+ },
134
+ {
135
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5",
136
+ "created": "2008-09-25T22:49:06Z",
137
+ "updated": "2008-09-25T22:49:06Z",
138
+ "isConnection": false,
139
+ "id": 5,
140
+ "fields":
141
+ [
142
+ {
143
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/nickname\/14",
144
+ "created": "2008-09-25T22:49:06Z",
145
+ "updated": "2008-09-25T22:49:06Z",
146
+ "id": 14,
147
+ "type": "nickname",
148
+ "value": "MoonGirl",
149
+ "flags": []
150
+ },
151
+ {
152
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/email\/14",
153
+ "created": "2008-09-25T22:49:06Z",
154
+ "updated": "2008-09-25T22:49:06Z",
155
+ "id": 14,
156
+ "type": "email",
157
+ "value": "MoonGirl@example.com",
158
+ "flags": []
159
+ },
160
+ {
161
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/address\/21",
162
+ "created": "2008-09-25T22:49:06Z",
163
+ "updated": "2008-09-25T22:49:06Z",
164
+ "id": 21,
165
+ "type": "address",
166
+ "value":
167
+ {
168
+ "street": "0123",
169
+ "city": "NowheresVille",
170
+ "stateOrProvince": "Ca",
171
+ "postalCode": "90012",
172
+ "country": "USA"
173
+ },
174
+ "flags":
175
+ [
176
+ "HOME"
177
+ ]
178
+ }
179
+ ],
180
+ "categories":
181
+ [
182
+ {
183
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/category\/Clowns",
184
+ "created": "2008-08-28T01:05:17Z",
185
+ "updated": "2008-09-25T22:49:06Z",
186
+ "id": 1,
187
+ "name": "Clowns"
188
+ }
189
+ ]
190
+ } ,
191
+ {
192
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5",
193
+ "created": "2008-09-25T22:49:06Z",
194
+ "updated": "2008-09-25T22:49:06Z",
195
+ "isConnection": false,
196
+ "id": 5,
197
+ "fields":
198
+ [
199
+ {
200
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/nickname\/14",
201
+ "created": "2008-09-25T22:49:06Z",
202
+ "updated": "2008-09-25T22:49:06Z",
203
+ "id": 14,
204
+ "type": "nickname",
205
+ "value": "NoEmailGirl",
206
+ "flags": []
207
+ },
208
+ {
209
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/address\/21",
210
+ "created": "2008-09-25T22:49:06Z",
211
+ "updated": "2008-09-25T22:49:06Z",
212
+ "id": 21,
213
+ "type": "address",
214
+ "value":
215
+ {
216
+ "street": "0123",
217
+ "city": "NowheresVille",
218
+ "stateOrProvince": "Ca",
219
+ "postalCode": "90012",
220
+ "country": "USA"
221
+ },
222
+ "flags":
223
+ [
224
+ "HOME"
225
+ ]
226
+ }
227
+ ],
228
+ "categories":
229
+ [
230
+ {
231
+ "uri": "http:\/\/social.yahooapis.com\/v1\/user\/XYZUHL23NH5DGGGGXM\/contact\/5\/category\/Clowns",
232
+ "created": "2008-08-28T01:05:17Z",
233
+ "updated": "2008-09-25T22:49:06Z",
234
+ "id": 1,
235
+ "name": "Clowns"
236
+ }
237
+ ]
238
+ }
239
+ ]
240
+ }
241
+ }