aeden-contacts 0.2.15 → 0.2.16
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/VERSION.yml +1 -1
- data/lib/contacts/google.rb +43 -2
- data/lib/contacts/windows_live.rb +1 -1
- data/lib/contacts.rb +4 -2
- data/spec/contact_spec.rb +9 -1
- data/spec/windows_live/windows_live_spec.rb +2 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/contacts/google.rb
CHANGED
@@ -46,6 +46,7 @@ module Contacts
|
|
46
46
|
AuthSubPath = '/accounts/AuthSub' # all variants go over HTTPS
|
47
47
|
ClientLogin = '/accounts/ClientLogin'
|
48
48
|
FeedsPath = '/m8/feeds/contacts/'
|
49
|
+
GroupsPath = '/m8/feeds/groups/'
|
49
50
|
|
50
51
|
# default options for #authentication_url
|
51
52
|
def self.authentication_url_options
|
@@ -119,19 +120,32 @@ module Contacts
|
|
119
120
|
@token = token.to_s
|
120
121
|
@headers = {
|
121
122
|
'Accept-Encoding' => 'gzip',
|
122
|
-
'User-Agent' => Identifier + ' (gzip)'
|
123
|
+
'User-Agent' => Identifier + ' (gzip)',
|
124
|
+
'GData-Version' => '3.0'
|
123
125
|
}.update(self.class.authorization_header(@token, client))
|
124
126
|
@projection = 'thin'
|
125
127
|
end
|
126
128
|
|
127
|
-
def get(params) # :nodoc:
|
129
|
+
def get(params={}) # :nodoc:
|
128
130
|
self.class.http_start(false) do |google|
|
129
131
|
path = FeedsPath + CGI.escape(@user)
|
130
132
|
google_params = translate_parameters(params)
|
131
133
|
query = self.class.query_string(google_params)
|
134
|
+
#puts "get query: #{query}"
|
132
135
|
google.get("#{path}/#{@projection}?#{query}", @headers)
|
133
136
|
end
|
134
137
|
end
|
138
|
+
|
139
|
+
def get_groups(params={})
|
140
|
+
self.class.http_start(false) do |google|
|
141
|
+
path = GroupsPath + CGI.escape(@user)
|
142
|
+
google_params = translate_parameters(params)
|
143
|
+
query = self.class.query_string(google_params)
|
144
|
+
url = "#{path}/full?#{query}"
|
145
|
+
#puts "get_groups url: #{url}"
|
146
|
+
google.get(url, @headers)
|
147
|
+
end
|
148
|
+
end
|
135
149
|
|
136
150
|
# Timestamp of last update. This value is available only after the XML
|
137
151
|
# document has been parsed; for instance after fetching the contact list.
|
@@ -164,6 +178,12 @@ module Contacts
|
|
164
178
|
in_chunks(options, :contacts, chunk_size)
|
165
179
|
end
|
166
180
|
|
181
|
+
def groups(options = {})
|
182
|
+
params = {}.update(options)
|
183
|
+
response = get_groups(params)
|
184
|
+
parse_groups response_body(response)
|
185
|
+
end
|
186
|
+
|
167
187
|
def response_body(response)
|
168
188
|
self.class.response_body(response)
|
169
189
|
end
|
@@ -192,6 +212,24 @@ module Contacts
|
|
192
212
|
returns
|
193
213
|
end
|
194
214
|
|
215
|
+
def parse_groups(body)
|
216
|
+
doc = Hpricot::XML body
|
217
|
+
groups_found = {}
|
218
|
+
|
219
|
+
(doc / '/feed/entry').each do |entry|
|
220
|
+
id_node = entry.at('id')
|
221
|
+
title_node = entry.at('/title')
|
222
|
+
|
223
|
+
entry_id = id_node.inner_text
|
224
|
+
title = title_node ? title_node.inner_text : ''
|
225
|
+
|
226
|
+
puts "#{title}: #{entry_id}"
|
227
|
+
groups_found[title] = entry_id
|
228
|
+
end
|
229
|
+
|
230
|
+
groups_found
|
231
|
+
end
|
232
|
+
|
195
233
|
def parse_contacts(body)
|
196
234
|
doc = Hpricot::XML body
|
197
235
|
contacts_found = []
|
@@ -326,6 +364,9 @@ module Contacts
|
|
326
364
|
when :updated_after
|
327
365
|
value = value.strftime("%Y-%m-%dT%H:%M:%S%Z") if value.respond_to? :strftime
|
328
366
|
'updated-min'
|
367
|
+
when :group_name
|
368
|
+
value = groups[value]
|
369
|
+
'group'
|
329
370
|
else key
|
330
371
|
end
|
331
372
|
|
data/lib/contacts.rb
CHANGED
@@ -6,10 +6,10 @@ module Contacts
|
|
6
6
|
|
7
7
|
# An object that represents a single contact
|
8
8
|
class Contact
|
9
|
-
attr_reader :emails, :ims, :phones, :addresses, :organizations
|
9
|
+
attr_reader :emails, :ims, :phones, :addresses, :organizations, :firstname, :lastname
|
10
10
|
attr_accessor :name, :username, :service_id, :note
|
11
11
|
|
12
|
-
def initialize(email, name = nil, username = nil)
|
12
|
+
def initialize(email, name = nil, username = nil, firstname = nil, lastname = nil)
|
13
13
|
@emails = []
|
14
14
|
@emails << email if email
|
15
15
|
@ims = []
|
@@ -18,6 +18,8 @@ module Contacts
|
|
18
18
|
@organizations = []
|
19
19
|
@name = name
|
20
20
|
@username = username
|
21
|
+
@firstname = firstname
|
22
|
+
@lastname = lastname
|
21
23
|
end
|
22
24
|
|
23
25
|
def email
|
data/spec/contact_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'contacts'
|
|
4
4
|
describe Contacts::Contact do
|
5
5
|
describe 'instance' do
|
6
6
|
before do
|
7
|
-
@contact = Contacts::Contact.new('max@example.com', 'Max Power', 'maxpower')
|
7
|
+
@contact = Contacts::Contact.new('max@example.com', 'Max Power', 'maxpower', "Max", "Power")
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should have email" do
|
@@ -44,6 +44,14 @@ describe Contacts::Contact do
|
|
44
44
|
it "should have username" do
|
45
45
|
@contact.username.should == 'maxpower'
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should have firstname" do
|
49
|
+
@contact.firstname.should == 'Max'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have lastname" do
|
53
|
+
@contact.lastname.should == 'Power'
|
54
|
+
end
|
47
55
|
end
|
48
56
|
|
49
57
|
describe '#inspect' do
|
@@ -13,6 +13,8 @@ describe Contacts::WindowsLive do
|
|
13
13
|
|
14
14
|
contacts[0].name.should be_nil
|
15
15
|
contacts[0].email.should == 'froz@gmail.com'
|
16
|
+
contacts[1].firstname.should == "Rafael"
|
17
|
+
contacts[1].lastname.should == "Timbo"
|
16
18
|
contacts[1].name.should == 'Rafael Timbo'
|
17
19
|
contacts[1].email.should == 'timbo@hotmail.com'
|
18
20
|
contacts[2].name.should be_nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aeden-contacts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Mislav Marohni\xC6\x92\xC3\xA1"
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-07-
|
14
|
+
date: 2009-07-10 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies: []
|
17
17
|
|