google_contacts_api 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +15 -6
- data/VERSION +1 -1
- data/google_contacts_api.gemspec +3 -1
- data/lib/google_contacts_api/api.rb +3 -0
- data/spec/contact_set.json +1096 -0
- data/spec/google_contacts_api_spec.rb +192 -3
- data/spec/group_set.json +213 -0
- data/spec/spec_helper.rb +26 -2
- metadata +4 -2
@@ -1,7 +1,196 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
|
3
|
+
describe "GoogleContactsApi" do
|
4
|
+
describe "Api" do
|
5
|
+
before(:each) do
|
6
|
+
@oauth = double("oauth")
|
7
|
+
@oauth.stub(:get).and_return("get response")
|
8
|
+
@api = GoogleContactsApi::Api.new(@oauth)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should perform a get request using oauth returning json" do
|
12
|
+
# expectation should come before execution
|
13
|
+
@oauth.should_receive(:get).with(
|
14
|
+
GoogleContactsApi::Api::BASE_URL + "any_url?alt=json¶m=param", {"header" => "header"})
|
15
|
+
@api.get("any_url",
|
16
|
+
{"param" => "param"},
|
17
|
+
{"header" => "header"}).should == ("get response")
|
18
|
+
end
|
19
|
+
# Not implemented yet
|
20
|
+
pending "should perform a post request using oauth"
|
21
|
+
pending "should perform a put request using oauth"
|
22
|
+
pending "should perform a delete request using oauth"
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "User" do
|
26
|
+
before(:each) do
|
27
|
+
@oauth = double("oauth")
|
28
|
+
@user = GoogleContactsApi::User.new(@oauth)
|
29
|
+
@user.api.stub(:get).and_return(Hashie::Mash.new({
|
30
|
+
"body" => "some response", # could use example response here
|
31
|
+
"code" => 200
|
32
|
+
}))
|
33
|
+
GoogleContactsApi::GroupSet.stub(:new).and_return("group set")
|
34
|
+
GoogleContactsApi::ContactSet.stub(:new).and_return("contact set")
|
35
|
+
end
|
36
|
+
# Should hit the right URLs and return the right stuff
|
37
|
+
it "should be able to get groups" do
|
38
|
+
@user.api.should_receive(:get).with("groups/default/full", anything, {"GData-Version" => "2"})
|
39
|
+
@user.groups.should == "group set"
|
40
|
+
end
|
41
|
+
it "should be able to get contacts" do
|
42
|
+
@user.api.should_receive(:get).with("contacts/default/full", anything)
|
43
|
+
@user.contacts.should == "contact set"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "ResultSet" do
|
48
|
+
# no testing, it's just an implementation detail to use inheritance
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "ContactSet" do
|
52
|
+
before(:all) do
|
53
|
+
@contact_set_json = contact_set_json
|
54
|
+
@contact_set = GoogleContactsApi::ContactSet.new(@contact_set_json)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return the right starting index" do
|
58
|
+
@contact_set.start_index.should == 1
|
59
|
+
end
|
60
|
+
it "should return the right number of results per page" do
|
61
|
+
@contact_set.items_per_page.should == 25
|
62
|
+
end
|
63
|
+
it "should return the right number of total results" do
|
64
|
+
@contact_set.total_results.should == 500
|
65
|
+
end
|
66
|
+
it "should tell me if there are more results" do
|
67
|
+
# yeah this is an awkward assertion and matcher
|
68
|
+
@contact_set.should be_has_more
|
69
|
+
@contact_set.has_more?.should == true
|
70
|
+
end
|
71
|
+
it "should parse results into Contacts" do
|
72
|
+
@contact_set.to_a.first.should be_instance_of(GoogleContactsApi::Contact)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "GroupSet" do
|
77
|
+
before(:all) do
|
78
|
+
@group_set_json = group_set_json
|
79
|
+
@group_set = GoogleContactsApi::GroupSet.new(@group_set_json)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return the right starting index" do
|
83
|
+
@group_set.start_index.should == 1
|
84
|
+
end
|
85
|
+
it "should return the right number of results per page" do
|
86
|
+
@group_set.items_per_page.should == 25
|
87
|
+
end
|
88
|
+
it "should return the right number of total results" do
|
89
|
+
@group_set.total_results.should == 5
|
90
|
+
end
|
91
|
+
it "should tell me if there are more results" do
|
92
|
+
# yeah this is an awkward assertion and matcher
|
93
|
+
@group_set.should_not be_has_more
|
94
|
+
@group_set.has_more?.should == false
|
95
|
+
end
|
96
|
+
it "should parse results into Groups" do
|
97
|
+
@group_set.to_a.first.should be_instance_of(GoogleContactsApi::Group)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "Result" do
|
102
|
+
# no testing, it's just an implementation detail to inherit
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "Contact" do
|
106
|
+
before(:all) do
|
107
|
+
@contact_json_hash = contact_json_hash
|
108
|
+
@contact = GoogleContactsApi::Contact.new(@contact_json_hash)
|
109
|
+
end
|
110
|
+
# ok, these tests are kind of silly
|
111
|
+
it "should return the right title" do
|
112
|
+
@contact.title.should == "Contact 1"
|
113
|
+
end
|
114
|
+
it "should return the right id" do
|
115
|
+
@contact.id.should == "http://www.google.com/m8/feeds/contacts/example%40gmail.com/base/0"
|
116
|
+
end
|
117
|
+
it "should return the right content" do
|
118
|
+
# TODO: Nothing in source, oops
|
119
|
+
@contact.content.should == nil
|
120
|
+
end
|
121
|
+
it "should return the right updated time" do
|
122
|
+
# different representation slightly
|
123
|
+
@contact.updated.to_s.should == "2011-07-07T21:02:42+00:00"
|
124
|
+
end
|
125
|
+
it "should return the right self link" do
|
126
|
+
@contact.self_link.should == "https://www.google.com/m8/feeds/contacts/example%40gmail.com/full/0"
|
127
|
+
end
|
128
|
+
it "should return the right photo link" do
|
129
|
+
@contact.photo_link.should == "https://www.google.com/m8/feeds/photos/media/example%40gmail.com/0"
|
130
|
+
end
|
131
|
+
it "should return the right edit link" do
|
132
|
+
@contact.edit_link.should == "https://www.google.com/m8/feeds/contacts/example%40gmail.com/full/0"
|
133
|
+
end
|
134
|
+
it "should return the right edit photo link" do
|
135
|
+
# TODO: there isn't one in this contact, hahah
|
136
|
+
@contact.edit_photo_link.should == nil
|
137
|
+
end
|
138
|
+
it "should try to fetch a photo" do
|
139
|
+
@oauth = mock("oauth")
|
140
|
+
@oauth.stub(:get).and_return(Hashie::Mash.new({
|
141
|
+
"body" => "some response", # could use example response here
|
142
|
+
"code" => 200
|
143
|
+
}))
|
144
|
+
# @api = GoogleContactsApi::Api.new(@oauth)
|
145
|
+
@api = mock("api")
|
146
|
+
@api.stub(:oauth).and_return(@oauth)
|
147
|
+
@contact = GoogleContactsApi::Contact.new(@contact_json_hash, nil, @api)
|
148
|
+
@oauth.should_receive("get").with(@contact.photo_link)
|
149
|
+
@contact.photo
|
150
|
+
end
|
151
|
+
it "should return all e-mail addresses" do
|
152
|
+
@contact.emails.should == ["contact1@example.com"]
|
153
|
+
end
|
154
|
+
it "should return the right primary e-mail address" do
|
155
|
+
@contact.primary_email.should == "contact1@example.com"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "Group" do
|
160
|
+
before(:all) do
|
161
|
+
@group_json_hash = group_json_hash
|
162
|
+
@group = GoogleContactsApi::Group.new(group_json_hash)
|
163
|
+
end
|
164
|
+
# ok, these tests are kind of silly
|
165
|
+
it "should return the right title" do
|
166
|
+
@group.title.should == "System Group: My Contacts"
|
167
|
+
end
|
168
|
+
it "should return the right id" do
|
169
|
+
@group.id.should == "http://www.google.com/m8/feeds/groups/example%40gmail.com/base/6"
|
170
|
+
end
|
171
|
+
it "should return the right content" do
|
172
|
+
# TODO: Nothing in source, oops
|
173
|
+
@group.content.should == "System Group: My Contacts"
|
174
|
+
end
|
175
|
+
it "should return the right updated time" do
|
176
|
+
# different representation slightly
|
177
|
+
@group.updated.to_s.should == "1970-01-01T00:00:00+00:00"
|
178
|
+
end
|
179
|
+
it "should tell me if it's a system group" do
|
180
|
+
@group.should be_system_group
|
181
|
+
end
|
182
|
+
it "should get contacts from the group and cache them" do
|
183
|
+
@api = mock("api")
|
184
|
+
@api.stub(:get).and_return(Hashie::Mash.new({
|
185
|
+
"body" => "some response", # could use example response here
|
186
|
+
"code" => 200
|
187
|
+
}))
|
188
|
+
GoogleContactsApi::ContactSet.stub(:new).and_return("contact set")
|
189
|
+
@group = GoogleContactsApi::Group.new(@contact_json_hash, nil, @api)
|
190
|
+
@api.should_receive("get").with(an_instance_of(String),
|
191
|
+
hash_including({"group" => @group.id})).once
|
192
|
+
@group.contacts
|
193
|
+
@group.contacts
|
194
|
+
end
|
6
195
|
end
|
7
196
|
end
|
data/spec/group_set.json
ADDED
@@ -0,0 +1,213 @@
|
|
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": "5"
|
64
|
+
},
|
65
|
+
"openSearch$startIndex": {
|
66
|
+
"$t": "1"
|
67
|
+
},
|
68
|
+
"openSearch$itemsPerPage": {
|
69
|
+
"$t": "25"
|
70
|
+
},
|
71
|
+
"entry": [{
|
72
|
+
"gd$etag": "\"YDwqeyI.\"",
|
73
|
+
"id": {
|
74
|
+
"$t": "http://www.google.com/m8/feeds/groups/example%40gmail.com/base/6"
|
75
|
+
},
|
76
|
+
"updated": {
|
77
|
+
"$t": "1970-01-01T00:00:00.000Z"
|
78
|
+
},
|
79
|
+
"category": [{
|
80
|
+
"scheme": "http://schemas.google.com/g/2005#kind",
|
81
|
+
"term": "http://schemas.google.com/contact/2008#group"
|
82
|
+
}],
|
83
|
+
"title": {
|
84
|
+
"$t": "System Group: My Contacts"
|
85
|
+
},
|
86
|
+
"content": {
|
87
|
+
"$t": "System Group: My Contacts"
|
88
|
+
},
|
89
|
+
"link": [{
|
90
|
+
"rel": "self",
|
91
|
+
"type": "application/atom+xml",
|
92
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full/6"
|
93
|
+
}],
|
94
|
+
"gContact$systemGroup": {
|
95
|
+
"id": "Contacts"
|
96
|
+
}
|
97
|
+
},
|
98
|
+
{
|
99
|
+
"gd$etag": "\"YDwqeyI.\"",
|
100
|
+
"id": {
|
101
|
+
"$t": "http://www.google.com/m8/feeds/groups/example%40gmail.com/base/d"
|
102
|
+
},
|
103
|
+
"updated": {
|
104
|
+
"$t": "1970-01-01T00:00:00.000Z"
|
105
|
+
},
|
106
|
+
"category": [{
|
107
|
+
"scheme": "http://schemas.google.com/g/2005#kind",
|
108
|
+
"term": "http://schemas.google.com/contact/2008#group"
|
109
|
+
}],
|
110
|
+
"title": {
|
111
|
+
"$t": "System Group: Friends"
|
112
|
+
},
|
113
|
+
"content": {
|
114
|
+
"$t": "System Group: Friends"
|
115
|
+
},
|
116
|
+
"link": [{
|
117
|
+
"rel": "self",
|
118
|
+
"type": "application/atom+xml",
|
119
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full/d"
|
120
|
+
}],
|
121
|
+
"gContact$systemGroup": {
|
122
|
+
"id": "Friends"
|
123
|
+
}
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"gd$etag": "\"YDwqeyI.\"",
|
127
|
+
"id": {
|
128
|
+
"$t": "http://www.google.com/m8/feeds/groups/example%40gmail.com/base/e"
|
129
|
+
},
|
130
|
+
"updated": {
|
131
|
+
"$t": "1970-01-01T00:00:00.000Z"
|
132
|
+
},
|
133
|
+
"category": [{
|
134
|
+
"scheme": "http://schemas.google.com/g/2005#kind",
|
135
|
+
"term": "http://schemas.google.com/contact/2008#group"
|
136
|
+
}],
|
137
|
+
"title": {
|
138
|
+
"$t": "System Group: Family"
|
139
|
+
},
|
140
|
+
"content": {
|
141
|
+
"$t": "System Group: Family"
|
142
|
+
},
|
143
|
+
"link": [{
|
144
|
+
"rel": "self",
|
145
|
+
"type": "application/atom+xml",
|
146
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full/e"
|
147
|
+
}],
|
148
|
+
"gContact$systemGroup": {
|
149
|
+
"id": "Family"
|
150
|
+
}
|
151
|
+
},
|
152
|
+
{
|
153
|
+
"gd$etag": "\"YDwqeyI.\"",
|
154
|
+
"id": {
|
155
|
+
"$t": "http://www.google.com/m8/feeds/groups/example%40gmail.com/base/f"
|
156
|
+
},
|
157
|
+
"updated": {
|
158
|
+
"$t": "1970-01-01T00:00:00.000Z"
|
159
|
+
},
|
160
|
+
"category": [{
|
161
|
+
"scheme": "http://schemas.google.com/g/2005#kind",
|
162
|
+
"term": "http://schemas.google.com/contact/2008#group"
|
163
|
+
}],
|
164
|
+
"title": {
|
165
|
+
"$t": "System Group: Coworkers"
|
166
|
+
},
|
167
|
+
"content": {
|
168
|
+
"$t": "System Group: Coworkers"
|
169
|
+
},
|
170
|
+
"link": [{
|
171
|
+
"rel": "self",
|
172
|
+
"type": "application/atom+xml",
|
173
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full/f"
|
174
|
+
}],
|
175
|
+
"gContact$systemGroup": {
|
176
|
+
"id": "Coworkers"
|
177
|
+
}
|
178
|
+
},
|
179
|
+
{
|
180
|
+
"gd$etag": "\"Q3c4fjVSLyp7ImA9WB9VEE4PRgQ.\"",
|
181
|
+
"id": {
|
182
|
+
"$t": "http://www.google.com/m8/feeds/groups/example%40gmail.com/base/270f"
|
183
|
+
},
|
184
|
+
"updated": {
|
185
|
+
"$t": "2007-11-25T23:58:22.936Z"
|
186
|
+
},
|
187
|
+
"app$edited": {
|
188
|
+
"xmlns$app": "http://www.w3.org/2007/app",
|
189
|
+
"$t": "2007-11-25T23:58:22.936Z"
|
190
|
+
},
|
191
|
+
"category": [{
|
192
|
+
"scheme": "http://schemas.google.com/g/2005#kind",
|
193
|
+
"term": "http://schemas.google.com/contact/2008#group"
|
194
|
+
}],
|
195
|
+
"title": {
|
196
|
+
"$t": "Non-system Group"
|
197
|
+
},
|
198
|
+
"content": {
|
199
|
+
"$t": "Non-system Group"
|
200
|
+
},
|
201
|
+
"link": [{
|
202
|
+
"rel": "self",
|
203
|
+
"type": "application/atom+xml",
|
204
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full/270f"
|
205
|
+
},
|
206
|
+
{
|
207
|
+
"rel": "edit",
|
208
|
+
"type": "application/atom+xml",
|
209
|
+
"href": "https://www.google.com/m8/feeds/groups/example%40gmail.com/full/270f"
|
210
|
+
}]
|
211
|
+
}]
|
212
|
+
}
|
213
|
+
}
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,36 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
require 'rspec'
|
4
|
+
require 'json'
|
5
|
+
require 'hashie'
|
4
6
|
require 'google_contacts_api'
|
5
7
|
|
6
8
|
# Requires supporting files with custom matchers and macros, etc,
|
7
9
|
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
# Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
11
|
|
10
12
|
RSpec.configure do |config|
|
11
|
-
|
13
|
+
config.mock_framework = :rspec
|
12
14
|
end
|
15
|
+
|
16
|
+
def contact_set_json
|
17
|
+
f = File.open("#{File.dirname(__FILE__)}/contact_set.json")
|
18
|
+
json = f.read
|
19
|
+
f.close
|
20
|
+
json
|
21
|
+
end
|
22
|
+
|
23
|
+
def group_set_json
|
24
|
+
f = File.open("#{File.dirname(__FILE__)}/group_set.json")
|
25
|
+
json = f.read
|
26
|
+
f.close
|
27
|
+
json
|
28
|
+
end
|
29
|
+
|
30
|
+
def contact_json_hash
|
31
|
+
Hashie::Mash.new(JSON.parse(contact_set_json)).feed.entry.first
|
32
|
+
end
|
33
|
+
|
34
|
+
def group_json_hash
|
35
|
+
Hashie::Mash.new(JSON.parse(group_set_json)).feed.entry.first
|
36
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: google_contacts_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alvin Liang
|
@@ -139,7 +139,9 @@ files:
|
|
139
139
|
- lib/google_contacts_api/result.rb
|
140
140
|
- lib/google_contacts_api/result_set.rb
|
141
141
|
- lib/google_contacts_api/user.rb
|
142
|
+
- spec/contact_set.json
|
142
143
|
- spec/google_contacts_api_spec.rb
|
144
|
+
- spec/group_set.json
|
143
145
|
- spec/spec_helper.rb
|
144
146
|
has_rdoc: true
|
145
147
|
homepage: http://github.com/aliang/google_contacts_api
|
@@ -155,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
157
|
requirements:
|
156
158
|
- - ">="
|
157
159
|
- !ruby/object:Gem::Version
|
158
|
-
hash:
|
160
|
+
hash: 2324905511123203107
|
159
161
|
segments:
|
160
162
|
- 0
|
161
163
|
version: "0"
|