google_contacts_api 0.6.0 → 0.7.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.
- data/LICENSE.txt +1 -1
- data/README.markdown +1 -1
- data/VERSION +1 -1
- data/google_contacts_api.gemspec +2 -2
- data/lib/google_contacts_api/contact.rb +58 -4
- data/lib/google_contacts_api/group.rb +6 -1
- data/lib/google_contacts_api/result.rb +2 -2
- data/spec/google_contacts_api_spec.rb +74 -5
- metadata +3 -3
data/LICENSE.txt
CHANGED
data/README.markdown
CHANGED
@@ -78,7 +78,7 @@ by jeweler).
|
|
78
78
|
|
79
79
|
## Copyright
|
80
80
|
|
81
|
-
Copyright (c) 2011-
|
81
|
+
Copyright (c) 2011-15 Alvin Liang (aliang). See LICENSE.txt for further details.
|
82
82
|
|
83
83
|
Some code based on a few bugfixes in lfittl and fraudpointer forks.
|
84
84
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/google_contacts_api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "google_contacts_api"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alvin Liang"]
|
12
|
-
s.date = "2015-
|
12
|
+
s.date = "2015-07-24"
|
13
13
|
s.description = "Lets you read from the Google Contacts API. Posting to come later."
|
14
14
|
s.email = "ayliang@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -22,6 +22,10 @@ module GoogleContactsApi
|
|
22
22
|
_link ? _link.href : nil
|
23
23
|
end
|
24
24
|
|
25
|
+
def etag
|
26
|
+
self['gd$etag']
|
27
|
+
end
|
28
|
+
|
25
29
|
# Returns link entry for the photo
|
26
30
|
def photo_link_entry
|
27
31
|
self["link"].find { |l| l.rel == "http://schemas.google.com/contacts/2008/rel#photo" }
|
@@ -113,16 +117,25 @@ module GoogleContactsApi
|
|
113
117
|
end
|
114
118
|
end
|
115
119
|
def given_name
|
116
|
-
|
120
|
+
nested_field_name_only 'gd$name', 'gd$givenName'
|
121
|
+
end
|
122
|
+
def given_name_yomi
|
123
|
+
nested_field_yomi_only 'gd$name', 'gd$givenName'
|
117
124
|
end
|
118
125
|
def family_name
|
119
|
-
|
126
|
+
nested_field_name_only 'gd$name', 'gd$familyName'
|
127
|
+
end
|
128
|
+
def family_name_yomi
|
129
|
+
nested_field_yomi_only 'gd$name', 'gd$familyName'
|
120
130
|
end
|
121
131
|
def full_name
|
122
132
|
nested_t_field_or_nil 'gd$name', 'gd$fullName'
|
123
133
|
end
|
124
134
|
def additional_name
|
125
|
-
|
135
|
+
nested_field_name_only 'gd$name', 'gd$additionalName'
|
136
|
+
end
|
137
|
+
def additional_name_yomi
|
138
|
+
nested_field_yomi_only 'gd$name', 'gd$additionalName'
|
126
139
|
end
|
127
140
|
def name_prefix
|
128
141
|
nested_t_field_or_nil 'gd$name', 'gd$namePrefix'
|
@@ -152,7 +165,13 @@ module GoogleContactsApi
|
|
152
165
|
format_entities('gd$structuredPostalAddress', :format_address)
|
153
166
|
end
|
154
167
|
def organizations
|
155
|
-
format_entities('gd$organization')
|
168
|
+
format_entities('gd$organization').map do |org|
|
169
|
+
if org[:org_name]
|
170
|
+
org[:org_name_yomi] = org[:org_name]['yomi'] if org[:org_name]['yomi']
|
171
|
+
org[:org_name] = name_only(org[:org_name])
|
172
|
+
end
|
173
|
+
org
|
174
|
+
end
|
156
175
|
end
|
157
176
|
def websites
|
158
177
|
format_entities('gContact$website')
|
@@ -168,7 +187,42 @@ module GoogleContactsApi
|
|
168
187
|
format_entities('gd$email')
|
169
188
|
end
|
170
189
|
|
190
|
+
def group_membership_info
|
191
|
+
if self['gContact$groupMembershipInfo']
|
192
|
+
self['gContact$groupMembershipInfo'].map(&method(:format_group_membership))
|
193
|
+
else
|
194
|
+
[]
|
195
|
+
end
|
196
|
+
end
|
197
|
+
def format_group_membership(membership)
|
198
|
+
{ deleted: membership['deleted'] == 'true', href: membership['href'] }
|
199
|
+
end
|
200
|
+
def group_memberships
|
201
|
+
group_membership_info.select { |info| !info[:deleted] }.map { |info| info[:href] }
|
202
|
+
end
|
203
|
+
def deleted_group_memberships
|
204
|
+
group_membership_info.select { |info| info[:deleted] }.map { |info| info[:href] }
|
205
|
+
end
|
206
|
+
|
171
207
|
private
|
208
|
+
def nested_field_name_only(level1, level2)
|
209
|
+
name_only(self[level1][level2]) if self[level1]
|
210
|
+
end
|
211
|
+
|
212
|
+
# Certain fields allow an optional Japanese yomigana subfield (making it
|
213
|
+
# sometimes be a hash which can cause a bug if you're expecteding a string)
|
214
|
+
# This normalizes the field to a string whether the yomi is present or not
|
215
|
+
# This method also accounts for any other unexpected fields
|
216
|
+
def name_only(name)
|
217
|
+
return name if name.blank?
|
218
|
+
return name if name.is_a?(String)
|
219
|
+
name['$t']
|
220
|
+
end
|
221
|
+
|
222
|
+
def nested_field_yomi_only(level1, level2)
|
223
|
+
self[level1][level2]['yomi'] if self[level1]
|
224
|
+
end
|
225
|
+
|
172
226
|
def format_entities(key, format_method=:format_entity)
|
173
227
|
self[key] ? self[key].map(&method(format_method)) : []
|
174
228
|
end
|
@@ -8,6 +8,11 @@ module GoogleContactsApi
|
|
8
8
|
!self["gContact$systemGroup"].nil?
|
9
9
|
end
|
10
10
|
|
11
|
+
def system_group_id
|
12
|
+
return unless self.system_group?
|
13
|
+
self['gContact$systemGroup']['id']
|
14
|
+
end
|
15
|
+
|
11
16
|
# Return the contacts in this group and cache them.
|
12
17
|
def contacts(params = {})
|
13
18
|
# contacts in this group
|
@@ -36,4 +41,4 @@ module GoogleContactsApi
|
|
36
41
|
_link ? _link.href : nil
|
37
42
|
end
|
38
43
|
end
|
39
|
-
end
|
44
|
+
end
|
@@ -240,7 +240,10 @@ describe "GoogleContactsApi" do
|
|
240
240
|
end
|
241
241
|
|
242
242
|
describe "Result" do
|
243
|
-
|
243
|
+
it 'supports the deleted? method' do
|
244
|
+
expect(GoogleContactsApi::Result.new('gd$deleted' => {}).deleted?).to eq(true)
|
245
|
+
expect(GoogleContactsApi::Result.new.deleted?).to eq(false)
|
246
|
+
end
|
244
247
|
end
|
245
248
|
|
246
249
|
describe "Contact" do
|
@@ -397,6 +400,16 @@ describe "GoogleContactsApi" do
|
|
397
400
|
'gd$orgName' => { '$t' => 'Example, Inc' },
|
398
401
|
'rel' => 'http://schemas.google.com/g/2005#other'
|
399
402
|
}
|
403
|
+
],
|
404
|
+
'gContact$groupMembershipInfo' => [
|
405
|
+
{
|
406
|
+
'deleted' => 'false',
|
407
|
+
'href' => 'http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/111'
|
408
|
+
},
|
409
|
+
{
|
410
|
+
'deleted' => 'true',
|
411
|
+
'href' => 'http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/222'
|
412
|
+
}
|
400
413
|
]
|
401
414
|
)
|
402
415
|
end
|
@@ -408,13 +421,11 @@ describe "GoogleContactsApi" do
|
|
408
421
|
end
|
409
422
|
|
410
423
|
it 'has given_name' do
|
411
|
-
expect(@contact_v3).to
|
412
|
-
expect(@contact_v3.given_name).to eq('val')
|
424
|
+
expect(@contact_v3.given_name).to eq('John')
|
413
425
|
end
|
414
426
|
|
415
427
|
it 'has family_name' do
|
416
|
-
expect(@contact_v3).to
|
417
|
-
expect(@contact_v3.family_name).to eq('val')
|
428
|
+
expect(@contact_v3.family_name).to eq('Doe')
|
418
429
|
end
|
419
430
|
|
420
431
|
it 'has full_name' do
|
@@ -475,6 +486,56 @@ describe "GoogleContactsApi" do
|
|
475
486
|
]
|
476
487
|
expect(@contact_v3.organizations).to eq(formatted_organizations)
|
477
488
|
end
|
489
|
+
|
490
|
+
it 'has group membership info' do
|
491
|
+
expect(@empty.group_membership_info).to eq([])
|
492
|
+
|
493
|
+
group_membership_info = [
|
494
|
+
{ deleted: false, href: 'http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/111' },
|
495
|
+
{ deleted: true, href: 'http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/222' }
|
496
|
+
]
|
497
|
+
expect(@contact_v3.group_membership_info).to eq(group_membership_info)
|
498
|
+
end
|
499
|
+
|
500
|
+
it 'has group memberships' do
|
501
|
+
expect(@contact_v3.group_memberships).to eq(['http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/111'])
|
502
|
+
end
|
503
|
+
|
504
|
+
it 'has deleted group memberships' do
|
505
|
+
expect(@contact_v3.deleted_group_memberships).to eq(['http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/222'])
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
# The Google Contacts API (https://developers.google.com/gdata/docs/2.0/elements)
|
510
|
+
# specifies an optional yomi field for orgName, givenName, additionalName and familyName
|
511
|
+
it 'handles Japanese yomigana "yomi" name values' do
|
512
|
+
contact_params = {
|
513
|
+
'gd$name' => {
|
514
|
+
'gd$givenName' => {'$t' => 'John' },
|
515
|
+
'gd$additionalName' => {'$t' => 'Text name', 'yomi' => 'And yomi chars' },
|
516
|
+
'gd$familyName' => { 'yomi' => 'Yomi chars only' },
|
517
|
+
},
|
518
|
+
'gd$organization' => [{
|
519
|
+
'rel' => 'http://schemas.google.com/g/2005#other',
|
520
|
+
'primary' => 'true',
|
521
|
+
'gd$orgName' => {
|
522
|
+
'yomi' => 'Yomigana'
|
523
|
+
}
|
524
|
+
}],
|
525
|
+
}
|
526
|
+
contact = GoogleContactsApi::Contact.new(contact_params, nil, @api)
|
527
|
+
|
528
|
+
expect(contact.given_name).to eq('John')
|
529
|
+
expect(contact.given_name_yomi).to be_nil
|
530
|
+
|
531
|
+
expect(contact.additional_name).to eq('Text name')
|
532
|
+
expect(contact.additional_name_yomi).to eq('And yomi chars')
|
533
|
+
|
534
|
+
expect(contact.family_name).to be_nil
|
535
|
+
expect(contact.family_name_yomi).to eq('Yomi chars only')
|
536
|
+
|
537
|
+
expect(contact.organizations.first[:org_name]).to be_nil
|
538
|
+
expect(contact.organizations.first[:org_name_yomi]).to eq('Yomigana')
|
478
539
|
end
|
479
540
|
end
|
480
541
|
|
@@ -501,6 +562,14 @@ describe "GoogleContactsApi" do
|
|
501
562
|
it "should tell me if it's a system group" do
|
502
563
|
expect(@group).to be_system_group
|
503
564
|
end
|
565
|
+
it 'tells the system group id or nil if not a system group' do
|
566
|
+
expect(@group).to be_system_group
|
567
|
+
expect(@group.system_group_id).to eq('Contacts')
|
568
|
+
|
569
|
+
@group.delete('gContact$systemGroup')
|
570
|
+
expect(@group).to_not be_system_group
|
571
|
+
expect(@group.system_group_id).to be_nil
|
572
|
+
end
|
504
573
|
describe ".contacts" do
|
505
574
|
before(:each) do
|
506
575
|
@api = double("api")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_contacts_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -236,7 +236,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
236
236
|
version: '0'
|
237
237
|
segments:
|
238
238
|
- 0
|
239
|
-
hash: -
|
239
|
+
hash: -2507649345760241403
|
240
240
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
241
|
none: false
|
242
242
|
requirements:
|