mirror-api 0.0.6 → 0.0.7

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/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
@@ -27,6 +27,10 @@ module Mirror
27
27
  do_verb(:put, json)
28
28
  end
29
29
 
30
+ def patch(json=false)
31
+ do_verb(:patch, json)
32
+ end
33
+
30
34
  def delete
31
35
  get_verb(:delete)
32
36
  end
@@ -44,7 +48,7 @@ module Mirror
44
48
  def handle_http_response(response, request, result, &block)
45
49
  @request = request
46
50
  case response.code
47
- when 422
51
+ when 400
48
52
  if @logger
49
53
  msg = "ERROR - Rejected #{request.inspect} to #{self.invoke_url} with params #{self.params}. Response is #{response.body}"
50
54
  @logger.error(msg)
@@ -113,7 +117,7 @@ module Mirror
113
117
 
114
118
  def do_verb(verb=:post, json=false)
115
119
  begin
116
- data = json ? self.params.to_json : self.params
120
+ data = json ? self.params : self.params.to_json
117
121
  @response = RestClient.send(verb, self.invoke_url, data, self.headers) do |response, request, result, &block|
118
122
  handle_http_response(response, request, result, &block)
119
123
  end
@@ -25,6 +25,10 @@ module Mirror
25
25
  def locations
26
26
  @locations ||= Resource.new(@credentials, Request::LOCATIONS)
27
27
  end
28
+
29
+ def contacts
30
+ @contacts ||= Resource.new(@credentials, Request::CONTACTS)
31
+ end
28
32
  end
29
33
  end
30
34
  end
@@ -8,6 +8,7 @@ module Mirror
8
8
  TIMELINE = "timeline"
9
9
  SUBSCRIPTIONS = "subscriptions"
10
10
  LOCATIONS = "locations"
11
+ CONTACTS = "contacts"
11
12
 
12
13
  def initialize(creds, options={})
13
14
  @resource = options[:resource] || TIMELINE
@@ -29,6 +29,10 @@ module Mirror
29
29
  Request.new(@credentials, item_options(id, params)).put
30
30
  end
31
31
 
32
+ def patch(id, params)
33
+ Request.new(@credentials, item_options(id, params)).patch
34
+ end
35
+
32
36
  def delete(id)
33
37
  Request.new(@credentials, item_options(id)).delete
34
38
  end
@@ -1,5 +1,5 @@
1
1
  module Mirror
2
2
  module Api
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -13,10 +13,11 @@ describe Mirror::Api::Client do
13
13
  context "with valid params" do
14
14
  before do
15
15
  @msg = "Hello world"
16
+ @body = {text: @msg}
16
17
 
17
18
  stub_request(:post, "https://www.googleapis.com/mirror/v1/timeline/").
18
- with(body: {text: @msg},
19
- headers: json_post_request_headers).
19
+ with(body: @body,
20
+ headers: json_post_request_headers(@body.to_json)).
20
21
  to_return(status: 200,
21
22
  body: fixture("timeline_item.json", true),
22
23
  headers: JSON.parse(fixture("timeline_item_response_headers.json", true)))
@@ -32,13 +33,12 @@ describe Mirror::Api::Client do
32
33
 
33
34
  context "with invalid params" do
34
35
  before do
35
- @msg = "Hello world"
36
-
37
- # TODO: Verify error code is 422
36
+ @msg = "123"
37
+ @body = {text: @msg}
38
38
  stub_request(:post, "https://www.googleapis.com/mirror/v1/timeline/").
39
- with(body: {random: "123"},
40
- headers: json_get_request_headers).
41
- to_return(status: 422, body: {}.to_json,
39
+ with(body: @body,
40
+ headers: json_post_request_headers(@body.to_json)).
41
+ to_return(status: 400, body: {}.to_json,
42
42
  headers: {})
43
43
  end
44
44
 
@@ -69,22 +69,22 @@ describe Mirror::Api::Client do
69
69
  headers: {})
70
70
  end
71
71
 
