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.
metadata CHANGED
@@ -1,116 +1,102 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_contacts_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
5
- prerelease:
4
+ version: 0.7.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alvin Liang
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-07-24 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: i18n
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: json
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: hashie
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: shoulda
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: simplecov
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: rspec
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ~>
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ~>
124
109
  - !ruby/object:Gem::Version
@@ -126,65 +111,57 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: rdoc
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - '>='
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - '>='
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: bundler
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ! '>='
129
+ - - '>='
148
130
  - !ruby/object:Gem::Version
149
131
  version: '0'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ! '>='
136
+ - - '>='
156
137
  - !ruby/object:Gem::Version
157
138
  version: '0'
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: jeweler
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
- - - ! '>='
143
+ - - '>='
164
144
  - !ruby/object:Gem::Version
165
145
  version: '0'
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
- - - ! '>='
150
+ - - '>='
172
151
  - !ruby/object:Gem::Version
173
152
  version: '0'
174
153
  - !ruby/object:Gem::Dependency
175
154
  name: travis-lint
176
155
  requirement: !ruby/object:Gem::Requirement
177
- none: false
178
156
  requirements:
179
- - - ! '>='
157
+ - - '>='
180
158
  - !ruby/object:Gem::Version
181
159
  version: '0'
182
160
  type: :development
183
161
  prerelease: false
184
162
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
163
  requirements:
187
- - - ! '>='
164
+ - - '>='
188
165
  - !ruby/object:Gem::Version
189
166
  version: '0'
190
167
  description: Lets you read from the Google Contacts API. Posting to come later.
@@ -196,6 +173,7 @@ extra_rdoc_files:
196
173
  - README.markdown
197
174
  files:
198
175
  - .document
176
+ - .rspec
199
177
  - .travis.yml
200
178
  - Gemfile
201
179
  - LICENSE.txt
@@ -215,38 +193,44 @@ files:
215
193
  - lib/google_contacts_api/result_set.rb
216
194
  - lib/google_contacts_api/user.rb
217
195
  - lib/google_contacts_api/version.rb
218
- - spec/contact_set.json
219
- - spec/empty_contact_set.json
220
- - spec/errors/auth_sub_401.html
221
- - spec/google_contacts_api_spec.rb
222
- - spec/group_set.json
196
+ - spec/fixtures/contact_set.json
197
+ - spec/fixtures/empty_contact_set.json
198
+ - spec/fixtures/empty_group_set.json
199
+ - spec/fixtures/group_set.json
200
+ - spec/lib/google_contacts_api/api_spec.rb
201
+ - spec/lib/google_contacts_api/contact_set_spec.rb
202
+ - spec/lib/google_contacts_api/contact_spec.rb
203
+ - spec/lib/google_contacts_api/contacts_spec.rb
204
+ - spec/lib/google_contacts_api/group_set_spec.rb
205
+ - spec/lib/google_contacts_api/group_spec.rb
206
+ - spec/lib/google_contacts_api/groups_spec.rb
207
+ - spec/lib/google_contacts_api/result_set_spec.rb
208
+ - spec/lib/google_contacts_api/result_spec.rb
209
+ - spec/lib/google_contacts_api/user_spec.rb
223
210
  - spec/spec_helper.rb
211
+ - spec/support/rspec_helpers.rb
224
212
  homepage: http://github.com/aliang/google_contacts_api
225
213
  licenses:
226
214
  - MIT
215
+ metadata: {}
227
216
  post_install_message:
228
217
  rdoc_options: []
229
218
  require_paths:
230
219
  - lib
231
220
  required_ruby_version: !ruby/object:Gem::Requirement
232
- none: false
233
221
  requirements:
234
- - - ! '>='
222
+ - - '>='
235
223
  - !ruby/object:Gem::Version
236
224
  version: '0'
237
- segments:
238
- - 0
239
- hash: -2507649345760241403
240
225
  required_rubygems_version: !ruby/object:Gem::Requirement
