iora-ruby-box 1.14.0
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/.document +5 -0
- data/.travis.yml +6 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +349 -0
- data/Rakefile +32 -0
- data/VERSION +1 -0
- data/lib/ruby-box.rb +21 -0
- data/lib/ruby-box/client.rb +163 -0
- data/lib/ruby-box/collaboration.rb +19 -0
- data/lib/ruby-box/comment.rb +14 -0
- data/lib/ruby-box/discussion.rb +15 -0
- data/lib/ruby-box/event.rb +4 -0
- data/lib/ruby-box/event_response.rb +17 -0
- data/lib/ruby-box/exceptions.rb +22 -0
- data/lib/ruby-box/file.rb +96 -0
- data/lib/ruby-box/folder.rb +113 -0
- data/lib/ruby-box/item.rb +181 -0
- data/lib/ruby-box/session.rb +136 -0
- data/lib/ruby-box/shared_link.rb +10 -0
- data/lib/ruby-box/user.rb +16 -0
- data/lib/ruby-box/web_link.rb +4 -0
- data/ruby-box.gemspec +99 -0
- data/spec/client_spec.rb +64 -0
- data/spec/event_spec.rb +70 -0
- data/spec/file_spec.rb +110 -0
- data/spec/fixtures/comment_create.json +18 -0
- data/spec/fixtures/events.json +161 -0
- data/spec/fixtures/me.json +17 -0
- data/spec/fixtures/users.json +39 -0
- data/spec/folder_spec.rb +181 -0
- data/spec/helper/account.example +3 -0
- data/spec/helper/account.rb +8 -0
- data/spec/integration_spec.rb +387 -0
- data/spec/item_spec.rb +31 -0
- data/spec/me_spec.rb +20 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/users_spec.rb +24 -0
- metadata +214 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
{
|
2
|
+
"total_count": 2,
|
3
|
+
"entries": [
|
4
|
+
{
|
5
|
+
"type": "user",
|
6
|
+
"id": "181216415",
|
7
|
+
"name": "sean rose",
|
8
|
+
"login": "sean+awesome@box.com",
|
9
|
+
"created_at": "2012-05-03T21:39:11-07:00",
|
10
|
+
"modified_at": "2012-08-23T14:57:48-07:00",
|
11
|
+
"language": "en",
|
12
|
+
"space_amount": 5368709120,
|
13
|
+
"space_used": 52947,
|
14
|
+
"max_upload_size": 104857600,
|
15
|
+
"status": "active",
|
16
|
+
"job_title": "",
|
17
|
+
"phone": "5555551374",
|
18
|
+
"address": "10 Cloud Way Los Altos CA",
|
19
|
+
"avatar_url": "https://api.box.com/api/avatar/large/181216415"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"type": "user",
|
23
|
+
"id": "181216416",
|
24
|
+
"name": "sean rose",
|
25
|
+
"login": "sean+awesomer@box.com",
|
26
|
+
"created_at": "2012-05-03T21:39:11-07:00",
|
27
|
+
"modified_at": "2012-08-23T14:57:48-07:00",
|
28
|
+
"language": "en",
|
29
|
+
"space_amount": 5368709120,
|
30
|
+
"space_used": 52947,
|
31
|
+
"max_upload_size": 104857600,
|
32
|
+
"status": "active",
|
33
|
+
"job_title": "",
|
34
|
+
"phone": "5555551374",
|
35
|
+
"address": "10 Cloud Way Los Altos CA",
|
36
|
+
"avatar_url": "https://api.box.com/api/avatar/large/181216416"
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
data/spec/folder_spec.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'helper/account'
|
5
|
+
require 'ruby-box'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
|
8
|
+
describe RubyBox::Folder do
|
9
|
+
before do
|
10
|
+
@session = RubyBox::Session.new
|
11
|
+
@full_folder = JSON.parse('{ "type": "folder", "id": "11446498", "sequence_id": "1", "etag": "1", "name": "Pictures", "created_at": "2012-12-12T10:53:43-08:00", "modified_at": "2012-12-12T11:15:04-08:00", "description": "Some pictures I took", "size": 629644, "path_collection": { "total_count": 1, "entries": [ { "type": "folder", "id": "0", "sequence_id": null, "etag": null, "name": "All Files" } ] }, "created_by": { "type": "user", "id": "17738362", "name": "sean rose", "login": "sean@box.com" }, "modified_by": { "type": "user", "id": "17738362", "name": "sean rose", "login": "sean@box.com" }, "owned_by": { "type": "user", "id": "17738362", "name": "sean rose", "login": "sean@box.com" }, "shared_link": { "url": "https://www.box.com/s/vspke7y05sb214wjokpk", "download_url": "https://www.box.com/shared/static/vspke7y05sb214wjokpk", "vanity_url": null, "is_password_enabled": false, "unshared_at": null, "download_count": 0, "preview_count": 0, "access": "open", "permissions": { "can_download": true, "can_preview": true } }, "folder_upload_email": { "access": "open", "email": "upload.Picture.k13sdz1@u.box.com" }, "parent": { "type": "folder", "id": "0", "sequence_id": null, "etag": null, "name": "All Files" }, "item_status": "active", "item_collection": { "total_count": 1, "entries": [ { "type": "file", "id": "5000948880", "sequence_id": "3", "etag": "3", "sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc", "name": "tigers.jpeg" } ], "offset": 0, "limit": 100 }}')
|
12
|
+
@mini_folder = JSON.parse('{ "type":"folder", "id":"301415432", "sequence_id":"0", "name":"my first sub-folder"}')
|
13
|
+
@items = [
|
14
|
+
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" }, { "type": "collaboration", "id": "409042000", "status": "accepted" } ], "offset": "0", "limit": "3"}'),
|
15
|
+
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" }, { "type": "collaboration", "id": "409042001", "status": "accepted" } ], "offset": "2", "limit": "3"}')
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "#root returns full root folder object" do
|
20
|
+
RubyBox::Session.any_instance.stub(:request).and_return(@full_folder)
|
21
|
+
session = RubyBox::Session.new
|
22
|
+
root = RubyBox::Client.new(session).root_folder
|
23
|
+
root.name.should == 'Pictures'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns iso8601 format keys as a time object" do
|
27
|
+
RubyBox::Session.any_instance.stub(:request).and_return(@full_folder)
|
28
|
+
session = RubyBox::Session.new
|
29
|
+
root = RubyBox::Client.new(session).root_folder
|
30
|
+
root.created_at.year.should == 2012
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#find_by_type" do
|
34
|
+
it "compares name in a case insensitive manner" do
|
35
|
+
items = [
|
36
|
+
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "2"}'),
|
37
|
+
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
|
38
|
+
]
|
39
|
+
|
40
|
+
RubyBox::Session.any_instance.stub(:request) { items.pop }
|
41
|
+
session = RubyBox::Session.new
|
42
|
+
|
43
|
+
# should return one file.
|
44
|
+
files = RubyBox::Folder.new(session, {'id' => 1}).files('A CHOICE file')
|
45
|
+
files.count.should == 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#items' do
|
50
|
+
it "should return a folder object for folder items" do
|
51
|
+
item = JSON.parse('{ "id": "0000001", "total_count": 1, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" } ], "offset": "0", "limit": "1"}')
|
52
|
+
RubyBox::Session.any_instance.stub(:request).and_return(item)
|
53
|
+
session = RubyBox::Session.new
|
54
|
+
item = RubyBox::Client.new(session).root_folder.items.first
|
55
|
+
item.kind_of?(RubyBox::Folder).should == true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should return a file object for file items" do
|
59
|
+
item = JSON.parse('{ "id": "0000001", "total_count": 1, "entries": [ { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "1"}')
|
60
|
+
RubyBox::Session.any_instance.stub(:request).and_return(item)
|
61
|
+
session = RubyBox::Session.new
|
62
|
+
item = RubyBox::Client.new(session).root_folder.items.first
|
63
|
+
item.kind_of?(RubyBox::File).should == true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "it should return an iterator that lazy loads all entries" do
|
67
|
+
RubyBox::Session.any_instance.stub(:request) { @items.pop }
|
68
|
+
session = RubyBox::Session.new
|
69
|
+
items = RubyBox::Folder.new(session, {'id' => 1}).items(1).to_a
|
70
|
+
items[0].kind_of?(RubyBox::Folder).should == true
|
71
|
+
items[1].kind_of?(RubyBox::File).should == true
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should allow a fields parameter to be set" do
|
75
|
+
RubyBox::Session.any_instance.should_receive(:get).with('https://api.box.com/2.0/folders/1/items?limit=100&offset=0&fields=size').and_return({'entries' => []})
|
76
|
+
session = RubyBox::Session.new
|
77
|
+
RubyBox::Folder.new(session, {'id' => 1}).items(100, 0, [:size]).to_a
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should not have the fields parameter set by default" do
|
81
|
+
RubyBox::Session.any_instance.should_receive(:get).with('https://api.box.com/2.0/folders/1/items?limit=100&offset=0').and_return({'entries' => []})
|
82
|
+
session = RubyBox::Session.new
|
83
|
+
RubyBox::Folder.new(session, {'id' => 1}).items.to_a
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#files' do
|
88
|
+
it "should only return items of type file" do
|
89
|
+
RubyBox::Session.any_instance.stub(:request) { @items.pop }
|
90
|
+
session = RubyBox::Session.new
|
91
|
+
files = RubyBox::Folder.new(session, {'id' => 1}).files
|
92
|
+
files.count.should == 1
|
93
|
+
files.first.kind_of?(RubyBox::File).should == true
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should allow you to filter files by name" do
|
97
|
+
items = [
|
98
|
+
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "2"}'),
|
99
|
+
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
|
100
|
+
]
|
101
|
+
|
102
|
+
RubyBox::Session.any_instance.stub(:request) { items.pop }
|
103
|
+
session = RubyBox::Session.new
|
104
|
+
|
105
|
+
# should return one file.
|
106
|
+
files = RubyBox::Folder.new(session, {'id' => 1}).files('A choice file')
|
107
|
+
files.count.should == 1
|
108
|
+
|
109
|
+
items = [
|
110
|
+
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047867", "sequence_id": "1", "etag": "1", "name": "Here\'s your folder" }, { "type": "file", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "2"}'),
|
111
|
+
JSON.parse('{ "total_count": 4, "entries": [ { "type": "folder", "id": "409047868", "sequence_id": "1", "etag": "1", "name": "Here\'s another folder" }, { "type": "file", "id": "409042810", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "2", "limit": "2"}')
|
112
|
+
]
|
113
|
+
|
114
|
+
# should return no files.
|
115
|
+
files = RubyBox::Folder.new(session, {'id' => 1}).files('foobar')
|
116
|
+
files.count.should == 0
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#discussions' do
|
121
|
+
it "should return all the discussions surrounding a folder" do
|
122
|
+
item = JSON.parse('{ "id": "0000001", "total_count": 1, "entries": [ { "type": "discussion", "id": "409042867", "sequence_id": "1", "etag": "1", "name": "A choice file" } ], "offset": "0", "limit": "1"}')
|
123
|
+
RubyBox::Session.any_instance.stub(:request).and_return(item)
|
124
|
+
session = RubyBox::Session.new
|
125
|
+
item = RubyBox::Client.new(session).root_folder.discussions.first
|
126
|
+
item.kind_of?(RubyBox::Discussion).should == true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#folders' do
|
131
|
+
it "should only return items of type folder" do
|
132
|
+
RubyBox::Session.any_instance.stub(:request) { @items.pop }
|
133
|
+
session = RubyBox::Session.new
|
134
|
+
files = RubyBox::Folder.new(session, {'id' => 1}).folders
|
135
|
+
files.count.should == 1
|
136
|
+
files.first.kind_of?(RubyBox::Folder).should == true
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context '#copy_to' do
|
141
|
+
let(:source_folder) { RubyBox::Folder.new(@session, {'id' => 1}) }
|
142
|
+
let(:destination) { RubyBox::Folder.new(@session, {'id' => 100}) }
|
143
|
+
let(:last_request) { JSON.parse(@request.body) }
|
144
|
+
let(:last_uri) { @uri.to_s }
|
145
|
+
|
146
|
+
before(:each) do
|
147
|
+
@session.stub(:request).with do |uri, request, _, _|
|
148
|
+
@uri, @request = uri, request
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'uses itself for the copy uri' do
|
153
|
+
source_folder.copy_to destination
|
154
|
+
last_uri.should match /folders\/#{source_folder.id}\/copy/
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'uses the destination as the parent' do
|
158
|
+
source_folder.copy_to destination
|
159
|
+
last_request['parent']['id'].should eq(destination.id)
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'uses the source as the name by default' do
|
163
|
+
source_folder.copy_to destination
|
164
|
+
last_request.should_not have_key 'name'
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'can provide a new name if desired' do
|
168
|
+
source_folder.copy_to destination, 'renamed-folder'
|
169
|
+
last_request['name'].should eq('renamed-folder')
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'returns the newly created folder' do
|
173
|
+
@session.should_receive(:request).and_return('type' => 'folder', 'id' => '123')
|
174
|
+
copied_folder = source_folder.copy_to(destination)
|
175
|
+
|
176
|
+
copied_folder.should be_a(RubyBox::Folder)
|
177
|
+
copied_folder.id.should eq("123")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
@@ -0,0 +1,387 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'helper/account'
|
5
|
+
require 'ruby-box'
|
6
|
+
require 'webmock/rspec'
|
7
|
+
|
8
|
+
describe RubyBox, :skip => true do
|
9
|
+
before do
|
10
|
+
|
11
|
+
WebMock.allow_net_connect!
|
12
|
+
|
13
|
+
@session = RubyBox::Session.new({
|
14
|
+
api_key: ACCOUNT['api_key'],
|
15
|
+
auth_token: ACCOUNT['auth_token']
|
16
|
+
})
|
17
|
+
|
18
|
+
@client = RubyBox::Client.new(@session)
|
19
|
+
|
20
|
+
# Create a file with a UTF-8 name for testing.
|
21
|
+
# This is not checked in, as UTF-8 causes issues with
|
22
|
+
# Windows (lame).
|
23
|
+
f = File.new('./spec/fixtures/遠志教授.jpg', 'w')
|
24
|
+
f.puts('Hello World!')
|
25
|
+
f.close()
|
26
|
+
end
|
27
|
+
|
28
|
+
after do
|
29
|
+
File.delete('./spec/fixtures/遠志教授.jpg')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "raises an AuthError if not client auth fails" do
|
33
|
+
session = RubyBox::Session.new({
|
34
|
+
api_key: 'bad-key',
|
35
|
+
auth_token: 'bad-token'
|
36
|
+
})
|
37
|
+
|
38
|
+
@bad_client = RubyBox::Client.new(session)
|
39
|
+
|
40
|
+
lambda {@bad_client.root_folder}.should raise_error( RubyBox::AuthError )
|
41
|
+
end
|
42
|
+
|
43
|
+
it "raises a RequestError if a badly formed request detected by the server" do
|
44
|
+
stub_request(:get, "https://api.box.com/2.0/folders/0").to_return(:status => 401, :body => '{"type": "error", "status": 401, "message": "baddd req"}', :headers => {})
|
45
|
+
lambda {@client.root_folder}.should raise_error( RubyBox::AuthError )
|
46
|
+
|
47
|
+
# make sure status and body is
|
48
|
+
# set on error object.
|
49
|
+
begin
|
50
|
+
@client.root_folder
|
51
|
+
rescue Exception => e
|
52
|
+
e.body.should == '{"type": "error", "status": 401, "message": "baddd req"}'
|
53
|
+
e.status.should == 401
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "raises a ServerError if the server raises a 500 error" do
|
58
|
+
stub_request(:get, "https://api.box.com/2.0/folders/0").to_return(:status => 503, :body => '{"type": "error", "status": 503, "message": "We messed up! - Box.com"}', :headers => {})
|
59
|
+
lambda {@client.root_folder}.should raise_error( RubyBox::ServerError )
|
60
|
+
|
61
|
+
# make sure status and body is
|
62
|
+
# set on error object.
|
63
|
+
begin
|
64
|
+
@client.root_folder
|
65
|
+
rescue Exception => e
|
66
|
+
e.body.should == '{"type": "error", "status": 503, "message": "We messed up! - Box.com"}'
|
67
|
+
e.status.should == 503
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe RubyBox::Folder do
|
73
|
+
describe '#root_folder' do
|
74
|
+
it "#items returns a lits of items in the root folder" do
|
75
|
+
items = @client.root_folder.items.to_a
|
76
|
+
items.count.should == 6
|
77
|
+
items.any? do |item|
|
78
|
+
item.type == "folder" &&
|
79
|
+
item.id == "318810303" &&
|
80
|
+
item.name == "ruby-box_gem_testing"
|
81
|
+
end.should == true
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns list of items in the folder id passed in" do
|
85
|
+
folder = RubyBox::Folder.new(@session, {'id' => '318810303'})
|
86
|
+
items = folder.items.to_a
|
87
|
+
items.count.should == 2
|
88
|
+
items.any? do |item|
|
89
|
+
item.type == "file" &&
|
90
|
+
item.id == "2550686921" &&
|
91
|
+
item.name == "2513582219_03fb9b67db_b.jpg"
|
92
|
+
end.should == true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#file' do
|
97
|
+
it "finds the id of a file" do
|
98
|
+
folder = RubyBox::Folder.new(@session, {'id' => '318810303'})
|
99
|
+
file = folder.files( '2513582219_03fb9b67db_b.jpg' ).first
|
100
|
+
file.id.should == "2550686921"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe '#files' do
|
105
|
+
it "allows additional fields to be requested in file listing" do
|
106
|
+
folder = RubyBox::Folder.new(@session, {'id' => '318810303'})
|
107
|
+
file = folder.files({fields: [:name, :size]}).first
|
108
|
+
file.id.should == "2550686921"
|
109
|
+
file.name.should == "2513582219_03fb9b67db_b.jpg"
|
110
|
+
file.size.should == 593978
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#create' do
|
115
|
+
it "creates a folder" do
|
116
|
+
folder = @client.folder('/ruby-box_gem_testing')
|
117
|
+
subfolder = folder.create_subfolder( 'new_folder_created' )
|
118
|
+
subfolder.id.should_not == nil
|
119
|
+
|
120
|
+
subfolder.delete
|
121
|
+
end
|
122
|
+
|
123
|
+
it "creates a folder with special chars in the name" do
|
124
|
+
folder = @client.folder('/ruby-box_gem_testing')
|
125
|
+
subfolder = folder.create_subfolder( '!@#$%^&$$()' )
|
126
|
+
subfolder.id.should_not == nil
|
127
|
+
|
128
|
+
subfolder.delete
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
describe RubyBox::Client do
|
135
|
+
|
136
|
+
describe RubyBox::Client do
|
137
|
+
describe '#item' do
|
138
|
+
it "item method can lookup generic items, e.g., files or folders" do
|
139
|
+
file = @client.item( '/ruby-box_gem_testing/cool stuff/кузнецкий_105_а_№2.test' )
|
140
|
+
file.size.should == 14
|
141
|
+
file.name.should == 'кузнецкий_105_а_№2.test'
|
142
|
+
|
143
|
+
folder = @client.item( 'ruby-box_gem_testing' )
|
144
|
+
folder.name.should == 'ruby-box_gem_testing'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'uploading files' do
|
150
|
+
it "should update an existing file" do
|
151
|
+
utf8_file_name = '遠志教授.jpg'
|
152
|
+
fdata = File.open( 'spec/fixtures/' + utf8_file_name, 'rb' )
|
153
|
+
response = @client.upload_data('/ruby-box_gem_testing/cool stuff/遠志教授.jpg', fdata)
|
154
|
+
fdata = File.open( 'spec/fixtures/' + utf8_file_name, 'rb' )
|
155
|
+
|
156
|
+
file = @client.upload_data('/ruby-box_gem_testing/cool stuff/遠志教授.jpg', fdata)
|
157
|
+
file.name.should == '遠志教授.jpg'
|
158
|
+
file.delete
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should raise an exception if files collide and overwrite is false' do
|
162
|
+
fdata = File.open( 'spec/fixtures/遠志教授.jpg', 'rb' )
|
163
|
+
file = @client.upload_data('/ruby-box_gem_testing/cool stuff/遠志教授.jpg', fdata)
|
164
|
+
fdata = File.open( 'spec/fixtures/遠志教授.jpg', 'rb' )
|
165
|
+
|
166
|
+
expect{ @client.upload_data('/ruby-box_gem_testing/cool stuff/遠志教授.jpg', fdata, false) }.to raise_error(RubyBox::ItemNameInUse)
|
167
|
+
file.delete
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should upload a new file" do
|
171
|
+
utf8_file_name = '遠志教授.jpg'
|
172
|
+
file = @client.upload_file('spec/fixtures/' + utf8_file_name, '/ruby-box_gem_testing/cool stuff/')
|
173
|
+
file.name.should == '遠志教授.jpg'
|
174
|
+
file.delete
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should allow a file to be uploaded by a folder id" do
|
178
|
+
utf8_file_name = '遠志教授.jpg'
|
179
|
+
folder = @client.folder('/ruby-box_gem_testing/cool stuff/')
|
180
|
+
file = @client.upload_file_by_folder_id('spec/fixtures/' + utf8_file_name, folder.id)
|
181
|
+
file.name.should == '遠志教授.jpg'
|
182
|
+
file.delete
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#create_folder' do
|
187
|
+
it "creates a path that doesnt exist" do
|
188
|
+
folder = @client.create_folder('/ruby-box_gem_testing/cool stuff/екузц/path1/path2')
|
189
|
+
folder.id.should_not == nil
|
190
|
+
folder.delete if folder
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#folder_by_id' do
|
195
|
+
it "allows a folder to be retrieved by its id" do
|
196
|
+
folder = @client.folder('/ruby-box_gem_testing')
|
197
|
+
folder_by_id = @client.folder_by_id(folder.id)
|
198
|
+
folder_by_id.name.should == folder.name
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe '#delete folder' do
|
203
|
+
it "should be able to recursively delete the contents of a folder" do
|
204
|
+
folder = @client.create_folder('/ruby-box_gem_testing/delete_test')
|
205
|
+
@client.create_folder('/ruby-box_gem_testing/delete_test/subfolder')
|
206
|
+
folder.delete(recursive: 'true')
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'retrieving a file' do
|
211
|
+
it "returns meta information for a file" do
|
212
|
+
file = @client.file( '/ruby-box_gem_testing/cool stuff/кузнецкий_105_а_№2.test' )
|
213
|
+
file.size.should == 14
|
214
|
+
end
|
215
|
+
|
216
|
+
it "a file can be retrieved by its id" do
|
217
|
+
file = @client.file( '/ruby-box_gem_testing/cool stuff/кузнецкий_105_а_№2.test' )
|
218
|
+
file_by_id = @client.file_by_id( file.id )
|
219
|
+
file_by_id.size.should == 14
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe '#stream' do
|
224
|
+
it "should download file contents" do
|
225
|
+
stream = @client.stream( '/ruby-box_gem_testing/cool stuff/кузнецкий_105_а_№2.test' )
|
226
|
+
stream.read.should eq "Test more data"
|
227
|
+
end
|
228
|
+
|
229
|
+
it "should execute content_length_proc lambda with filesize" do
|
230
|
+
stream = @client.stream(
|
231
|
+
'/ruby-box_gem_testing/cool stuff/кузнецкий_105_а_№2.test',
|
232
|
+
:content_length_proc => lambda {|filesize|
|
233
|
+
filesize.should == 14
|
234
|
+
}
|
235
|
+
)
|
236
|
+
stream.read.should eq "Test more data"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe '#download' do
|
241
|
+
it "finds the id of a file" do
|
242
|
+
data = @client.download( '/ruby-box_gem_testing/cool stuff/кузнецкий_105_а_№2.test' )
|
243
|
+
data.should eq "Test more data"
|
244
|
+
end
|
245
|
+
|
246
|
+
it "returns nil for a nonexistent file" do
|
247
|
+
data = @client.download( '/ruby-box_gem_testing/doesntexist' )
|
248
|
+
data.should eq nil
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe '#collaborations' do
|
253
|
+
it 'should be able to create and list collaborations on a folder' do
|
254
|
+
folder = @client.create_folder('/ruby-box_gem_testing/collaboration_folder')
|
255
|
+
folder.create_collaboration('bencoe@gmail.com')
|
256
|
+
folder.create_collaboration('ben@attachments.me', 'editor')
|
257
|
+
collaborations = folder.collaborations.to_a
|
258
|
+
|
259
|
+
collaborations[0].role.should == 'viewer'
|
260
|
+
collaborations[1].role.should == 'editor'
|
261
|
+
collaborations.count.should == 2
|
262
|
+
|
263
|
+
folder.delete if folder
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
describe '#shared_link' do
|
268
|
+
it 'should allow a share link to be created for a folder' do
|
269
|
+
folder = @client.create_folder('/ruby-box_gem_testing/shared_folder').create_shared_link
|
270
|
+
|
271
|
+
# share link was successfully created.
|
272
|
+
folder.shared_link.url.should match /https?:\/\/[\S]+/
|
273
|
+
folder.shared_link.is_a?(RubyBox::SharedLink).should == true
|
274
|
+
|
275
|
+
# share link can be disabled.
|
276
|
+
folder.disable_shared_link
|
277
|
+
folder.shared_link.should == nil
|
278
|
+
|
279
|
+
folder.delete if folder
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'should allow a share link to be created for a file' do
|
283
|
+
utf8_file_name = '遠志教授.jpg'
|
284
|
+
file = @client.upload_file('spec/fixtures/' + utf8_file_name, '/ruby-box_gem_testing/cool stuff/').create_shared_link
|
285
|
+
|
286
|
+
# share link was successfully created.
|
287
|
+
file.shared_link.url.should match /https?:\/\/[\S]+/
|
288
|
+
|
289
|
+
# share link can be disabled.
|
290
|
+
file.disable_shared_link
|
291
|
+
file.shared_link.should == nil
|
292
|
+
|
293
|
+
file.delete
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe "#create_comment" do
|
298
|
+
it "allows a comment to be created on a file" do
|
299
|
+
file = @client.upload_file('spec/fixtures/遠志教授.jpg', '/ruby-box_gem_testing/cool stuff/')
|
300
|
+
file.create_comment('Hello world!')
|
301
|
+
file.comments.first.message.should == 'Hello world!'
|
302
|
+
file.delete
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
describe "#copy_to" do
|
307
|
+
it "it copies a file to a folder when a folder id is passed in" do
|
308
|
+
file = @client.upload_file('spec/fixtures/遠志教授.jpg', '/ruby-box_gem_testing/')
|
309
|
+
folder = @client.folder('/ruby-box_gem_testing/cool stuff/')
|
310
|
+
|
311
|
+
file.copy_to(folder.id)
|
312
|
+
|
313
|
+
copied_file = @client.file('/ruby-box_gem_testing/cool stuff/遠志教授.jpg')
|
314
|
+
|
315
|
+
copied_file.name.should == file.name
|
316
|
+
copied_file.size.should == file.size
|
317
|
+
|
318
|
+
file.delete
|
319
|
+
copied_file.delete
|
320
|
+
end
|
321
|
+
|
322
|
+
it "it copies a file to a folder when a folder is passed in" do
|
323
|
+
file = @client.upload_file('spec/fixtures/遠志教授.jpg', '/ruby-box_gem_testing/')
|
324
|
+
folder = @client.folder('/ruby-box_gem_testing/cool stuff/')
|
325
|
+
|
326
|
+
file.copy_to(folder)
|
327
|
+
|
328
|
+
copied_file = @client.file('/ruby-box_gem_testing/cool stuff/遠志教授.jpg')
|
329
|
+
|
330
|
+
copied_file.name.should == file.name
|
331
|
+
copied_file.size.should == file.size
|
332
|
+
|
333
|
+
file.delete
|
334
|
+
copied_file.delete
|
335
|
+
end
|
336
|
+
|
337
|
+
it "allows file to be renamed when copied" do
|
338
|
+
file = @client.upload_file('spec/fixtures/遠志教授.jpg', '/ruby-box_gem_testing/')
|
339
|
+
folder = @client.folder('/ruby-box_gem_testing/cool stuff/')
|
340
|
+
|
341
|
+
file.copy_to(folder, 'banana.jpg')
|
342
|
+
|
343
|
+
copied_file = @client.file('/ruby-box_gem_testing/cool stuff/banana.jpg')
|
344
|
+
|
345
|
+
copied_file.name.should == 'banana.jpg'
|
346
|
+
copied_file.size.should == file.size
|
347
|
+
|
348
|
+
file.delete
|
349
|
+
copied_file.delete
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
describe "#move_to" do
|
354
|
+
it "it moves a file to a folder, the original no longer exists" do
|
355
|
+
file = @client.upload_file('spec/fixtures/遠志教授.jpg', '/ruby-box_gem_testing/')
|
356
|
+
folder = @client.folder('/ruby-box_gem_testing/cool stuff/')
|
357
|
+
|
358
|
+
file.move_to(folder.id)
|
359
|
+
original_file = @client.file('/ruby-box_gem_testing/遠志教授.jpg')
|
360
|
+
original_file.should == nil # the original should no longer exist.
|
361
|
+
|
362
|
+
moved_file = @client.file('/ruby-box_gem_testing/cool stuff/遠志教授.jpg')
|
363
|
+
moved_file.name.should == file.name # the file should exist in the new location.
|
364
|
+
moved_file.size.should == file.size
|
365
|
+
|
366
|
+
moved_file.delete
|
367
|
+
end
|
368
|
+
|
369
|
+
it "allows file to be renamed when moved" do
|
370
|
+
file = @client.upload_file('spec/fixtures/遠志教授.jpg', '/ruby-box_gem_testing/')
|
371
|
+
folder = @client.folder('/ruby-box_gem_testing/cool stuff/')
|
372
|
+
|
373
|
+
file.move_to(folder, 'banana.jpg')
|
374
|
+
original_file = @client.file('/ruby-box_gem_testing/遠志教授.jpg')
|
375
|
+
original_file.should == nil # the original should no longer exist.
|
376
|
+
|
377
|
+
moved_file = @client.file('/ruby-box_gem_testing/cool stuff/banana.jpg')
|
378
|
+
moved_file.name.should == 'banana.jpg' # the file should exist in the new location.
|
379
|
+
moved_file.size.should == file.size
|
380
|
+
|
381
|
+
moved_file.delete
|
382
|
+
end
|
383
|
+
|
384
|
+
end
|
385
|
+
|
386
|
+
end
|
387
|
+
end
|