boxr 1.8.0 → 1.11.1
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.
- checksums.yaml +4 -4
- data/.env.example +3 -3
- data/.gitignore +1 -0
- data/README.md +7 -2
- data/lib/boxr/auth.rb +22 -9
- data/lib/boxr/client.rb +2 -0
- data/lib/boxr/files.rb +23 -19
- data/lib/boxr/groups.rb +11 -11
- data/lib/boxr/metadata.rb +22 -1
- data/lib/boxr/version.rb +1 -1
- data/spec/boxr/auth_spec.rb +31 -0
- data/spec/boxr/collaborations_spec.rb +1 -1
- data/spec/boxr/files_spec.rb +10 -2
- data/spec/boxr/metadata_spec.rb +21 -0
- data/spec/boxr_spec.rb +5 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81bc808dde71fc65c270c2a145ee55c5dd6ac48ef964e9156512dbc04bb6ddf7
|
4
|
+
data.tar.gz: cc3d5e5140ef46fc95ff138d1fa79534e0bae12dc14e04bc54d212236cfc0ab9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f9bbc5f449301705e0919f122f9d55819ea7be821f2e081ee5d5f913db4d4cddf31d50f98cb831f4a9bbb2b59687a39ccbbecd71ac5d489d33d81760ea43b2e
|
7
|
+
data.tar.gz: 2181831ee3b4732c7ad4152aad85b51ef8f7dd951f25ab1cc6059b031f8653e6554961e3159585fe1ef1d72f125f0afe2d916f1acf4f0c26b7d69aaf2b5c0701
|
data/.env.example
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#1. go to https://developers.box.com,
|
1
|
+
#1. go to https://developers.box.com,
|
2
2
|
#2. find or create your Box Content API app for testing
|
3
3
|
#3. click 'Edit Application'
|
4
4
|
#4. check the boxes for 'Read and write all files and folders' and 'Manage an enterprise'
|
@@ -11,5 +11,5 @@ BOX_DEVELOPER_TOKEN={a valid developer token for your Box app}
|
|
11
11
|
BOX_CLIENT_ID={client id of your Box app}
|
12
12
|
BOX_CLIENT_SECRET={client secret of your Box app}
|
13
13
|
BOX_ENTERPRISE_ID={box enterprise id}
|
14
|
-
|
15
|
-
|
14
|
+
JWT_PRIVATE_KEY_PATH={path to your JWT private key}
|
15
|
+
JWT_PRIVATE_KEY_PASSWORD={JWT private key password}
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# Boxr
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/boxr)
|
4
|
+
|
2
5
|
Boxr is a Ruby client library for the Box V2 Content API. Box employees affectionately refer to one another as Boxers, hence the name of this gem.
|
3
6
|
|
4
7
|
The purpose of this gem is to provide a clear, efficient, and intentional method of interacting with the Box Content API. As with any SDK that wraps a REST API, it is important to fully understand the Box Content API at the REST endpoint level. You are strongly encouraged to read through the Box documentation located [here](https://box-content.readme.io/).
|
@@ -392,9 +395,11 @@ update_folder_metadata(folder, updates, scope, template)
|
|
392
395
|
delete_metadata(file, scope: :global, template: :properties)
|
393
396
|
delete_folder_metadata(folder, scope, template)
|
394
397
|
|
395
|
-
|
398
|
+
get_enterprise_templates
|
399
|
+
get_metadata_template_by_name(scope, template_key)
|
396
400
|
|
397
|
-
|
401
|
+
create_metadata_template(display_name, template_key: nil, fields: [], hidden: nil)
|
402
|
+
delete_metadata_template(scope, template_key)
|
398
403
|
```
|
399
404
|
|
400
405
|
#### [Watermarking](https://box-content.readme.io/reference#watermarking)
|
data/lib/boxr/auth.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Boxr
|
2
2
|
|
3
3
|
JWT_GRANT_TYPE="urn:ietf:params:oauth:grant-type:jwt-bearer"
|
4
|
+
TOKEN_EXCHANGE_TOKEN_TYPE="urn:ietf:params:oauth:token-type:access_token"
|
5
|
+
TOKEN_EXCHANGE_GRANT_TYPE="urn:ietf:params:oauth:grant-type:token-exchange"
|
4
6
|
|
5
7
|
def self.oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil, client_id: ENV['BOX_CLIENT_ID'])
|
6
8
|
template = Addressable::Template.new("https://{host}/api/oauth2/authorize{?query*}")
|
@@ -8,13 +10,13 @@ module Boxr
|
|
8
10
|
query = {"response_type" => "#{response_type}", "state" => "#{state}", "client_id" => "#{client_id}"}
|
9
11
|
query["scope"] = "#{scope}" unless scope.nil?
|
10
12
|
query["folder_id"] = "#{folder_id}" unless folder_id.nil?
|
11
|
-
|
13
|
+
|
12
14
|
uri = template.expand({"host" => "#{host}", "query" => query})
|
13
15
|
uri
|
14
16
|
end
|
15
17
|
|
16
18
|
def self.get_tokens(code=nil, grant_type: "authorization_code", assertion: nil, scope: nil, username: nil, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
|
17
|
-
uri =
|
19
|
+
uri = Boxr::Client::AUTH_URI
|
18
20
|
body = "grant_type=#{grant_type}&client_id=#{client_id}&client_secret=#{client_secret}"
|
19
21
|
body = body + "&code=#{code}" unless code.nil?
|
20
22
|
body = body + "&scope=#{scope}" unless scope.nil?
|
@@ -25,7 +27,7 @@ module Boxr
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def self.get_enterprise_token(private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
|
28
|
-
public_key_id: ENV['JWT_PUBLIC_KEY_ID'], enterprise_id: ENV['BOX_ENTERPRISE_ID'],
|
30
|
+
public_key_id: ENV['JWT_PUBLIC_KEY_ID'], enterprise_id: ENV['BOX_ENTERPRISE_ID'],
|
29
31
|
client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
|
30
32
|
unlocked_private_key = unlock_key(private_key, private_key_password)
|
31
33
|
assertion = jwt_assertion(unlocked_private_key, client_id, enterprise_id, "enterprise", public_key_id)
|
@@ -40,19 +42,31 @@ module Boxr
|
|
40
42
|
end
|
41
43
|
|
42
44
|
def self.refresh_tokens(refresh_token, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
|
43
|
-
uri =
|
45
|
+
uri = Boxr::Client::AUTH_URI
|
44
46
|
body = "grant_type=refresh_token&refresh_token=#{refresh_token}&client_id=#{client_id}&client_secret=#{client_secret}"
|
45
47
|
|
46
48
|
auth_post(uri, body)
|
47
49
|
end
|
48
50
|
|
49
51
|
def self.revoke_tokens(token, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
|
50
|
-
uri =
|
52
|
+
uri = Boxr::Client::REVOKE_AUTH_URI
|
51
53
|
body = "client_id=#{client_id}&client_secret=#{client_secret}&token=#{token}"
|
52
54
|
|
53
55
|
auth_post(uri, body)
|
54
56
|
end
|
55
57
|
|
58
|
+
# Exchange an existing token for a lesser-scoped token
|
59
|
+
def self.exchange_token(subject_token, scope, resource_id: nil, resource_type: :file)
|
60
|
+
uri = Boxr::Client::AUTH_URI
|
61
|
+
resouce_uri = resource_type == :file ? Boxr::Client::FILES_URI : Boxr::Client::FOLDERS_URI
|
62
|
+
resource_url = "#{resouce_uri}/#{resource_id}"
|
63
|
+
|
64
|
+
body = "subject_token=#{subject_token}&subject_token_type=#{TOKEN_EXCHANGE_TOKEN_TYPE}&scope=#{scope}&grant_type=#{TOKEN_EXCHANGE_GRANT_TYPE}"
|
65
|
+
body = body + "&resource=#{resource_url}" unless resource_id.nil?
|
66
|
+
|
67
|
+
auth_post(uri, body)
|
68
|
+
end
|
69
|
+
|
56
70
|
class << self
|
57
71
|
alias :get_token :get_tokens
|
58
72
|
alias :refresh_token :refresh_tokens
|
@@ -67,14 +81,14 @@ module Boxr
|
|
67
81
|
iss: iss,
|
68
82
|
sub: sub,
|
69
83
|
box_sub_type: box_sub_type,
|
70
|
-
aud:
|
84
|
+
aud: Boxr::Client::AUTH_URI,
|
71
85
|
jti: SecureRandom.hex(64),
|
72
86
|
exp: (Time.now.utc + 10).to_i
|
73
87
|
}
|
74
88
|
|
75
89
|
additional_headers = {}
|
76
90
|
additional_headers['kid'] = public_key_id unless public_key_id.nil?
|
77
|
-
|
91
|
+
|
78
92
|
JWT.encode(payload, private_key, "RS256", additional_headers)
|
79
93
|
end
|
80
94
|
|
@@ -98,5 +112,4 @@ module Boxr
|
|
98
112
|
OpenSSL::PKey::RSA.new(private_key, private_key_password)
|
99
113
|
end
|
100
114
|
end
|
101
|
-
|
102
|
-
end
|
115
|
+
end
|
data/lib/boxr/client.rb
CHANGED
@@ -8,6 +8,8 @@ module Boxr
|
|
8
8
|
#UPLOAD_URI = "https://upload.wcheng.inside-box.net/api/2.0"
|
9
9
|
|
10
10
|
API_URI = "https://api.box.com/2.0"
|
11
|
+
AUTH_URI = "https://api.box.com/oauth2/token"
|
12
|
+
REVOKE_AUTH_URI = "https://api.box.com/oauth2/revoke"
|
11
13
|
UPLOAD_URI = "https://upload.box.com/api/2.0"
|
12
14
|
FILES_URI = "#{API_URI}/files"
|
13
15
|
FILES_UPLOAD_URI = "#{UPLOAD_URI}/files/content"
|
data/lib/boxr/files.rb
CHANGED
@@ -75,6 +75,7 @@ module Boxr
|
|
75
75
|
|
76
76
|
def download_file(file, version: nil, follow_redirect: true)
|
77
77
|
file_id = ensure_id(file)
|
78
|
+
|
78
79
|
begin
|
79
80
|
uri = "#{FILES_URI}/#{file_id}/content"
|
80
81
|
query = {}
|
@@ -85,7 +86,8 @@ module Boxr
|
|
85
86
|
location = response.header['Location'][0]
|
86
87
|
|
87
88
|
if(follow_redirect)
|
88
|
-
|
89
|
+
file_content, response = get(location, process_response: false)
|
90
|
+
return file_content
|
89
91
|
else
|
90
92
|
return location #simply return the url
|
91
93
|
end
|
@@ -93,9 +95,7 @@ module Boxr
|
|
93
95
|
retry_after_seconds = response.header['Retry-After'][0]
|
94
96
|
sleep retry_after_seconds.to_i
|
95
97
|
end
|
96
|
-
end until
|
97
|
-
|
98
|
-
file
|
98
|
+
end until file_content
|
99
99
|
end
|
100
100
|
|
101
101
|
def download_url(file, version: nil)
|
@@ -104,27 +104,31 @@ module Boxr
|
|
104
104
|
|
105
105
|
def upload_file(path_to_file, parent, name: nil, content_created_at: nil, content_modified_at: nil,
|
106
106
|
preflight_check: true, send_content_md5: true)
|
107
|
-
|
108
|
-
parent_id = ensure_id(parent)
|
109
|
-
|
110
107
|
filename = name ? name : File.basename(path_to_file)
|
111
|
-
preflight_check(path_to_file, filename, parent_id) if preflight_check
|
112
|
-
|
113
|
-
file_info = nil
|
114
|
-
response = nil
|
115
108
|
|
116
109
|
File.open(path_to_file) do |file|
|
117
|
-
|
110
|
+
upload_file_from_io(file, parent, name: filename, content_created_at: content_created_at, content_modified_at: content_modified_at, preflight_check: preflight_check, send_content_md5: send_content_md5)
|
111
|
+
end
|
112
|
+
end
|
118
113
|
|
119
|
-
|
120
|
-
|
121
|
-
attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
|
114
|
+
def upload_file_from_io(io, parent, name:, content_created_at: nil, content_modified_at: nil, preflight_check: true, send_content_md5: true)
|
115
|
+
parent_id = ensure_id(parent)
|
122
116
|
|
123
|
-
|
117
|
+
preflight_check(io, name, parent_id) if preflight_check
|
124
118
|
|
125
|
-
|
119
|
+
if send_content_md5
|
120
|
+
content_md5 = Digest::SHA1.hexdigest(io.read)
|
121
|
+
io.rewind
|
126
122
|
end
|
127
123
|
|
124
|
+
attributes = {name: name, parent: {id: parent_id}}
|
125
|
+
attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil?
|
126
|
+
attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
|
127
|
+
|
128
|
+
body = {attributes: JSON.dump(attributes), file: io}
|
129
|
+
|
130
|
+
file_info, response = post(FILES_UPLOAD_URI, body, process_body: false, content_md5: content_md5)
|
131
|
+
|
128
132
|
file_info.entries[0]
|
129
133
|
end
|
130
134
|
|
@@ -254,8 +258,8 @@ module Boxr
|
|
254
258
|
|
255
259
|
private
|
256
260
|
|
257
|
-
def preflight_check(
|
258
|
-
size = File.size(
|
261
|
+
def preflight_check(io, filename, parent_id)
|
262
|
+
size = File.size(io)
|
259
263
|
|
260
264
|
#TODO: need to make sure that figuring out the filename from the path_to_file works for people using Windows
|
261
265
|
attributes = {name: filename, parent: {id: "#{parent_id}"}, size: size}
|
data/lib/boxr/groups.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Boxr
|
2
2
|
class Client
|
3
3
|
|
4
|
-
def groups(fields: [])
|
4
|
+
def groups(fields: [], offset: 0, limit: DEFAULT_LIMIT)
|
5
5
|
query = build_fields_query(fields, GROUP_FIELDS_QUERY)
|
6
|
-
groups = get_all_with_pagination(GROUPS_URI, query: query, offset:
|
6
|
+
groups = get_all_with_pagination(GROUPS_URI, query: query, offset: offset, limit: limit)
|
7
7
|
end
|
8
8
|
|
9
9
|
def group_from_id(group_id, fields: [])
|
@@ -39,21 +39,21 @@ module Boxr
|
|
39
39
|
result
|
40
40
|
end
|
41
41
|
|
42
|
-
def group_memberships(group)
|
42
|
+
def group_memberships(group, offset: 0, limit: DEFAULT_LIMIT)
|
43
43
|
group_id = ensure_id(group)
|
44
44
|
uri = "#{GROUPS_URI}/#{group_id}/memberships"
|
45
|
-
memberships = get_all_with_pagination(uri, offset:
|
45
|
+
memberships = get_all_with_pagination(uri, offset: offset, limit: limit)
|
46
46
|
end
|
47
47
|
|
48
|
-
def group_memberships_for_user(user)
|
48
|
+
def group_memberships_for_user(user, offset: 0, limit: DEFAULT_LIMIT)
|
49
49
|
user_id = ensure_id(user)
|
50
50
|
uri = "#{USERS_URI}/#{user_id}/memberships"
|
51
|
-
memberships = get_all_with_pagination(uri, offset:
|
51
|
+
memberships = get_all_with_pagination(uri, offset: offset, limit: limit)
|
52
52
|
end
|
53
53
|
|
54
|
-
def group_memberships_for_me
|
54
|
+
def group_memberships_for_me(offset: 0, limit: DEFAULT_LIMIT)
|
55
55
|
uri = "#{USERS_URI}/me/memberships"
|
56
|
-
memberships = get_all_with_pagination(uri, offset:
|
56
|
+
memberships = get_all_with_pagination(uri, offset: offset, limit: limit)
|
57
57
|
end
|
58
58
|
|
59
59
|
def group_membership_from_id(membership_id)
|
@@ -89,11 +89,11 @@ module Boxr
|
|
89
89
|
result
|
90
90
|
end
|
91
91
|
|
92
|
-
def group_collaborations(group)
|
92
|
+
def group_collaborations(group, offset: 0, limit: DEFAULT_LIMIT)
|
93
93
|
group_id = ensure_id(group)
|
94
94
|
uri = "#{GROUPS_URI}/#{group_id}/collaborations"
|
95
|
-
collaborations = get_all_with_pagination(uri, offset:
|
95
|
+
collaborations = get_all_with_pagination(uri, offset: offset, limit: limit)
|
96
96
|
end
|
97
97
|
|
98
98
|
end
|
99
|
-
end
|
99
|
+
end
|
data/lib/boxr/metadata.rb
CHANGED
@@ -77,12 +77,33 @@ module Boxr
|
|
77
77
|
ent_metadata, response = get(uri)
|
78
78
|
ent_metadata
|
79
79
|
end
|
80
|
+
alias :get_enterprise_templates :enterprise_metadata
|
80
81
|
|
81
82
|
def metadata_schema(scope, template_key)
|
82
83
|
uri = "#{METADATA_TEMPLATES_URI}/#{scope}/#{template_key}/schema"
|
83
84
|
schema, response = get(uri)
|
84
85
|
schema
|
85
86
|
end
|
87
|
+
alias :get_metadata_template_by_name :metadata_schema
|
88
|
+
|
89
|
+
def create_metadata_template(display_name, template_key: nil, fields: [], hidden: nil)
|
90
|
+
uri = "#{METADATA_TEMPLATES_URI}/schema"
|
91
|
+
schema = {
|
92
|
+
scope: "enterprise",
|
93
|
+
displayName: display_name,
|
94
|
+
}
|
95
|
+
schema[:templateKey] = template_key unless template_key.nil?
|
96
|
+
schema[:hidden] = hidden unless hidden.nil?
|
97
|
+
schema[:fields] = fields unless fields.empty?
|
98
|
+
|
99
|
+
metadata_template, response = post(uri, schema, content_type: "application/json")
|
100
|
+
metadata_template
|
101
|
+
end
|
86
102
|
|
103
|
+
def delete_metadata_template(scope, template_key)
|
104
|
+
uri = "#{METADATA_TEMPLATES_URI}/#{scope}/#{template_key}/schema"
|
105
|
+
result, response = delete(uri)
|
106
|
+
result
|
107
|
+
end
|
87
108
|
end
|
88
|
-
end
|
109
|
+
end
|
data/lib/boxr/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
#rake spec SPEC_OPTS="-e \"invokes auth operations"\"
|
4
|
+
describe 'auth operations' do
|
5
|
+
it "invokes auth operations" do
|
6
|
+
private_key = OpenSSL::PKey::RSA.new(File.read(ENV['JWT_PRIVATE_KEY_PATH']), ENV['JWT_PRIVATE_KEY_PASSWORD'])
|
7
|
+
|
8
|
+
puts "get enterprise token"
|
9
|
+
enterprise_token = Boxr::get_enterprise_token(private_key: private_key)
|
10
|
+
expect(enterprise_token).to include('access_token', 'expires_in')
|
11
|
+
|
12
|
+
puts "downgrade token"
|
13
|
+
child_token = Boxr::exchange_token(enterprise_token['access_token'], 'root_readonly')
|
14
|
+
expect(child_token).to include('access_token','expires_in')
|
15
|
+
|
16
|
+
# Currently cannot test due to user requiring
|
17
|
+
puts "get user token"
|
18
|
+
second_test_user = BOX_CLIENT.create_user("Second Test User", login: "second_test_user@#{('a'..'z').to_a.shuffle[0,10].join}.com", role: 'user', is_platform_access_only: true)
|
19
|
+
user_token = Boxr::get_user_token(second_test_user.id, private_key: private_key)
|
20
|
+
expect(user_token).to include('access_token','expires_in')
|
21
|
+
|
22
|
+
puts "revoke user token"
|
23
|
+
user_client = Boxr::Client.new(user_token['access_token'])
|
24
|
+
expect(user_client.root_folder_items).to eq []
|
25
|
+
Boxr::revoke_token(user_token['access_token'])
|
26
|
+
expect{user_client.root_folder_items}.to raise_error{Boxr::BoxrError}
|
27
|
+
|
28
|
+
puts "cleanup data"
|
29
|
+
BOX_CLIENT.delete_user(second_test_user, force: true)
|
30
|
+
end
|
31
|
+
end
|
@@ -32,6 +32,6 @@ describe 'collaborations operations' do
|
|
32
32
|
expect(pending_collaborations).to eq([])
|
33
33
|
|
34
34
|
puts "add invalid collaboration"
|
35
|
-
expect { BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :invalid_role)}.to raise_error
|
35
|
+
expect { BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :invalid_role)}.to raise_error{Boxr::BoxrError}
|
36
36
|
end
|
37
37
|
end
|
data/spec/boxr/files_spec.rb
CHANGED
@@ -12,6 +12,11 @@ describe "file operations" do
|
|
12
12
|
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder, name: TEST_FILE_NAME_CUSTOM)
|
13
13
|
expect(new_file.name).to eq(TEST_FILE_NAME_CUSTOM)
|
14
14
|
|
15
|
+
puts "upload a file from IO"
|
16
|
+
io = File.open("./spec/test_files/#{TEST_FILE_NAME}")
|
17
|
+
new_file = BOX_CLIENT.upload_file_from_io(io, @test_folder, name: TEST_FILE_NAME_IO)
|
18
|
+
expect(new_file.name).to eq(TEST_FILE_NAME_IO)
|
19
|
+
|
15
20
|
puts "get file using path"
|
16
21
|
file = BOX_CLIENT.file_from_path("/#{TEST_FOLDER_NAME}/#{TEST_FILE_NAME}")
|
17
22
|
expect(file.id).to eq(test_file.id)
|
@@ -50,13 +55,16 @@ describe "file operations" do
|
|
50
55
|
expect(unlocked_file.lock).to be_nil
|
51
56
|
|
52
57
|
puts "download file"
|
53
|
-
|
58
|
+
file_content = BOX_CLIENT.download_file(test_file)
|
54
59
|
f = File.open("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}", 'w+')
|
55
|
-
f.write(
|
60
|
+
f.write(file_content)
|
56
61
|
f.close
|
57
62
|
expect(FileUtils.identical?("./spec/test_files/#{TEST_FILE_NAME}","./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")).to eq(true)
|
58
63
|
File.delete("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")
|
59
64
|
|
65
|
+
puts "download invalid file"
|
66
|
+
expect { BOX_CLIENT.download_file('INVALID_FILE_NAME.pdf') }.to raise_exception(Boxr::BoxrError)
|
67
|
+
|
60
68
|
puts "upload new version of file"
|
61
69
|
new_version = BOX_CLIENT.upload_new_version_of_file("./spec/test_files/#{TEST_FILE_NAME}", test_file)
|
62
70
|
expect(new_version.id).to eq(test_file.id)
|
data/spec/boxr/metadata_spec.rb
CHANGED
@@ -29,6 +29,8 @@ describe 'file metadata operations' do
|
|
29
29
|
#NOTE: this test will fail unless you create a metadata template called 'test' with two attributes: 'a' of type text, and 'b' of type text
|
30
30
|
it "invokes folder metadata operations" do
|
31
31
|
new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @test_folder)
|
32
|
+
fields = [{displayName: "a", type: "string"},{displayName: "b", type: "string"}]
|
33
|
+
metadata_template = BOX_CLIENT.create_metadata_template("test", fields: fields)
|
32
34
|
|
33
35
|
puts "create folder metadata"
|
34
36
|
meta = {"a" => "hello", "b" => "world"}
|
@@ -48,5 +50,24 @@ describe 'file metadata operations' do
|
|
48
50
|
puts "delete folder metadata"
|
49
51
|
result = BOX_CLIENT.delete_folder_metadata(new_folder, "enterprise", "test")
|
50
52
|
expect(result).to eq({})
|
53
|
+
|
54
|
+
puts "cleanup metadata template"
|
55
|
+
template_key = metadata_template["templateKey"]
|
56
|
+
scope = metadata_template["scope"]
|
57
|
+
BOX_CLIENT.delete_metadata_template(scope, template_key)
|
58
|
+
end
|
59
|
+
|
60
|
+
#rake spec SPEC_OPTS="-e \"invokes metadata template operations"\"
|
61
|
+
it "invokes metadata template operations" do
|
62
|
+
puts "create metadata template"
|
63
|
+
metadata_template = BOX_CLIENT.create_metadata_template("Test Template")
|
64
|
+
expect(metadata_template["displayName"]).to eq("Test Template")
|
65
|
+
|
66
|
+
template_key = metadata_template["templateKey"]
|
67
|
+
scope = metadata_template["scope"]
|
68
|
+
|
69
|
+
puts "delete metadata template"
|
70
|
+
result = BOX_CLIENT.delete_metadata_template(scope, template_key)
|
71
|
+
expect(result).to eq({})
|
51
72
|
end
|
52
73
|
end
|
data/spec/boxr_spec.rb
CHANGED
@@ -10,7 +10,11 @@ describe Boxr::Client do
|
|
10
10
|
|
11
11
|
#REQUIRED BOX SETTINGS
|
12
12
|
# 1. The developer token used must have admin or co-admin priviledges
|
13
|
+
# 1.5 In the admin settings, advanced features must be enabled (perform as user and create user access tokens)
|
13
14
|
# 2. Enterprise settings must allow Admin and Co-admins to permanently delete content in Trash
|
15
|
+
# 3. In Box Admin settings, you must authorize the app.
|
16
|
+
# - Admin Console > Enterprise Settings > Apps > Custom Applications > Authorize New App. Insert you client ID (API key)
|
17
|
+
# - You may need to re-authorize the app if you're running into issues with user tokens
|
14
18
|
|
15
19
|
#follow the directions in .env.example to set up your BOX_DEVELOPER_TOKEN
|
16
20
|
#keep in mind it is only valid for 60 minutes
|
@@ -25,6 +29,7 @@ describe Boxr::Client do
|
|
25
29
|
SUB_FOLDER_DESCRIPTION = 'This was created by the Boxr test suite'
|
26
30
|
TEST_FILE_NAME = 'test file.txt'
|
27
31
|
TEST_FILE_NAME_CUSTOM = 'test file custom.txt'
|
32
|
+
TEST_FILE_NAME_IO = 'test file io.txt'
|
28
33
|
DOWNLOADED_TEST_FILE_NAME = 'downloaded test file.txt'
|
29
34
|
COMMENT_MESSAGE = 'this is a comment'
|
30
35
|
REPLY_MESSAGE = 'this is a comment reply'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Burnette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -209,6 +209,7 @@ files:
|
|
209
209
|
- lib/boxr/version.rb
|
210
210
|
- lib/boxr/watermarking.rb
|
211
211
|
- lib/boxr/web_links.rb
|
212
|
+
- spec/boxr/auth_spec.rb
|
212
213
|
- spec/boxr/collaborations_spec.rb
|
213
214
|
- spec/boxr/comments_spec.rb
|
214
215
|
- spec/boxr/files_spec.rb
|
@@ -247,6 +248,7 @@ signing_key:
|
|
247
248
|
specification_version: 4
|
248
249
|
summary: A Ruby client library for the Box V2 Content API.
|
249
250
|
test_files:
|
251
|
+
- spec/boxr/auth_spec.rb
|
250
252
|
- spec/boxr/collaborations_spec.rb
|
251
253
|
- spec/boxr/comments_spec.rb
|
252
254
|
- spec/boxr/files_spec.rb
|