241
- none: false
242
226
  requirements:
243
- - - ! '>='
227
+ - - '>='
244
228
  - !ruby/object:Gem::Version
245
229
  version: '0'
246
230
  requirements: []
247
231
  rubyforge_project:
248
- rubygems_version: 1.8.24
232
+ rubygems_version: 2.4.8
249
233
  signing_key:
250
- specification_version: 3
234
+ specification_version: 4
251
235
  summary: Lets you read from the Google Contacts API
252
236
  test_files: []
File without changes
@@ -1,608 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- class MockOAuth2Error < StandardError
4
- attr_accessor :response
5
-
6
- def initialize(response)
7
- @response = response
8
- end
9
- end
10
-
11
- describe "GoogleContactsApi" do
12
- describe "Api" do
13
- before(:each) do
14
- @oauth = double("oauth")
15
- allow(@oauth).to receive(:get).and_return("get response")
16
- @api = GoogleContactsApi::Api.new(@oauth)
17
- end
18
-
19
- describe ".get" do
20
- it "should perform a get request using oauth returning json with version 3" do
21
- # expectation should come before execution
22
- expect(@oauth).to receive(:get).with(
23
- GoogleContactsApi::Api::BASE_URL + "any_url?alt=json&param=param&v=3", {"header" => "header"})
24
- expect(@api.get("any_url",
25
- {"param" => "param"},
26
- {"header" => "header"})).to eq("get response")
27
- end
28
-
29
- it "should perform a get request using oauth with the version specified" do
30
- expect(@oauth).to receive(:get).with(
31
- GoogleContactsApi::Api::BASE_URL + "any_url?alt=json&param=param&v=2", {"header" => "header"})
32
- expect(@api.get("any_url",
33
- {"param" => "param", "v" => "2"},
34
- {"header" => "header"})).to eq("get response")
35
- end
36
- end
37
-
38
- # Not implemented yet
39
- pending "should perform a post request using oauth"
40
- pending "should perform a put request using oauth"
41
- pending "should perform a delete request using oauth"
42
- # Not sure how to test, you'd need a revoked token.
43
- it "should raise UnauthorizedError if OAuth 1.0 returns unauthorized" do
44
- oauth = double("oauth")
45
- error_html = load_file(File.join('errors', 'auth_sub_401.html'))
46
- allow(oauth).to receive(:get).and_return(Net::HTTPUnauthorized.new("1.1", 401, error_html))
47
- api = GoogleContactsApi::Api.new(oauth)
48
- expect { api.get("any url",
49
- {"param" => "param"},
50
- {"header" => "header"}) }.to raise_error(GoogleContactsApi::UnauthorizedError)
51
- end
52
-
53
- it "should raise UnauthorizedError if OAuth 2.0 returns unauthorized" do
54
- oauth = double("oauth2")
55
- oauth2_response = Struct.new(:status)
56
- allow(oauth).to receive(:get).and_raise(MockOAuth2Error.new(oauth2_response.new(401)))
57
- api = GoogleContactsApi::Api.new(oauth)
58
- expect { api.get("any url",
59
- {"param" => "param"},
60
- {"header" => "header"}) }.to raise_error(GoogleContactsApi::UnauthorizedError)
61
- end
62
-
63
- describe "parsing response code" do
64
- before(:all) do
65
- @Oauth = Struct.new(:code)
66
- @Oauth2 = Struct.new(:status)
67
- end
68
- it "should parse something that looks like an oauth gem response" do
69
- expect(GoogleContactsApi::Api.parse_response_code(@Oauth.new("401"))).to eq(401)
70
- end
71
-
72
- it "should parse something that looks like an oauth2 gem response" do
73
- expect(GoogleContactsApi::Api.parse_response_code(@Oauth2.new(401))).to eq(401)
74
- end
75
- end
76
- end
77
-
78
- describe GoogleContactsApi::Contacts do
79
- let(:api) { double("api") }
80
- let(:test_class) {
81
- Class.new do
82
- include GoogleContactsApi::Contacts
83
- def initialize(api)
84
- @api = api
85
- end
86
- end
87
- }
88
- describe ".get_contacts" do
89
- it "should get the contacts using the internal @api object" do
90
- expect(api).to receive(:get).with("contacts/default/full", kind_of(Hash)).and_return(Hashie::Mash.new({
91
- "body" => "some response", # could use example response here
92
- "code" => 200
93
- }))
94
- allow(GoogleContactsApi::ContactSet).to receive(:new).and_return("contact set")
95
- expect(test_class.new(api).get_contacts).to eq("contact set")
96
- end
97
- end
98
- end
99
-
100
- describe GoogleContactsApi::Groups do
101
- let(:api) { double("api") }
102
- let(:test_class) {
103
- Class.new do
104
- include GoogleContactsApi::Groups
105
- def initialize(api)
106
- @api = api
107
- end
108
- end
109
- }
110
- describe ".get_groups" do
111
- it "should get the groups using the internal @api object" do
112
- expect(api).to receive(:get).with("groups/default/full", kind_of(Hash)).and_return(Hashie::Mash.new({
113
- "body" => "some response", # could use example response here
114
- "code" => 200
115
- }))
116
- allow(GoogleContactsApi::GroupSet).to receive(:new).and_return("group set")
117
- expect(test_class.new(api).get_groups).to eq("group set")
118
- end
119
- end
120
- end
121
-
122
- describe GoogleContactsApi::User do
123
- let(:oauth) { double ("oauth") }
124
- let(:user) { GoogleContactsApi::User.new(@oauth) }
125
-
126
- # Should hit the right URLs and return the right stuff
127
- describe ".groups" do
128
- it "should be able to get groups including system groups" do
129
- expect(user).to receive(:get_groups).and_return("group set")
130
- expect(user.groups).to eq("group set")
131
- end
132
- end
133
- describe ".groups!" do
134
- it "should be able to get groups" do
135
- expect(user).to receive(:get_groups).and_return("group set")
136
- expect(user.groups!).to eq("group set")
137
- end
138
- it "should pass query params along to get_groups" do
139
- expect(user).to receive(:get_groups).with("something" => "important").and_return("group set")
140
- expect(user.groups!("something" => "important")).to eq("group set")
141
- end
142
- it "should reload the groups" do
143
- expect(user).to receive(:get_groups).and_return("group set").twice
144
- user.groups
145
- groups = user.groups!
146
- expect(groups).to eq("group set")
147
- end
148
- end
149
- describe ".contacts" do
150
- it "should be able to get contacts" do
151
- expect(user).to receive(:get_contacts).and_return("contact set")
152
- expect(user.contacts).to eq("contact set")
153
- end
154
- it "should use the contact cache for subsequent access" do
155
- expect(user).to receive(:get_contacts).and_return("contact set").once
156
- user.contacts
157
- contacts = user.contacts
158
- expect(contacts).to eq("contact set")
159
- end
160
- end
161
- describe ".contacts!" do
162
- it "should be able to get contacts" do
163
- expect(user).to receive(:get_contacts).and_return("contact set")
164
- expect(user.contacts!).to eq("contact set")
165
- end
166
- it "should pass query params along to get_contacts" do
167
- expect(user).to receive(:get_contacts).with("something" => "important").and_return("contact set")
168
- expect(user.contacts!("something" => "important")).to eq("contact set")
169
- end
170
- it "should reload the contacts" do
171
- expect(user).to receive(:get_contacts).and_return("contact set").twice
172
- user.contacts
173
- contacts = user.contacts!
174
- expect(contacts).to eq("contact set")
175
- end
176
- end
177
- end
178
-
179
- describe "ResultSet" do
180
- pending ".each"
181
- pending ".has_more?"
182
- end
183
-
184
- describe "ContactSet" do
185
- describe "with entries" do
186
- before(:all) do
187
- @contact_set_json = contact_set_json
188
- @contact_set = GoogleContactsApi::ContactSet.new(@contact_set_json)
189
- end
190
-
191
- it "should return the right starting index" do
192
- expect(@contact_set.start_index).to eq(1)
193
- end
194
- it "should return the right number of results per page" do
195
- expect(@contact_set.items_per_page).to eq(25)
196
- end
197
- it "should return the right number of total results" do
198
- expect(@contact_set.total_results).to eq(500)
199
- end
200
- it "should tell me if there are more results" do
201
- # yeah this is an awkward assertion and matcher
202
- expect(@contact_set).to be_has_more
203
- expect(@contact_set.has_more?).to eq(true)
204
- end
205
- it "should parse results into Contacts" do
206
- expect(@contact_set.to_a.first).to be_instance_of(GoogleContactsApi::Contact)
207
- end
208
- end
209
- it "should parse nil results into an empty array" do
210
- @empty_contact_set_json = empty_contact_set_json
211
- @empty_contact_set = GoogleContactsApi::ContactSet.new(@empty_contact_set_json)
212
- expect(@empty_contact_set.total_results).to eq(0)
213
- expect(@empty_contact_set.instance_variable_get("@results")).to eq([])
214
- end
215
- end
216
-
217
- describe "GroupSet" do
218
- before(:all) do
219
- @group_set_json = group_set_json
220
- @group_set = GoogleContactsApi::GroupSet.new(@group_set_json)
221
- end
222
-
223
- it "should return the right starting index" do
224
- expect(@group_set.start_index).to eq(1)
225
- end
226
- it "should return the right number of results per page" do
227
- expect(@group_set.items_per_page).to eq(25)
228
- end
229
- it "should return the right number of total results" do
230
- expect(@group_set.total_results).to eq(5)
231
- end
232
- it "should tell me if there are more results" do
233
- # yeah this is an awkward assertion and matcher
234
- expect(@group_set).not_to be_has_more
235
- expect(@group_set.has_more?).to eq(false)
236
- end
237
- it "should parse results into Groups" do
238
- expect(@group_set.to_a.first).to be_instance_of(GoogleContactsApi::Group)
239
- end
240
- end
241
-
242
- describe "Result" do
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
247
- end
248
-
249
- describe "Contact" do
250
- before(:all) do
251
- @contact_json_hash = contact_json_hash
252
- @contact = GoogleContactsApi::Contact.new(@contact_json_hash)
253
- end
254
- # ok, these tests are kind of silly
255
- it "should return the right title" do
256
- expect(@contact.title).to eq("Contact 1")
257
- end
258
- it "should return the right id" do
259
- expect(@contact.id).to eq("http://www.google.com/m8/feeds/contacts/example%40gmail.com/base/0")
260
- end
261
- it "should return the right content" do
262
- # TODO: Nothing in source, oops
263
- expect(@contact.content).to eq(nil)
264
- end
265
- it "should return the right updated time" do
266
- # different representation slightly
267
- expect(@contact.updated.to_s).to eq("2011-07-07T21:02:42+00:00")
268
- end
269
- it "should return the right self link" do
270
- expect(@contact.self_link).to eq("https://www.google.com/m8/feeds/contacts/example%40gmail.com/full/0")
271
- end
272
- it "should return the right photo link entry" do
273
- expect(@contact.photo_link_entry).to eq({
274
- "rel" => "http://schemas.google.com/contacts/2008/rel#photo",
275
- "type" => "image/*",
276
- "href" => "https://www.google.com/m8/feeds/photos/media/example%40gmail.com/0",
277
- "gd$etag" => "\"dxt2DAEZfCp7ImA-AV4zRxBoPG4UK3owXBM.\""
278
- })
279
- end
280
- it "should return the right photo link" do
281
- expect(@contact.photo_link).to eq("https://www.google.com/m8/feeds/photos/media/example%40gmail.com/0")
282
- end
283
- it "should return the right edit link" do
284
- expect(@contact.edit_link).to eq("https://www.google.com/m8/feeds/contacts/example%40gmail.com/full/0")
285
- end
286
- it "should return the right edit photo link" do
287
- # TODO: there isn't one in this contact, hahah
288
- expect(@contact.edit_photo_link).to eq(nil)
289
- end
290
- it "should try to fetch a photo" do
291
- @oauth = double("oauth")
292
- allow(@oauth).to receive(:get).and_return(Hashie::Mash.new({
293
- "body" => "some response", # could use example response here
294
- "code" => 200
295
- }))
296
- # @api = GoogleContactsApi::Api.new(@oauth)
297
- @api = double("api")
298
- allow(@api).to receive(:oauth).and_return(@oauth)
299
- @contact = GoogleContactsApi::Contact.new(@contact_json_hash, nil, @api)
300
- expect(@oauth).to receive("get").with(@contact.photo_link)
301
- @contact.photo
302
- end
303
- it "should fetch a photo with metadata" do
304
- @oauth = double("oauth")
305
- allow(@oauth).to receive(:get).and_return(Hashie::Mash.new({
306
- "body" => "some response",
307
- "code" => 200,
308
- "headers" => { "content-type" => "image/jpeg" }
309
- }))
310
- @api = double("api")
311
- allow(@api).to receive(:oauth).and_return(@oauth)
312
- @contact = GoogleContactsApi::Contact.new(@contact_json_hash, nil, @api)
313
- expect(@oauth).to receive("get").with(@contact.photo_link)
314
- expect(@contact.photo_with_metadata).to eq( { data: 'some response',
315
- etag: 'dxt2DAEZfCp7ImA-AV4zRxBoPG4UK3owXBM.',
316
- content_type: 'image/jpeg'
317
- } )
318
- end
319
- # TODO: there isn't any phone number in here
320
- pending "should return all phone numbers"
321
- it "should return all e-mail addresses" do
322
- expect(@contact.emails).to eq(["contact1@example.com"])
323
- end
324
- it "should return the right primary e-mail address" do
325
- expect(@contact.primary_email).to eq("contact1@example.com")
326
- end
327
- it "should return an empty array if there are no e-mail addresses" do
328
- @contact = GoogleContactsApi::Contact.new(contact_no_emails_json_hash)
329
- expect(@contact.emails).to eq([])
330
- end
331
- it "should return nil if there is no primary e-mail address" do
332
- @contact2 = GoogleContactsApi::Contact.new(contact_no_emails_json_hash)
333
- expect(@contact2.primary_email).to be_nil
334
- @contact3 = GoogleContactsApi::Contact.new(contact_no_primary_email_json_hash)
335
- expect(@contact3.primary_email).to be_nil
336
- end
337
- it "should return all instant messaging accounts" do
338
- expect(@contact.ims).to eq(["contact1@example.com"])
339
- end
340
- it "should return an empty array if there are no instant messaging accounts" do
341
- @contact = GoogleContactsApi::Contact.new(contact_no_emails_json_hash)
342
- expect(@contact.ims).to eq([])
343
- end
344
-
345
- #
346
- describe 'Contacts API v3 fields' do
347
- before do
348
- @empty = GoogleContactsApi::Contact.new
349
-
350
- @partly_empty = GoogleContactsApi::Contact.new(
351
- 'gd$name' => {},
352
- 'gContact$relation' => []
353
- )
354
-
355
- @contact_v3 = GoogleContactsApi::Contact.new(
356
- 'gd$name' => {
357
- 'gd$givenName' => { '$t' => 'John' },
358
- 'gd$familyName' => { '$t' => 'Doe' },
359
- 'gd$fullName' => { '$t' => 'John Doe' }
360
- },
361
- 'gContact$birthday' => {
362
- 'when' => '1988-05-12'
363
- },
364
- 'gContact$relation' => [ { '$t' => 'Jane', 'rel' => 'spouse' } ],
365
- 'gd$structuredPostalAddress' => [
366
- {
367
- 'gd$country' => { '$t' => 'United States of America' },
368
- 'gd$formattedAddress' => { '$t' => "2345 Long Dr. #232\nSomwhere\nIL\n12345\nUnited States of America" },
369
- 'gd$city' => { '$t' => 'Somwhere' },
370
- 'gd$street' => { '$t' => '2345 Long Dr. #232' },
371
- 'gd$region' => { '$t' => 'IL' },
372
- 'gd$postcode' => { '$t' => '12345' }
373
- },
374
- {
375
- 'rel' => 'http://schemas.google.com/g/2005#home',
376
- 'primary' => 'true',
377
- 'gd$country' => { '$t' => 'United States of America' },
378
- 'gd$formattedAddress' => { '$t' => "123 Far Ln.\nAnywhere\nMO\n67891\nUnited States of America" },
379
- 'gd$city' => { '$t' => 'Anywhere' },
380
- 'gd$street' => { '$t' => '123 Far Ln.' }
381
- }
382
- ],
383
- 'gd$email' => [
384
- {
385
- 'primary' => 'true',
386
- 'rel' => 'http://schemas.google.com/g/2005#other',
387
- 'address' => 'johnsmith@example.com'
388
- }
389
- ],
390
- 'gd$phoneNumber' => [
391
- {
392
- 'primary' => 'true',
393
- '$t' => '(123) 334-5158',
394
- 'rel' => 'http://schemas.google.com/g/2005#mobile'
395
- }
396
- ],
397
- 'gd$organization' => [
398
- {
399
- 'gd$orgTitle' => { '$t' => 'Worker Person' },
400
- 'gd$orgName' => { '$t' => 'Example, Inc' },
401
- 'rel' => 'http://schemas.google.com/g/2005#other'
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
- }
413
- ]
414
- )
415
- end
416
-
417
- it 'should catch nil values for nested fields' do
418
- expect(@empty.nested_t_field_or_nil('gd$name', 'gd$givenName')).to be_nil
419
- expect(@partly_empty.nested_t_field_or_nil('gd$name', 'gd$givenName')).to be_nil
420
- expect(@contact_v3.nested_t_field_or_nil('gd$name', 'gd$givenName')).to eq('John')
421
- end
422
-
423
- it 'has given_name' do
424
- expect(@contact_v3.given_name).to eq('John')
425
- end
426
-
427
- it 'has family_name' do
428
- expect(@contact_v3.family_name).to eq('Doe')
429
- end
430
-
431
- it 'has full_name' do
432
- expect(@contact_v3).to receive(:nested_t_field_or_nil).with('gd$name', 'gd$fullName').and_return('val')
433
- expect(@contact_v3.full_name).to eq('val')
434
- end
435
-
436
- it 'has relations' do
437
- expect(@empty.relations).to eq([])
438
- expect(@partly_empty.relations).to eq([])
439
- expect(@contact_v3.relations).to eq([ { '$t' => 'Jane', 'rel' => 'spouse' } ])
440
- end
441
- it 'has spouse' do
442
- expect(@empty.spouse).to be_nil
443
- expect(@partly_empty.spouse).to be_nil
444
- expect(@contact_v3.spouse).to eq('Jane')
445
- end
446
-
447
- it 'has birthday' do
448
- expect(@empty.birthday).to be_nil
449
- expect(@contact_v3.birthday).to eq({ year: 1988, month: 5, day: 12 })
450
-
451
- contact_birthday_no_year = GoogleContactsApi::Contact.new('gContact$birthday' => { 'when' => '--05-12' })
452
- expect(contact_birthday_no_year.birthday).to eq({ year: nil, month: 5, day: 12 })
453
- end
454
-
455
- it 'has addresses' do
456
- expect(@empty.addresses).to eq([])
457
-
458
- formatted_addresses = [
459
- { rel: 'work', primary: false, country: 'United States of America', city: 'Somwhere', street: '2345 Long Dr. #232',
460
- region: 'IL', postcode: '12345' },
461
- { rel: 'home', primary: true, country: 'United States of America', city: 'Anywhere', street: '123 Far Ln.',
462
- region: nil, postcode: nil }
463
- ]
464
- expect(@contact_v3.addresses).to eq(formatted_addresses)
465
- end
466
-
467
- it 'has full phone numbers' do
468
- expect(@empty.phone_numbers_full).to eq([])
469
- expect(@contact_v3.phone_numbers_full).to eq([ { :primary => true, :number => '(123) 334-5158', :rel => 'mobile' } ])
470
- end
471
- it 'has full emails' do
472
- expect(@empty.emails_full).to eq([])
473
- expect(@contact_v3.emails_full).to eq([ { :primary => true, :address => 'johnsmith@example.com', :rel => 'other' } ])
474
- end
475
-
476
- it 'has organizations' do
477
- expect(@empty.organizations).to eq([])
478
-
479
- formatted_organizations = [
480
- {
481
- org_title: 'Worker Person',
482
- org_name: 'Example, Inc',
483
- primary: false,
484
- rel: 'other'
485
- }
486
- ]
487
- expect(@contact_v3.organizations).to eq(formatted_organizations)
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')
539
- end
540
- end
541
-
542
- describe GoogleContactsApi::Group do
543
- before(:all) do
544
- @group_json_hash = group_json_hash
545
- @group = GoogleContactsApi::Group.new(group_json_hash)
546
- end
547
- # ok, these tests are kind of silly
548
- it "should return the right title" do
549
- expect(@group.title).to eq("System Group: My Contacts")
550
- end
551
- it "should return the right id" do
552
- expect(@group.id).to eq("http://www.google.com/m8/feeds/groups/example%40gmail.com/base/6")
553
- end
554
- it "should return the right content" do
555
- # TODO: Nothing in source, oops
556
- expect(@group.content).to eq("System Group: My Contacts")
557
- end
558
- it "should return the right updated time" do
559
- # different representation slightly
560
- expect(@group.updated.to_s).to eq("1970-01-01T00:00:00+00:00")
561
- end
562
- it "should tell me if it's a system group" do
563
- expect(@group).to be_system_group
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
573
- describe ".contacts" do
574
- before(:each) do
575
- @api = double("api")
576
- @group = GoogleContactsApi::Group.new(@contact_json_hash, nil, @api)
577
- allow(@group).to receive(:id).and_return("group id")
578
- end
579
- it "should be able to get contacts" do
580
- expect(@group).to receive(:get_contacts).with(hash_including({"group" => "group id"})).and_return("contact set")
581
- expect(@group.contacts).to eq("contact set")
582
- end
583
- it "should use the contact cache for subsequent access" do
584
- expect(@group).to receive(:get_contacts).with(hash_including({"group" => "group id"})).and_return("contact set").once
585
- @group.contacts
586
- contacts = @group.contacts
587
- expect(contacts).to eq("contact set")
588
- end
589
- end
590
- describe ".contacts!" do
591
- before(:each) do
592
- @api = double("api")
593
- @group = GoogleContactsApi::Group.new(@contact_json_hash, nil, @api)
594
- allow(@group).to receive(:id).and_return("group id")
595
- end
596
- it "should be able to get contacts" do
597
- expect(@group).to receive(:get_contacts).with(hash_including({"group" => "group id"})).and_return("contact set")
598
- expect(@group.contacts!).to eq("contact set")
599
- end
600
- it "should use the contact cache for subsequent access" do
601
- expect(@group).to receive(:get_contacts).with(hash_including({"group" => "group id"})).and_return("contact set").twice
602
- @group.contacts
603
- contacts = @group.contacts!
604
- expect(contacts).to eq("contact set")
605
- end
606
- end
607
- end
608
- end