google_contacts_api 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/README.markdown +3 -3
- data/VERSION +1 -1
- data/google_contacts_api.gemspec +23 -11
- data/lib/google_contacts_api/contacts.rb +1 -1
- data/lib/google_contacts_api/group_set.rb +6 -2
- data/spec/{contact_set.json → fixtures/contact_set.json} +0 -0
- data/spec/{empty_contact_set.json → fixtures/empty_contact_set.json} +0 -0
- data/spec/fixtures/empty_group_set.json +72 -0
- data/spec/{group_set.json → fixtures/group_set.json} +1 -1
- data/spec/lib/google_contacts_api/api_spec.rb +88 -0
- data/spec/lib/google_contacts_api/contact_set_spec.rb +39 -0
- data/spec/lib/google_contacts_api/contact_spec.rb +420 -0
- data/spec/lib/google_contacts_api/contacts_spec.rb +33 -0
- data/spec/lib/google_contacts_api/group_set_spec.rb +39 -0
- data/spec/lib/google_contacts_api/group_spec.rb +92 -0
- data/spec/lib/google_contacts_api/groups_spec.rb +33 -0
- data/spec/lib/google_contacts_api/result_set_spec.rb +35 -0
- data/spec/lib/google_contacts_api/result_spec.rb +69 -0
- data/spec/lib/google_contacts_api/user_spec.rb +66 -0
- data/spec/spec_helper.rb +2 -34
- data/spec/support/rspec_helpers.rb +48 -0
- metadata +43 -59
- data/spec/errors/auth_sub_401.html +0 -0
- data/spec/google_contacts_api_spec.rb +0 -608
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd239c2ecad17fa5fb9ca5f01cfda0bf248cb5c5
|
4
|
+
data.tar.gz: 2dc497813f158780edc3741290dcb564d634fcb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45c49f64438e64b67cfadfce88c18b2c77941dd1134782f881fff5e8542f7b1dceffa415840d7027d1271d868cce2bd752e35a02395c30d05c98b129b2506eec
|
7
|
+
data.tar.gz: feec2067b0542e8c270b2f9f3eb5bf38a1c47e5514480e977b47742ad6a85935a6be03283b3bd64c2b5836b0b3fd7a521a1038d4e82cad97ef393e7389ee0ef6
|
data/.rspec
ADDED
data/README.markdown
CHANGED
@@ -80,6 +80,6 @@ by jeweler).
|
|
80
80
|
|
81
81
|
Copyright (c) 2011-15 Alvin Liang (aliang). See LICENSE.txt for further details.
|
82
82
|
|
83
|
-
Some code based on a few bugfixes in lfittl and fraudpointer forks.
|
84
|
-
|
85
|
-
|
83
|
+
* Some code based on a few bugfixes in lfittl and fraudpointer forks.
|
84
|
+
* Support for Google Contacts API version 3 fields by draffensperger.
|
85
|
+
* Additional specs and empty GroupSet entry fix by Jeiwan.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.1
|
data/google_contacts_api.gemspec
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: google_contacts_api 0.7.1 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "google_contacts_api"
|
8
|
-
s.version = "0.7.
|
9
|
+
s.version = "0.7.1"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
11
13
|
s.authors = ["Alvin Liang"]
|
12
|
-
s.date = "
|
14
|
+
s.date = "2016-01-05"
|
13
15
|
s.description = "Lets you read from the Google Contacts API. Posting to come later."
|
14
16
|
s.email = "ayliang@gmail.com"
|
15
17
|
s.extra_rdoc_files = [
|
@@ -18,6 +20,7 @@ Gem::Specification.new do |s|
|
|
18
20
|
]
|
19
21
|
s.files = [
|
20
22
|
".document",
|
23
|
+
".rspec",
|
21
24
|
".travis.yml",
|
22
25
|
"Gemfile",
|
23
26
|
"LICENSE.txt",
|
@@ -37,21 +40,30 @@ Gem::Specification.new do |s|
|
|
37
40
|
"lib/google_contacts_api/result_set.rb",
|
38
41
|
"lib/google_contacts_api/user.rb",
|
39
42
|
"lib/google_contacts_api/version.rb",
|
40
|
-
"spec/contact_set.json",
|
41
|
-
"spec/empty_contact_set.json",
|
42
|
-
"spec/
|
43
|
-
"spec/
|
44
|
-
"spec/
|
45
|
-
"spec/
|
43
|
+
"spec/fixtures/contact_set.json",
|
44
|
+
"spec/fixtures/empty_contact_set.json",
|
45
|
+
"spec/fixtures/empty_group_set.json",
|
46
|
+
"spec/fixtures/group_set.json",
|
47
|
+
"spec/lib/google_contacts_api/api_spec.rb",
|
48
|
+
"spec/lib/google_contacts_api/contact_set_spec.rb",
|
49
|
+
"spec/lib/google_contacts_api/contact_spec.rb",
|
50
|
+
"spec/lib/google_contacts_api/contacts_spec.rb",
|
51
|
+
"spec/lib/google_contacts_api/group_set_spec.rb",
|
52
|
+
"spec/lib/google_contacts_api/group_spec.rb",
|
53
|
+
"spec/lib/google_contacts_api/groups_spec.rb",
|
54
|
+
"spec/lib/google_contacts_api/result_set_spec.rb",
|
55
|
+
"spec/lib/google_contacts_api/result_spec.rb",
|
56
|
+
"spec/lib/google_contacts_api/user_spec.rb",
|
57
|
+
"spec/spec_helper.rb",
|
58
|
+
"spec/support/rspec_helpers.rb"
|
46
59
|
]
|
47
60
|
s.homepage = "http://github.com/aliang/google_contacts_api"
|
48
61
|
s.licenses = ["MIT"]
|
49
|
-
s.
|
50
|
-
s.rubygems_version = "1.8.24"
|
62
|
+
s.rubygems_version = "2.4.8"
|
51
63
|
s.summary = "Lets you read from the Google Contacts API"
|
52
64
|
|
53
65
|
if s.respond_to? :specification_version then
|
54
|
-
s.specification_version =
|
66
|
+
s.specification_version = 4
|
55
67
|
|
56
68
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
69
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
@@ -3,7 +3,11 @@ module GoogleContactsApi
|
|
3
3
|
# Initialize a GroupSet from an API response body that contains groups data
|
4
4
|
def initialize(response_body, api = nil)
|
5
5
|
super
|
6
|
-
@
|
6
|
+
if @parsed.nil? || @parsed.feed.nil? || @parsed.feed.entry.nil?
|
7
|
+
@results = []
|
8
|
+
else
|
9
|
+
@results = @parsed.feed.entry.map { |e| GoogleContactsApi::Group.new(e, nil, api) }
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
|
-
end
|
13
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,72 @@
|
|
1
|
+
{
|
2
|
+
"version": "1.0",
|
3
|
+
"encoding": "UTF-8",
|
4
|
+
"feed": {
|
5
|
+
"xmlns": "http://www.w3.org/2005/Atom",
|
6
|
+
"xmlns$openSearch": "http://a9.com/-/spec/opensearch/1.1/",
|
7
|
+
"xmlns$gContact": "http://schemas.google.com/contact/2008",
|
8
|
+
"xmlns$batch": "http://schemas.google.com/gdata/batch",
|
9
|
+
"xmlns$gd": "http://schemas.google.com/g/2005",
|
10
|
+
"gd$etag": "W/\"C0UESXY5eip7ImA9WhdTEkw.\"",
|
11
|
+
"id": {
|
12
|
+
"$t": "example@gmail.com"
|
13
|
+
},
|
14
|
+
"updated": {
|
15
|
+
"$t": "2011-07-09T11:33:28.822Z"
|
16
|
+
},
|
17
|
+
"category": [{
|
18
|
+
"scheme": "http://schemas.google.com/g/2005#kind",
|
19
|
+
"term": "http://schemas.google.com/contact/2008#group"
|
20
|
+
}],
|
21
|
+
"title": {
|
22
|
+
"$t": "Example User's Contact Groups"
|
23
|
+
},
|
24
|
+
"link": [{
|
25
|
+
"rel": "alternate",
|
26
|
+
"type": "text/html",
|
27
|
+
"href": "http://www.google.com/"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"rel": "http://schemas.google.com/g/2005#feed",
|
31
|
+
"type": "application/atom+xml",
|
32
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"rel": "http://schemas.google.com/g/2005#post",
|
36
|
+
"type": "application/atom+xml",
|
37
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full"
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"rel": "http://schemas.google.com/g/2005#batch",
|
41
|
+
"type": "application/atom+xml",
|
42
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full/batch"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"rel": "self",
|
46
|
+
"type": "application/atom+xml",
|
47
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full?alt\u003djson\u0026max-results\u003d25"
|
48
|
+
}],
|
49
|
+
"author": [{
|
50
|
+
"name": {
|
51
|
+
"$t": "Example User"
|
52
|
+
},
|
53
|
+
"email": {
|
54
|
+
"$t": "example@gmail.com"
|
55
|
+
}
|
56
|
+
}],
|
57
|
+
"generator": {
|
58
|
+
"version": "1.0",
|
59
|
+
"uri": "http://www.google.com/m8/feeds",
|
60
|
+
"$t": "Contacts"
|
61
|
+
},
|
62
|
+
"openSearch$totalResults": {
|
63
|
+
"$t": "0"
|
64
|
+
},
|
65
|
+
"openSearch$startIndex": {
|
66
|
+
"$t": "1"
|
67
|
+
},
|
68
|
+
"openSearch$itemsPerPage": {
|
69
|
+
"$t": "25"
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
class MockOAuth2Error < StandardError
|
2
|
+
attr_accessor :response
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe GoogleContactsApi::Api do
|
10
|
+
describe '#get' do
|
11
|
+
context 'when all parameters are correct' do
|
12
|
+
before do
|
13
|
+
@oauth = double("oauth")
|
14
|
+
allow(@oauth).to receive(:get).and_return("get response")
|
15
|
+
@api = GoogleContactsApi::Api.new(@oauth)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when version is not specified' do
|
19
|
+
it 'performs a get request using oauth returning json with version 3' do
|
20
|
+
expect(@oauth).to receive(:get).with(
|
21
|
+
GoogleContactsApi::Api::BASE_URL + "any_url?alt=json¶m=param&v=3", {"header" => "header"})
|
22
|
+
|
23
|
+
expect(@api.get("any_url",
|
24
|
+
{"param" => "param"},
|
25
|
+
{"header" => "header"})).to eq("get response")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when version is specified' do
|
30
|
+
it 'performs a get request using oauth with the version specified' do
|
31
|
+
expect(@oauth).to receive(:get).with(
|
32
|
+
GoogleContactsApi::Api::BASE_URL + "any_url?alt=json¶m=param&v=2", {"header" => "header"})
|
33
|
+
|
34
|
+
expect(@api.get("any_url",
|
35
|
+
{"param" => "param", "v" => "2"},
|
36
|
+
{"header" => "header"})).to eq("get response")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when OAuth 1.0 returns unauthorized' do
|
42
|
+
before do
|
43
|
+
@oauth = double("oauth")
|
44
|
+
allow(@oauth).to receive(:get).and_return(Net::HTTPUnauthorized.new("1.1", 401, "You're not authorized"))
|
45
|
+
@api = GoogleContactsApi::Api.new(@oauth)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'raises UnauthorizedError' do
|
49
|
+
expect { @api.get("any url",
|
50
|
+
{"param" => "param"},
|
51
|
+
{"header" => "header"}) }.to raise_error(GoogleContactsApi::UnauthorizedError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when OAuth 2.0 returns unauthorized' do
|
56
|
+
before do
|
57
|
+
@oauth = double("oauth")
|
58
|
+
allow(@oauth).to receive(:get).and_raise(MockOAuth2Error.new(OpenStruct.new(status: 401)))
|
59
|
+
@api = GoogleContactsApi::Api.new(@oauth)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'raises UnauthorizedError' do
|
63
|
+
expect { @api.get("any url",
|
64
|
+
{"param" => "param"},
|
65
|
+
{"header" => "header"}) }.to raise_error(GoogleContactsApi::UnauthorizedError)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#parse_response_code" do
|
71
|
+
before(:all) do
|
72
|
+
@Oauth = Struct.new(:code)
|
73
|
+
@Oauth2 = Struct.new(:status)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'parses oauth gem response' do
|
77
|
+
expect(GoogleContactsApi::Api.parse_response_code(@Oauth.new("401"))).to eq(401)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'parses oauth2 gem response' do
|
81
|
+
expect(GoogleContactsApi::Api.parse_response_code(@Oauth2.new(401))).to eq(401)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
pending "should perform a post request using oauth"
|
86
|
+
pending "should perform a put request using oauth"
|
87
|
+
pending "should perform a delete request using oauth"
|
88
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
describe GoogleContactsApi::ContactSet do
|
2
|
+
context "when entries are present" do
|
3
|
+
before(:all) do
|
4
|
+
@contact_set_json = contact_set_json
|
5
|
+
@contact_set = GoogleContactsApi::ContactSet.new(@contact_set_json)
|
6
|
+
end
|
7
|
+
|
8
|
+
specify "the right starting index is set" do
|
9
|
+
expect(@contact_set.start_index).to eq(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
specify "the right number of results per page is set" do
|
13
|
+
expect(@contact_set.items_per_page).to eq(25)
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "the right number of total results is set" do
|
17
|
+
expect(@contact_set.total_results).to eq(500)
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "results are parsed into Contacts" do
|
21
|
+
expect(@contact_set.to_a.first).to be_instance_of(GoogleContactsApi::Contact)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when entries are not present" do
|
26
|
+
before(:all) do
|
27
|
+
@empty_contact_set_json = empty_contact_set_json
|
28
|
+
@empty_contact_set = GoogleContactsApi::ContactSet.new(@empty_contact_set_json)
|
29
|
+
end
|
30
|
+
|
31
|
+
specify "totals_results is equal to 0" do
|
32
|
+
expect(@empty_contact_set.total_results).to eq(0)
|
33
|
+
end
|
34
|
+
|
35
|
+
specify "@results variable is an empty array" do
|
36
|
+
expect(@empty_contact_set.instance_variable_get("@results")).to eq([])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,420 @@
|
|
1
|
+
describe GoogleContactsApi::Contact do
|
2
|
+
subject { GoogleContactsApi::Contact.new(contact_json_hash) }
|
3
|
+
|
4
|
+
describe "#self_link" do
|
5
|
+
it "returns correct self_link" do
|
6
|
+
expect(subject.self_link).to eq("https://www.google.com/m8/feeds/contacts/example%40gmail.com/full/0")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#photo_link_entry" do
|
11
|
+
it "returns correct photo_link_entry" do
|
12
|
+
expect(subject.photo_link_entry).to eq({
|
13
|
+
"rel" => "http://schemas.google.com/contacts/2008/rel#photo",
|
14
|
+
"type" => "image/*",
|
15
|
+
"href" => "https://www.google.com/m8/feeds/photos/media/example%40gmail.com/0",
|
16
|
+
"gd$etag" => "\"dxt2DAEZfCp7ImA-AV4zRxBoPG4UK3owXBM.\""
|
17
|
+
})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#photo_link" do
|
22
|
+
it "returns correct photo_link" do
|
23
|
+
expect(subject.photo_link).to eq("https://www.google.com/m8/feeds/photos/media/example%40gmail.com/0")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#edit_link" do
|
28
|
+
it "returns correct edit_link" do
|
29
|
+
expect(subject.edit_link).to eq("https://www.google.com/m8/feeds/contacts/example%40gmail.com/full/0")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#edit_photo_link" do
|
34
|
+
it "returns correct edit_photo_link" do
|
35
|
+
# TODO: there isn't one in this contact, hahah
|
36
|
+
expect(subject.edit_photo_link).to eq(nil)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#photo" do
|
41
|
+
it "fetches a photo" do
|
42
|
+
@oauth = double("oauth")
|
43
|
+
allow(@oauth).to receive(:get).and_return(Hashie::Mash.new({
|
44
|
+
"body" => "some response", # could use example response here
|
45
|
+
"code" => 200
|
46
|
+
}))
|
47
|
+
@api = double("api")
|
48
|
+
allow(@api).to receive(:oauth).and_return(@oauth)
|
49
|
+
@contact = GoogleContactsApi::Contact.new(contact_json_hash, nil, @api)
|
50
|
+
|
51
|
+
expect(@oauth).to receive("get").with(@contact.photo_link)
|
52
|
+
|
53
|
+
@contact.photo
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#photo_with_metadata" do
|
58
|
+
it "returns photo with metadata" do
|
59
|
+
@oauth = double("oauth")
|
60
|
+
allow(@oauth).to receive(:get).and_return(Hashie::Mash.new({
|
61
|
+
"body" => "some response",
|
62
|
+
"code" => 200,
|
63
|
+
"headers" => { "content-type" => "image/jpeg" }
|
64
|
+
}))
|
65
|
+
@api = double("api")
|
66
|
+
allow(@api).to receive(:oauth).and_return(@oauth)
|
67
|
+
@contact = GoogleContactsApi::Contact.new(contact_json_hash, nil, @api)
|
68
|
+
|
69
|
+
expect(@oauth).to receive("get").with(@contact.photo_link)
|
70
|
+
expect(@contact.photo_with_metadata).to eq(
|
71
|
+
data: 'some response',
|
72
|
+
etag: 'dxt2DAEZfCp7ImA-AV4zRxBoPG4UK3owXBM.',
|
73
|
+
content_type: 'image/jpeg'
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#emails" do
|
79
|
+
context 'when emails are specified' do
|
80
|
+
it "returns an array of emails" do
|
81
|
+
expect(subject.emails).to eq(["contact1@example.com"])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'when emails are not specified' do
|
86
|
+
it "returns an empty array" do
|
87
|
+
@contact = GoogleContactsApi::Contact.new(contact_no_emails_json_hash)
|
88
|
+
expect(@contact.emails).to eq([])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#primary_email" do
|
94
|
+
context "when primary email is set" do
|
95
|
+
it "returns correct primary email" do
|
96
|
+
expect(subject.primary_email).to eq("contact1@example.com")
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "when primary email is not set" do
|
101
|
+
it "returns nil" do
|
102
|
+
@contact2 = GoogleContactsApi::Contact.new(contact_no_emails_json_hash)
|
103
|
+
expect(@contact2.primary_email).to be_nil
|
104
|
+
@contact3 = GoogleContactsApi::Contact.new(contact_no_primary_email_json_hash)
|
105
|
+
expect(@contact3.primary_email).to be_nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#ims" do
|
111
|
+
context "when instant messaging accounts are specified" do
|
112
|
+
it "returns instan messaging accounts" do
|
113
|
+
expect(subject.ims).to eq(["contact1@example.com"])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when instant messaging accounts are not specified" do
|
118
|
+
it "returns an empty array" do
|
119
|
+
@contact = GoogleContactsApi::Contact.new(contact_no_emails_json_hash)
|
120
|
+
expect(@contact.ims).to eq([])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
#
|
126
|
+
describe 'Contacts API v3 fields' do
|
127
|
+
before do
|
128
|
+
@empty = GoogleContactsApi::Contact.new
|
129
|
+
|
130
|
+
@partly_empty = GoogleContactsApi::Contact.new(
|
131
|
+
'gd$name' => {},
|
132
|
+
'gContact$relation' => []
|
133
|
+
)
|
134
|
+
|
135
|
+
@contact_v3 = GoogleContactsApi::Contact.new(
|
136
|
+
'gd$name' => {
|
137
|
+
'gd$givenName' => { '$t' => 'John' },
|
138
|
+
'gd$familyName' => { '$t' => 'Doe' },
|
139
|
+
'gd$fullName' => { '$t' => 'John Doe' }
|
140
|
+
},
|
141
|
+
'gContact$birthday' => {
|
142
|
+
'when' => '1988-05-12'
|
143
|
+
},
|
144
|
+
'gContact$relation' => [ { '$t' => 'Jane', 'rel' => 'spouse' } ],
|
145
|
+
'gd$structuredPostalAddress' => [
|
146
|
+
{
|
147
|
+
'gd$country' => { '$t' => 'United States of America' },
|
148
|
+
'gd$formattedAddress' => { '$t' => "2345 Long Dr. #232\nSomwhere\nIL\n12345\nUnited States of America" },
|
149
|
+
'gd$city' => { '$t' => 'Somwhere' },
|
150
|
+
'gd$street' => { '$t' => '2345 Long Dr. #232' },
|
151
|
+
'gd$region' => { '$t' => 'IL' },
|
152
|
+
'gd$postcode' => { '$t' => '12345' }
|
153
|
+
},
|
154
|
+
{
|
155
|
+
'rel' => 'http://schemas.google.com/g/2005#home',
|
156
|
+
'primary' => 'true',
|
157
|
+
'gd$country' => { '$t' => 'United States of America' },
|
158
|
+
'gd$formattedAddress' => { '$t' => "123 Far Ln.\nAnywhere\nMO\n67891\nUnited States of America" },
|
159
|
+
'gd$city' => { '$t' => 'Anywhere' },
|
160
|
+
'gd$street' => { '$t' => '123 Far Ln.' }
|
161
|
+
}
|
162
|
+
],
|
163
|
+
'gd$email' => [
|
164
|
+
{
|
165
|
+
'primary' => 'true',
|
166
|
+
'rel' => 'http://schemas.google.com/g/2005#other',
|
167
|
+
'address' => 'johnsmith@example.com'
|
168
|
+
}
|
169
|
+
],
|
170
|
+
'gd$phoneNumber' => [
|
171
|
+
{
|
172
|
+
'primary' => 'true',
|
173
|
+
'$t' => '(123) 334-5158',
|
174
|
+
'rel' => 'http://schemas.google.com/g/2005#mobile'
|
175
|
+
}
|
176
|
+
],
|
177
|
+
'gd$organization' => [
|
178
|
+
{
|
179
|
+
'gd$orgTitle' => { '$t' => 'Worker Person' },
|
180
|
+
'gd$orgName' => { '$t' => 'Example, Inc' },
|
181
|
+
'rel' => 'http://schemas.google.com/g/2005#other'
|
182
|
+
}
|
183
|
+
],
|
184
|
+
'gContact$groupMembershipInfo' => [
|
185
|
+
{
|
186
|
+
'deleted' => 'false',
|
187
|
+
'href' => 'http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/111'
|
188
|
+
},
|
189
|
+
{
|
190
|
+
'deleted' => 'true',
|
191
|
+
'href' => 'http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/222'
|
192
|
+
}
|
193
|
+
]
|
194
|
+
)
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '#nested_t_field_or_nil' do
|
198
|
+
context "when nested fields are present" do
|
199
|
+
it "returns correct value" do
|
200
|
+
expect(@contact_v3.nested_t_field_or_nil('gd$name', 'gd$givenName')).to eq('John')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context "when nested fields are not present" do
|
205
|
+
it "returns nil" do
|
206
|
+
expect(@empty.nested_t_field_or_nil('gd$name', 'gd$givenName')).to be_nil
|
207
|
+
expect(@partly_empty.nested_t_field_or_nil('gd$name', 'gd$givenName')).to be_nil
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "#given_name" do
|
213
|
+
it "returns given name" do
|
214
|
+
expect(@contact_v3.given_name).to eq('John')
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
describe "#family_name" do
|
219
|
+
it "returns family name" do
|
220
|
+
expect(@contact_v3.family_name).to eq('Doe')
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "#full_name" do
|
225
|
+
it "returns full name" do
|
226
|
+
expect(@contact_v3).to receive(:nested_t_field_or_nil).with('gd$name', 'gd$fullName').and_return('val')
|
227
|
+
expect(@contact_v3.full_name).to eq('val')
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "#phone_numbers" do
|
232
|
+
it "returns an array of phone numbers" do
|
233
|
+
expect(@contact_v3.phone_numbers).to eq ["(123) 334-5158"]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe "#relations" do
|
238
|
+
context "when relations are set" do
|
239
|
+
it "returns relations" do
|
240
|
+
expect(@contact_v3.relations).to eq([ { '$t' => 'Jane', 'rel' => 'spouse' } ])
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "when relations are not set" do
|
245
|
+
it "returns an empty array" do
|
246
|
+
expect(@empty.relations).to eq([])
|
247
|
+
expect(@partly_empty.relations).to eq([])
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe "#spouse" do
|
253
|
+
context "when spouse is set" do
|
254
|
+
it "returns spouse" do
|
255
|
+
expect(@contact_v3.spouse).to eq('Jane')
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context "when spouse is not set" do
|
260
|
+
it "returns nil" do
|
261
|
+
expect(@empty.spouse).to be_nil
|
262
|
+
expect(@partly_empty.spouse).to be_nil
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
describe "#birthday" do
|
268
|
+
context "when full birthday is set" do
|
269
|
+
it "returns full birthday" do
|
270
|
+
expect(@contact_v3.birthday).to eq({ year: 1988, month: 5, day: 12 })
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context "when year is not specified" do
|
275
|
+
it "returns partial birthday" do
|
276
|
+
contact_birthday_no_year = GoogleContactsApi::Contact.new('gContact$birthday' => { 'when' => '--05-12' })
|
277
|
+
expect(contact_birthday_no_year.birthday).to eq({ year: nil, month: 5, day: 12 })
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context "when birthday is not set" do
|
282
|
+
it "returns nil" do
|
283
|
+
expect(@empty.birthday).to be_nil
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe "#addresses" do
|
289
|
+
context "when addresses are specified" do
|
290
|
+
it "returns addresses" do
|
291
|
+
formatted_addresses = [
|
292
|
+
{ rel: 'work', primary: false, country: 'United States of America', city: 'Somwhere', street: '2345 Long Dr. #232',
|
293
|
+
region: 'IL', postcode: '12345' },
|
294
|
+
{ rel: 'home', primary: true, country: 'United States of America', city: 'Anywhere', street: '123 Far Ln.',
|
295
|
+
region: nil, postcode: nil }
|
296
|
+
]
|
297
|
+
expect(@contact_v3.addresses).to eq(formatted_addresses)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context "when addresses are not specified" do
|
302
|
+
it "returns an empty arary" do
|
303
|
+
expect(@empty.addresses).to eq([])
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
describe "#phone_numbers_full" do
|
309
|
+
context "when phone numbers are specified" do
|
310
|
+
it "returns full phone numbers" do
|
311
|
+
expect(@contact_v3.phone_numbers_full).to eq([ { :primary => true, :number => '(123) 334-5158', :rel => 'mobile' } ])
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context "when phone numbers are not specified" do
|
316
|
+
it "returns an empty array" do
|
317
|
+
expect(@empty.phone_numbers_full).to eq([])
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
describe "#gourp_membership_info" do
|
323
|
+
context "when gourp membership info is specified" do
|
324
|
+
it "returns gourp membership info" do
|
325
|
+
group_membership_info = [
|
326
|
+
{ deleted: false, href: 'http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/111' },
|
327
|
+
{ deleted: true, href: 'http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/222' }
|
328
|
+
]
|
329
|
+
expect(@contact_v3.group_membership_info).to eq(group_membership_info)
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
context "when gourp membership info is not specified" do
|
334
|
+
it "returns an empty array" do
|
335
|
+
expect(@empty.group_membership_info).to eq([])
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
describe "#organizations" do
|
341
|
+
context "when organizations are specified" do
|
342
|
+
it "returns organizations" do
|
343
|
+
formatted_organizations = [
|
344
|
+
{
|
345
|
+
org_title: 'Worker Person',
|
346
|
+
org_name: 'Example, Inc',
|
347
|
+
primary: false,
|
348
|
+
rel: 'other'
|
349
|
+
}
|
350
|
+
]
|
351
|
+
expect(@contact_v3.organizations).to eq(formatted_organizations)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
context "when organizations is not specified" do
|
356
|
+
it "returns an empty array" do
|
357
|
+
expect(@empty.organizations).to eq([])
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
describe "#emails_full" do
|
363
|
+
context "when emails are specified" do
|
364
|
+
it "returns emails" do
|
365
|
+
expect(@contact_v3.emails_full).to eq([ { :primary => true, :address => 'johnsmith@example.com', :rel => 'other' } ])
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
context "when emails is not specified" do
|
370
|
+
it "returns an empty array" do
|
371
|
+
expect(@empty.emails_full).to eq([])
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
describe '#group_memberships' do
|
377
|
+
it "returns group memberships" do
|
378
|
+
expect(@contact_v3.group_memberships).to eq(['http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/111'])
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
describe "#deleted_group_memberships" do
|
383
|
+
it "returns deleted group memberships" do
|
384
|
+
expect(@contact_v3.deleted_group_memberships).to eq(['http://www.google.com/m8/feeds/groups/test.user%40gmail.com/base/222'])
|
385
|
+
end
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
# The Google Contacts API (https://developers.google.com/gdata/docs/2.0/elements)
|
390
|
+
# specifies an optional yomi field for orgName, givenName, additionalName and familyName
|
391
|
+
it 'handles Japanese yomigana "yomi" name values' do
|
392
|
+
contact_params = {
|
393
|
+
'gd$name' => {
|
394
|
+
'gd$givenName' => {'$t' => 'John' },
|
395
|
+
'gd$additionalName' => {'$t' => 'Text name', 'yomi' => 'And yomi chars' },
|
396
|
+
'gd$familyName' => { 'yomi' => 'Yomi chars only' },
|
397
|
+
},
|
398
|
+
'gd$organization' => [{
|
399
|
+
'rel' => 'http://schemas.google.com/g/2005#other',
|
400
|
+
'primary' => 'true',
|
401
|
+
'gd$orgName' => {
|
402
|
+
'yomi' => 'Yomigana'
|
403
|
+
}
|
404
|
+
}],
|
405
|
+
}
|
406
|
+
contact = GoogleContactsApi::Contact.new(contact_params, nil, @api)
|
407
|
+
|
408
|
+
expect(contact.given_name).to eq('John')
|
409
|
+
expect(contact.given_name_yomi).to be_nil
|
410
|
+
|
411
|
+
expect(contact.additional_name).to eq('Text name')
|
412
|
+
expect(contact.additional_name_yomi).to eq('And yomi chars')
|
413
|
+
|
414
|
+
expect(contact.family_name).to be_nil
|
415
|
+
expect(contact.family_name_yomi).to eq('Yomi chars only')
|
416
|
+
|
417
|
+
expect(contact.organizations.first[:org_name]).to be_nil
|
418
|
+
expect(contact.organizations.first[:org_name_yomi]).to eq('Yomigana')
|
419
|
+
end
|
420
|
+
end
|