mirror-api 0.0.7 → 0.0.8
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/lib/mirror-api/request.rb +12 -1
- data/lib/mirror-api/resource.rb +15 -5
- data/lib/mirror-api/version.rb +1 -1
- data/spec/client_spec.rb +138 -7
- data/spec/fixtures/files/fry.png +0 -0
- data/spec/fixtures/timeline_item_attachments_item.json +6 -0
- data/spec/fixtures/timeline_item_attachments_list.json +18 -0
- metadata +8 -2
data/lib/mirror-api/request.rb
CHANGED
@@ -20,7 +20,18 @@ module Mirror
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def invoke_url
|
23
|
-
@invoke_url
|
23
|
+
return @invoke_url unless @invoke_url.nil?
|
24
|
+
@invoke_url ="#{self.host}/mirror/v1/#{@resource}/#{@id ? @id : ''}"
|
25
|
+
@invoke_url += "/attachments/#{attachment_id ? attachment_id : ''}" if attachments
|
26
|
+
@invoke_url
|
27
|
+
end
|
28
|
+
|
29
|
+
def attachment_id
|
30
|
+
attachments[:id] if attachments
|
31
|
+
end
|
32
|
+
|
33
|
+
def attachments
|
34
|
+
params[:attachments] if params
|
24
35
|
end
|
25
36
|
|
26
37
|
def params
|
data/lib/mirror-api/resource.rb
CHANGED
@@ -11,12 +11,13 @@ module Mirror
|
|
11
11
|
raise "Invalid credentials #{credentials}" unless @credentials
|
12
12
|
end
|
13
13
|
|
14
|
-
def list(
|
15
|
-
|
14
|
+
def list(*args)
|
15
|
+
handle_list(args)
|
16
|
+
|
16
17
|
end
|
17
18
|
|
18
19
|
def create(params)
|
19
|
-
Request.new(@credentials, make_options(params
|
20
|
+
Request.new(@credentials, make_options(params)).post
|
20
21
|
end
|
21
22
|
alias insert create
|
22
23
|
|
@@ -33,8 +34,8 @@ module Mirror
|
|
33
34
|
Request.new(@credentials, item_options(id, params)).patch
|
34
35
|
end
|
35
36
|
|
36
|
-
def delete(id)
|
37
|
-
Request.new(@credentials, item_options(id)).delete
|
37
|
+
def delete(id, params=nil)
|
38
|
+
Request.new(@credentials, item_options(id, params)).delete
|
38
39
|
end
|
39
40
|
|
40
41
|
private
|
@@ -45,6 +46,15 @@ module Mirror
|
|
45
46
|
def item_options(id, params=nil, status=200)
|
46
47
|
{:resource => @resource_name, :id => id, :params => params, :expected_response => status}
|
47
48
|
end
|
49
|
+
|
50
|
+
def handle_list(args)
|
51
|
+
if args.first.is_a?(String)
|
52
|
+
Request.new(@credentials, item_options(args[0], args[1])).get
|
53
|
+
else
|
54
|
+
Request.new(@credentials, make_options(args[0])).get
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
data/lib/mirror-api/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Mirror::Api::Client do
|
|
23
23
|
headers: JSON.parse(fixture("timeline_item_response_headers.json", true)))
|
24
24
|
end
|
25
25
|
|
26
|
-
it "should insert plain text items"
|
26
|
+
it "should insert plain text items" do
|
27
27
|
item = @api.timeline.create({text: @msg})
|
28
28
|
item.should_not be_nil
|
29
29
|
item.created.should == "2012-09-25T23:28:43.192Z" # see fixture
|
@@ -34,7 +34,7 @@ describe Mirror::Api::Client do
|
|
34
34
|
context "with invalid params" do
|
35
35
|
before do
|
36
36
|
@msg = "123"
|
37
|
-
@body = {
|
37
|
+
@body = {random: @msg}
|
38
38
|
stub_request(:post, "https://www.googleapis.com/mirror/v1/timeline/").
|
39
39
|
with(body: @body,
|
40
40
|
headers: json_post_request_headers(@body.to_json)).
|
@@ -44,7 +44,7 @@ describe Mirror::Api::Client do
|
|
44
44
|
|
45
45
|
it "should not insert the item" do
|
46
46
|
|
47
|
-
item = @api.timeline.create(
|
47
|
+
item = @api.timeline.create(@body)
|
48
48
|
item.should be_nil
|
49
49
|
end
|
50
50
|
|
@@ -69,7 +69,7 @@ describe Mirror::Api::Client do
|
|
69
69
|
headers: {})
|
70
70
|
end
|
71
71
|
|
72
|
-
it "should get the location for @id"
|
72
|
+
it "should get the location for @id" do
|
73
73
|
location = @api.locations.get(@id)
|
74
74
|
location.should_not be_nil
|
75
75
|
location.displayName.should == "Home" # see fixture
|
@@ -89,7 +89,7 @@ describe Mirror::Api::Client do
|
|
89
89
|
|
90
90
|
it "should not get the item" do
|
91
91
|
|
92
|
-
item = @api.timeline.
|
92
|
+
item = @api.timeline.get(@id)
|
93
93
|
item.should be_nil
|
94
94
|
end
|
95
95
|
end
|
@@ -107,7 +107,7 @@ describe Mirror::Api::Client do
|
|
107
107
|
headers: {})
|
108
108
|
end
|
109
109
|
|
110
|
-
it "should return a list of locations"
|
110
|
+
it "should return a list of locations" do
|
111
111
|
locations = @api.locations.list()
|
112
112
|
locations.should_not be_nil
|
113
113
|
locations.items.count.should == 2 # see fixture
|
@@ -139,7 +139,7 @@ describe Mirror::Api::Client do
|
|
139
139
|
@id = "blah"
|
140
140
|
stub_request(:delete, "https://www.googleapis.com/mirror/v1/contacts/#{@id}").
|
141
141
|
with(headers: json_get_request_headers).
|
142
|
-
to_return(status:
|
142
|
+
to_return(status: 400,
|
143
143
|
body: {},
|
144
144
|
headers: {})
|
145
145
|
end
|
@@ -328,6 +328,137 @@ describe Mirror::Api::Client do
|
|
328
328
|
|
329
329
|
end
|
330
330
|
|
331
|
+
describe "timeline attachments" do
|
332
|
+
|
333
|
+
context "delete" do
|
334
|
+
context "with valid params" do
|
335
|
+
before do
|
336
|
+
@timeline_id = "1234"
|
337
|
+
@attachment_id = "123123312"
|
338
|
+
stub_request(:delete, "https://www.googleapis.com/mirror/v1/timeline/#{@timeline_id}/attachments/#{@attachment_id}").
|
339
|
+
with(headers: json_get_request_headers).
|
340
|
+
to_return(status: 200,
|
341
|
+
body: {},
|
342
|
+
headers: {})
|
343
|
+
end
|
344
|
+
it "should return nil" do
|
345
|
+
timeline_attachment = @api.timeline.delete(@timeline_id, {attachments:{id: @attachment_id}})
|
346
|
+
timeline_attachment.should == nil
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
context "with invalid params" do
|
351
|
+
before do
|
352
|
+
@timeline_id = "1234"
|
353
|
+
@attachment_id = "blah"
|
354
|
+
stub_request(:delete, "https://www.googleapis.com/mirror/v1/timeline/#{@timeline_id}/attachments/#{@attachment_id}").
|
355
|
+
with(headers: json_get_request_headers).
|
356
|
+
to_return(status: 400,
|
357
|
+
body: {},
|
358
|
+
headers: {})
|
359
|
+
end
|
360
|
+
it "should return nil" do
|
361
|
+
timeline_attachment = @api.timeline.delete(@timeline_id, {attachments:{id: @attachment_id}})
|
362
|
+
timeline_attachment.should == nil
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
context "get" do
|
368
|
+
context "with valid params" do
|
369
|
+
before do
|
370
|
+
@timeline_id = "1234"
|
371
|
+
@attachment_id = "123123312"
|
372
|
+
stub_request(:get, "https://www.googleapis.com/mirror/v1/timeline/#{@timeline_id}/attachments/#{@attachment_id}").
|
373
|
+
with(headers: json_get_request_headers).
|
374
|
+
to_return(status: 200,
|
375
|
+
body: fixture("timeline_item_attachments_item.json", true),
|
376
|
+
headers: {})
|
377
|
+
end
|
378
|
+
it "should return timeline_attachment with id '1234'" do
|
379
|
+
timeline_attachment = @api.timeline.get(@timeline_id, {attachments:{id: @attachment_id}})
|
380
|
+
timeline_attachment.id == '1234'
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
context "with invalid params" do
|
385
|
+
before do
|
386
|
+
@timeline_id = "1234"
|
387
|
+
@attachment_id = "blah"
|
388
|
+
stub_request(:get, "https://www.googleapis.com/mirror/v1/timeline/#{@timeline_id}/attachments/#{@attachment_id}").
|
389
|
+
with(headers: json_get_request_headers).
|
390
|
+
to_return(status: 404,
|
391
|
+
body: {},
|
392
|
+
headers: {})
|
393
|
+
end
|
394
|
+
it "should return nil" do
|
395
|
+
timeline_attachment = @api.timeline.get(@timeline_id, {attachments:{id: @attachment_id}})
|
396
|
+
timeline_attachment.should == nil
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
#TODO: Support file upload
|
402
|
+
# context "insert" do
|
403
|
+
# context "with valid params" do
|
404
|
+
# before do
|
405
|
+
# @timeline_id = "1234"
|
406
|
+
# @file = fixture_file_upload('files/fry.png', 'image/png')
|
407
|
+
# @params = {uploadType: 'media'}
|
408
|
+
|
409
|
+
# stub_request(:post, "https://www.googleapis.com/mirror/v1/timeline/#{@timeline_id}/attachments?uploadType=media").
|
410
|
+
# with(
|
411
|
+
# headers: json_post_request_headers(@body.to_json)).
|
412
|
+
# to_return(status: 200,
|
413
|
+
# body: fixture("timeline_item_attachments_item.json", true),
|
414
|
+
# headers: {})
|
415
|
+
# end
|
416
|
+
# it "should return timeline_attachment with id '1234'" do
|
417
|
+
# timeline_attachment = @api.timeline.delete(@timeline_id, {attachments:{id: @attachment_id}})
|
418
|
+
# timeline_attachment.id == '1234ß'
|
419
|
+
# end
|
420
|
+
# end
|
421
|
+
|
422
|
+
# context "with invalid params" do
|
423
|
+
# before do
|
424
|
+
# @body = {canIHazContact: "Really you thought that was valid?!"}
|
425
|
+
|
426
|
+
# stub_request(:post, "https://www.googleapis.com/mirror/v1/contacts/").
|
427
|
+
# with(body: @body,
|
428
|
+
# headers: json_post_request_headers(@body.to_json)).
|
429
|
+
# to_return(status: 404,
|
430
|
+
# body: {},
|
431
|
+
# headers: {})
|
432
|
+
# end
|
433
|
+
# it "should return nil" do
|
434
|
+
# contact = @api.contacts.insert(@body)
|
435
|
+
# contact.should == nil
|
436
|
+
# end
|
437
|
+
# end
|
438
|
+
# end
|
439
|
+
|
440
|
+
# TODO correct resource#list method to handle attachments
|
441
|
+
context "list" do
|
442
|
+
context "with valid params" do
|
443
|
+
before do
|
444
|
+
@timeline_id = "1234"
|
445
|
+
stub_request(:get, "https://www.googleapis.com/mirror/v1/timeline/#{@timeline_id}/attachments/").
|
446
|
+
with(headers: json_get_request_headers).
|
447
|
+
to_return(status: 200,
|
448
|
+
body: fixture("timeline_item_attachments_list.json", true),
|
449
|
+
headers: {})
|
450
|
+
end
|
451
|
+
|
452
|
+
it "should return a list of contacts", :focus => true do
|
453
|
+
attachments = @api.timeline.list(@timeline_id, {attachments: {} })
|
454
|
+
attachments.should_not be_nil
|
455
|
+
attachments.items.count.should == 2 # see fixture
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
end
|
461
|
+
|
331
462
|
def json_post_request_headers(body)
|
332
463
|
{
|
333
464
|
'Accept'=>'application/json',
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
{
|
3
|
+
"kind": "mirror#attachmentsList",
|
4
|
+
"items": [
|
5
|
+
{
|
6
|
+
"id": "1234",
|
7
|
+
"contentType": "image/png",
|
8
|
+
"contentUrl": "https://www.evernote.com/shard/s28/sh/be536e15-5664-4533-b46e-ee4f09a9ed26/4cc92448e68787d8d054839e9ccd6273/deep/0/Pasted%20Image%204/25/13%2012:18%20AM.png",
|
9
|
+
"isProcessingContent": false
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"id": "0987",
|
13
|
+
"contentType": "image/png",
|
14
|
+
"contentUrl": "https://www.evernote.com/didnt_want_to_upload_anything_fun.png",
|
15
|
+
"isProcessingContent": false
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
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.
|
4
|
+
version: 0.0.8
|
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-
|
13
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -213,9 +213,12 @@ files:
|
|
213
213
|
- spec/client_spec.rb
|
214
214
|
- spec/fixtures/contacts_item.json
|
215
215
|
- spec/fixtures/contacts_list.json
|
216
|
+
- spec/fixtures/files/fry.png
|
216
217
|
- spec/fixtures/locations_item.json
|
217
218
|
- spec/fixtures/locations_list.json
|
218
219
|
- spec/fixtures/timeline_item.json
|
220
|
+
- spec/fixtures/timeline_item_attachments_item.json
|
221
|
+
- spec/fixtures/timeline_item_attachments_list.json
|
219
222
|
- spec/fixtures/timeline_item_response_headers.json
|
220
223
|
- spec/spec_helper.rb
|
221
224
|
homepage: https://github.com/ciberch/mirror-api
|
@@ -246,8 +249,11 @@ test_files:
|
|
246
249
|
- spec/client_spec.rb
|
247
250
|
- spec/fixtures/contacts_item.json
|
248
251
|
- spec/fixtures/contacts_list.json
|
252
|
+
- spec/fixtures/files/fry.png
|
249
253
|
- spec/fixtures/locations_item.json
|
250
254
|
- spec/fixtures/locations_list.json
|
251
255
|
- spec/fixtures/timeline_item.json
|
256
|
+
- spec/fixtures/timeline_item_attachments_item.json
|
257
|
+
- spec/fixtures/timeline_item_attachments_list.json
|
252
258
|
- spec/fixtures/timeline_item_response_headers.json
|
253
259
|
- spec/spec_helper.rb
|