72
- it "should get the location for @id", :focus => true do
73
- location = @api.locations.get(@id)
74
- location.should_not be_nil
75
- location.displayName.should == "Home" # see fixture
72
+ it "should get the location for @id", :focus => true do
73
+ location = @api.locations.get(@id)
74
+ location.should_not be_nil
75
+ location.displayName.should == "Home" # see fixture
76
+ end
76
77
  end
77
- end
78
78
 
79
- context "with invalid params" do
80
- before do
81
- @id = "0987asdasds"
79
+ context "with invalid params" do
80
+ before do
81
+ @id = "0987asdasds"
82
+
83
+ stub_request(:get, "https://www.googleapis.com/mirror/v1/locations/").
84
+ with(headers: json_get_request_headers).
85
+ to_return(status: 404, body: {}.to_json,
86
+ headers: {})
82
87
 
83
- # TODO: Verify error code is 422
84
- stub_request(:get, "https://www.googleapis.com/mirror/v1/locations/").
85
- with(headers: json_post_request_headers).
86
- to_return(status: 422, body: {}.to_json,
87
- headers: {})
88
88
  end
89
89
 
90
90
  it "should not get the item" do
@@ -92,8 +92,9 @@ describe Mirror::Api::Client do
92
92
  item = @api.timeline.create({random: "123"})
93
93
  item.should be_nil
94
94
  end
95
- end
96
- end
95
+ end
96
+ end
97
+
97
98
  describe "list" do
98
99
 
99
100
  context "with valid params" do
@@ -106,7 +107,7 @@ describe Mirror::Api::Client do
106
107
  headers: {})
107
108
  end
108
109
 
109
- it "should return a list of ids", :focus => true do
110
+ it "should return a list of locations", :focus => true do
110
111
  locations = @api.locations.list()
111
112
  locations.should_not be_nil
112
113
  locations.items.count.should == 2 # see fixture
@@ -115,14 +116,225 @@ describe Mirror::Api::Client do
115
116
  end
116
117
  end
117
118
 
119
+ describe "contacts" do
120
+
121
+ describe "delete" do
122
+ context "with valid params" do
123
+ before do
124
+ @id = "123123312"
125
+ stub_request(:delete, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
126
+ with(headers: json_get_request_headers).
127
+ to_return(status: 200,
128
+ body: {},
129
+ headers: {})
130
+ end
131
+ it "should return nil" do
132
+ contact = @api.contacts.delete(@id)
133
+ contact.should == nil
134
+ end
135
+ end
136
+
137
+ context "with invalid params" do
138
+ before do
139
+ @id = "blah"
140
+ stub_request(:delete, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
141
+ with(headers: json_get_request_headers).
142
+ to_return(status: 422,
143
+ body: {},
144
+ headers: {})
145
+ end
146
+ it "should return nil" do
147
+ contact = @api.contacts.delete(@id)
148
+ contact.should == nil
149
+ end
150
+ end
151
+
152
+ end
153
+
154
+ describe "get" do
155
+
156
+ context "with valid params" do
157
+ before do
158
+ @id = "0987"
159
+
160
+ stub_request(:get, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
161
+ with(headers: json_get_request_headers).
162
+ to_return(status: 200,
163
+ body: fixture("contacts_item.json", true),
164
+ headers: {})
165
+ end
166
+ it "should return a contact with .kind == 'mirror#contact'" do
167
+ contact = @api.contacts.get(@id)
168
+ contact.kind.should == 'mirror#contact'
169
+ end
170
+ end
171
+
172
+ context "with invalid params" do
173
+ before do
174
+ @id = "bad_id"
175
+
176
+ stub_request(:get, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
177
+ with(headers: json_get_request_headers).
178
+ to_return(status: 404,
179
+ body: fixture("contacts_item.json", true),
180
+ headers: {})
181
+ end
182
+ it "should return nil" do
183
+ contact = @api.contacts.get(@id)
184
+ contact.should == nil
185
+ end
186
+ end
187
+
188
+ end
189
+
190
+ describe "insert" do
191
+
192
+ context "with valid params" do
193
+ before do
194
+ @body = {id: '1234', displayName: 'Demo App', imageUrls: ["http://pixelr3ap3r.com/wp-content/uploads/2012/08/357c6328ee4b11e1bfbf22000a1c91a7_7.jpg"]}
195
+
196
+ stub_request(:post, "https://www.googleapis.com/mirror/v1/contacts/").
197
+ with(body: @body,
198
+ headers: json_post_request_headers(@body.to_json)).
199
+ to_return(status: 200,
200
+ body: fixture("contacts_item.json", true),
201
+ headers: {})
202
+ end
203
+ it "should return a contact with .kind == 'mirror#contact'" do
204
+ contact = @api.contacts.insert(@body)
205
+ contact.kind.should == 'mirror#contact'
206
+ end
207
+ end
118
208
 
119
- def json_post_request_headers
209
+ context "with invalid params" do
210
+ before do
211
+ @body = {canIHazContact: "Really you thought that was valid?!"}
212
+
213
+ stub_request(:post, "https://www.googleapis.com/mirror/v1/contacts/").
214
+ with(body: @body,
215
+ headers: json_post_request_headers(@body.to_json)).
216
+ to_return(status: 404,
217
+ body: {},
218
+ headers: {})
219
+ end
220
+ it "should return nil" do
221
+ contact = @api.contacts.insert(@body)
222
+ contact.should == nil
223
+ end
224
+ end
225
+
226
+ end
227
+
228
+ describe "list" do
229
+
230
+ context "with valid params" do
231
+ before do
232
+
233
+ stub_request(:get, "https://www.googleapis.com/mirror/v1/contacts/").
234
+ with(headers: json_get_request_headers).
235
+ to_return(status: 200,
236
+ body: fixture("contacts_list.json", true),
237
+ headers: {})
238
+ end
239
+
240
+ it "should return a list of contacts" do
241
+ contacts = @api.contacts.list()
242
+ contacts.should_not be_nil
243
+ contacts.items.count.should == 2 # see fixture
244
+ end
245
+ end
246
+
247
+ end
248
+
249
+ describe "patch" do
250
+
251
+ context "with valid params" do
252
+ before do
253
+ @id = '1234'
254
+ @body = {displayName: 'Demo App'}
255
+
256
+ stub_request(:patch, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
257
+ with(body: @body,
258
+ headers: json_post_request_headers(@body.to_json)).
259
+ to_return(status: 200,
260
+ body: fixture("contacts_item.json", true),
261
+ headers: {})
262
+ end
263
+ it "should return a contact with .kind == 'mirror#contact'" do
264
+ contact = @api.contacts.patch(@id, @body)
265
+ contact.kind.should == 'mirror#contact'
266
+ end
267
+ end
268
+
269
+ context "with invalid params" do
270
+ before do
271
+ @id = '1234'
272
+ @body = {derp: 'troll'}
273
+
274
+ stub_request(:patch, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
275
+ with(body: @body,
276
+ headers: json_post_request_headers(@body.to_json)).
277
+ to_return(status: 400,
278
+ body: {},
279
+ headers: {})
280
+ end
281
+ it "should return nil" do
282
+ contact = @api.contacts.patch(@id, @body)
283
+ contact.should == nil
284
+ end
285
+ end
286
+
287
+ end
288
+
289
+ describe "update" do
290
+
291
+ context "with valid params" do
292
+ before do
293
+ @id = '1234'
294
+ @body = {displayName: 'Demo App'}
295
+
296
+ stub_request(:put, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
297
+ with(body: @body,
298
+ headers: json_post_request_headers(@body.to_json)).
299
+ to_return(status: 200,
300
+ body: fixture("contacts_item.json", true),
301
+ headers: {})
302
+ end
303
+ it "should return a contact with .kind == 'mirror#contact'" do
304
+ contact = @api.contacts.update(@id, @body)
305
+ contact.kind.should == 'mirror#contact'
306
+ end
307
+ end
308
+
309
+ context "with invalid params" do
310
+ before do
311
+ @id = '1234'
312
+ @body = {derp: 'troll'}
313
+
314
+ stub_request(:put, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
315
+ with(body: @body,
316
+ headers: json_post_request_headers(@body.to_json)).
317
+ to_return(status: 400,
318
+ body: {},
319
+ headers: {})
320
+ end
321
+ it "should return nil" do
322
+ contact = @api.contacts.update(@id, @body)
323
+ contact.should == nil
324
+ end
325
+ end
326
+
327
+ end
328
+
329
+ end
330
+
331
+ def json_post_request_headers(body)
120
332
  {
121
333
  'Accept'=>'application/json',
122
334
  'Accept-Encoding'=>'gzip, deflate',
123
335
  'Authorization'=>"Bearer #{@token}",
124
- 'Content-Length'=>/\d+/,
125
- 'Content-Type'=>'application/x-www-form-urlencoded',
336
+ 'Content-Length'=>body.length.to_s,
337
+ 'Content-Type'=>'application/json',
126
338
  'User-Agent'=>'Ruby'
127
339
  }
128
340
  end
@@ -0,0 +1,14 @@
1
+ {
2
+ "kind": "mirror#contact",
3
+ "source": "demo_app",
4
+ "id": "1234",
5
+ "displayName": "Demo App",
6
+ "imageUrls": [
7
+ "http://pixelr3ap3r.com/wp-content/uploads/2012/08/357c6328ee4b11e1bfbf22000a1c91a7_7.jpg"
8
+ ],
9
+ "type": "INDIVIDUAL",
10
+ "acceptTypes": [
11
+ ],
12
+ "phoneNumber": "1234345587",
13
+ "priority": 1
14
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "kind": "mirror#contacts",
3
+ "items": [
4
+ {
5
+ "kind": "mirror#contact",
6
+ "source": "demo_app",
7
+ "id": "1234",
8
+ "displayName": "Demo App",
9
+ "imageUrls": [
10
+ "http://pixelr3ap3r.com/wp-content/uploads/2012/08/357c6328ee4b11e1bfbf22000a1c91a7_7.jpg"
11
+ ],
12
+ "type": "INDIVIDUAL",
13
+ "acceptTypes": [
14
+ ],
15
+ "phoneNumber": "1234345587",
16
+ "priority": 1
17
+ },
18
+ {
19
+ "kind": "mirror#contact",
20
+ "source": "demo_app2",
21
+ "id": "0987",
22
+ "displayName": "Demo App 2",
23
+ "imageUrls": [
24
+ "http://pixelr3ap3r.com/wp-content/uploads/2012/08/357c6328ee4b11e1bfbf22000a1c91a7_7.jpg"
25
+ ],
26
+ "type": "GROUP",
27
+ "acceptTypes": [
28
+ ],
29
+ "phoneNumber": "1234345587",
30
+ "priority": 2
31
+ }
32
+ ]
33
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mirror-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-24 00:00:00.000000000 Z
13
+ date: 2013-04-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -211,6 +211,8 @@ files:
211
211
  - lib/mirror-api/version.rb
212
212
  - mirror-api.gemspec
213
213
  - spec/client_spec.rb
214
+ - spec/fixtures/contacts_item.json
215
+ - spec/fixtures/contacts_list.json
214
216
  - spec/fixtures/locations_item.json
215
217
  - spec/fixtures/locations_list.json
216
218
  - spec/fixtures/timeline_item.json
@@ -242,6 +244,8 @@ specification_version: 3
242
244
  summary: https://developers.google.com/glass/v1/reference/
243
245
  test_files:
244
246
  - spec/client_spec.rb
247
+ - spec/fixtures/contacts_item.json
248
+ - spec/fixtures/contacts_list.json
245
249
  - spec/fixtures/locations_item.json
246
250
  - spec/fixtures/locations_list.json
247
251
  - spec/fixtures/timeline_item.json