boxr 1.0.0 → 1.1.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.
- checksums.yaml +4 -4
- data/README.md +78 -74
- data/examples/metadata_search.rb +19 -0
- data/lib/boxr/client.rb +2 -1
- data/lib/boxr/metadata.rb +37 -5
- data/lib/boxr/version.rb +1 -1
- data/spec/boxr_spec.rb +27 -2
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dabf6e02613d429dee655d87eaacacdd8bba2386
|
|
4
|
+
data.tar.gz: d5f56cea3324cdadc93ace1b5d06aaf57f127f0b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5560f56757e1b129227fc0303fdb708054dc673f04afb262dc83dd4efe547f254c58d5ac71b4c9924990d18d1ba5e4e217ce4aa8c5ff7e56e02a91197f748fec
|
|
7
|
+
data.tar.gz: dea07c12287232c34ca1be07d38c9a6b34677ca5d3048c35ac23b09004115e67091c53eb4c5d0e110606a89d5d27741a7f5b230e756cb25c6fdfb426f2f1ce21
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Boxr
|
|
2
|
-
Boxr is a Ruby client library for the Box V2 Content API
|
|
2
|
+
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
3
|
|
|
4
|
-
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://
|
|
4
|
+
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/).
|
|
5
5
|
|
|
6
6
|
The full RubyDocs for Boxr can be found [here](http://www.rubydoc.info/gems/boxr/Boxr/Client). You are also encouraged to rely heavily on the source code found in the [lib/boxr](https://github.com/cburnette/boxr/tree/master/lib/boxr) directory of this gem, as well as on the integration tests found [here](https://github.com/cburnette/boxr/blob/master/spec/boxr_spec.rb).
|
|
7
7
|
|
|
@@ -47,7 +47,7 @@ There are a few different ways to create a Boxr client. The simplest is to use
|
|
|
47
47
|
```ruby
|
|
48
48
|
client = Boxr::Client.new('yPDWOvnumUFaKIMrNBg6PGJpWXC0oaFW')
|
|
49
49
|
|
|
50
|
-
# Alternatively, you can set an environment variable called BOX_DEVELOPER_TOKEN to
|
|
50
|
+
# Alternatively, you can set an environment variable called BOX_DEVELOPER_TOKEN to
|
|
51
51
|
# the value of your current token. By default, Boxr will look for that.
|
|
52
52
|
|
|
53
53
|
client = Boxr::Client.new #uses ENV['BOX_DEVELOPER_TOKEN']
|
|
@@ -66,12 +66,12 @@ If you want Boxr to automatically refresh the tokens once the access token becom
|
|
|
66
66
|
|
|
67
67
|
```ruby
|
|
68
68
|
token_refresh_callback = lambda {|access, refresh, identifier| some_method_that_saves_them(access, refresh)}
|
|
69
|
-
client = Boxr::Client.new('zX3UjFwNerOy5PSWc2WI8aJgMHtAjs8T',
|
|
69
|
+
client = Boxr::Client.new('zX3UjFwNerOy5PSWc2WI8aJgMHtAjs8T',
|
|
70
70
|
refresh_token: 'dvfzfCQoIcRi7r4Yeuar7mZnaghGWexXlX89sBaRy1hS9e5wFroVVOEM6bs0DwPQ',
|
|
71
71
|
client_id: 'kplh54vfeagt6jmi4kddg4xdswwvrw8y',
|
|
72
72
|
client_secret: 'sOsm9ZZ8L8svwrn9FsdulLQVwDizKueU',
|
|
73
73
|
&token_refresh_callback)
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
# By default Boxr will look for client_id and client_secret in your environment variables as
|
|
76
76
|
# BOX_CLIENT_ID and BOX_CLIENT_SECRET, respectively. You can omit the two optional parameters above
|
|
77
77
|
# if those are present.
|
|
@@ -79,24 +79,24 @@ client = Boxr::Client.new('zX3UjFwNerOy5PSWc2WI8aJgMHtAjs8T',
|
|
|
79
79
|
# You can provide another parameter called as_user. Read about what that means here: https://developers.box.com/docs/#users-as-user
|
|
80
80
|
|
|
81
81
|
# You can provide yet another parameter called identifier. This can be used, for example, to
|
|
82
|
-
# hold the id of the user associated with this Boxr client. When the callback is invoked this value
|
|
82
|
+
# hold the id of the user associated with this Boxr client. When the callback is invoked this value
|
|
83
83
|
# will be provided.
|
|
84
84
|
```
|
|
85
85
|
Here's the complete method signature to initialize an instance of Boxr::Client
|
|
86
86
|
```ruby
|
|
87
|
-
initialize( access_token=ENV['BOX_DEVELOPER_TOKEN'],
|
|
88
|
-
refresh_token: nil,
|
|
89
|
-
client_id: ENV['BOX_CLIENT_ID'],
|
|
87
|
+
initialize( access_token=ENV['BOX_DEVELOPER_TOKEN'],
|
|
88
|
+
refresh_token: nil,
|
|
89
|
+
client_id: ENV['BOX_CLIENT_ID'],
|
|
90
90
|
client_secret: ENV['BOX_CLIENT_SECRET'],
|
|
91
91
|
enterprise_id: ENV['BOX_ENTERPRISE_ID'],
|
|
92
|
-
jwt_private_key: ENV['JWT_PRIVATE_KEY'],
|
|
92
|
+
jwt_private_key: ENV['JWT_PRIVATE_KEY'],
|
|
93
93
|
jwt_private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'],
|
|
94
94
|
jwt_public_key_id: ENV['JWT_PUBLIC_KEY_ID'],
|
|
95
|
-
identifier: nil,
|
|
96
|
-
as_user: nil,
|
|
95
|
+
identifier: nil,
|
|
96
|
+
as_user: nil,
|
|
97
97
|
&token_refresh_listener)
|
|
98
98
|
```
|
|
99
|
-
|
|
99
|
+
|
|
100
100
|
### A quick example
|
|
101
101
|
Before diving into detailed documentation, let's take a look at how to accomplish a simple task with Boxr. This script will find a specific folder given its path, upload a file to that folder, and create an open shared link to that file.
|
|
102
102
|
|
|
@@ -112,7 +112,7 @@ puts "Shared Link: #{updated_file.shared_link.url}"
|
|
|
112
112
|
```
|
|
113
113
|
|
|
114
114
|
### Methods
|
|
115
|
-
#### [OAuth & JWT](https://
|
|
115
|
+
#### [OAuth & JWT](https://box-content.readme.io/reference#oauth-2)
|
|
116
116
|
```ruby
|
|
117
117
|
#NOTE: these are all module methods
|
|
118
118
|
|
|
@@ -130,42 +130,42 @@ Boxr::get_enterprise_token(private_key: ENV['JWT_PRIVATE_KEY'], private_key_pass
|
|
|
130
130
|
|
|
131
131
|
Boxr::get_user_token(user_id, private_key: ENV['JWT_PRIVATE_KEY'], private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'], public_key_id: ENV['JWT_PUBLIC_KEY_ID'], client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'])
|
|
132
132
|
```
|
|
133
|
-
#### [Folders](https://
|
|
133
|
+
#### [Folders](https://box-content.readme.io/reference#folder-object-1)
|
|
134
134
|
```ruby
|
|
135
135
|
folder_from_path(path)
|
|
136
136
|
|
|
137
137
|
folder_from_id(folder_id, fields: [])
|
|
138
138
|
alias :folder :folder_from_id
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
folder_items(folder, fields: [], offset: 0, limit: FOLDER_ITEMS_LIMIT)
|
|
141
|
-
|
|
141
|
+
|
|
142
142
|
root_folder_items(fields: [], offset: 0, limit: FOLDER_ITEMS_LIMIT)
|
|
143
|
-
|
|
143
|
+
|
|
144
144
|
create_folder(name, parent)
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
update_folder(folder, name: nil, description: nil, parent: nil, shared_link: nil,
|
|
147
147
|
folder_upload_email_access: nil, owned_by: nil, sync_state: nil, tags: nil,
|
|
148
148
|
can_non_owners_invite: nil, if_match: nil)
|
|
149
149
|
|
|
150
150
|
move_folder(folder, new_parent, name: nil, if_match: nil)
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
delete_folder(folder, recursive: false, if_match: nil)
|
|
153
|
-
|
|
153
|
+
|
|
154
154
|
copy_folder(folder, dest_folder, name: nil)
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
create_shared_link_for_folder(folder, access: nil, unshared_at: nil, can_download: nil, can_preview: nil)
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
disable_shared_link_for_folder(folder)
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
trash(fields: [], offset: 0, limit: FOLDER_ITEMS_LIMIT)
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
trashed_folder(folder, fields: [])
|
|
163
|
-
|
|
163
|
+
|
|
164
164
|
delete_trashed_folder(folder)
|
|
165
|
-
|
|
165
|
+
|
|
166
166
|
restore_trashed_folder(folder, name: nil, parent: nil)
|
|
167
167
|
```
|
|
168
|
-
#### [Files](https://
|
|
168
|
+
#### [Files](https://box-content.readme.io/reference#file-object)
|
|
169
169
|
```ruby
|
|
170
170
|
file_from_path(path)
|
|
171
171
|
|
|
@@ -189,12 +189,12 @@ download_file(file, version: nil, follow_redirect: true)
|
|
|
189
189
|
|
|
190
190
|
download_url(file, version: nil)
|
|
191
191
|
|
|
192
|
-
upload_file(path_to_file, parent, content_created_at: nil, content_modified_at: nil,
|
|
192
|
+
upload_file(path_to_file, parent, content_created_at: nil, content_modified_at: nil,
|
|
193
193
|
preflight_check: true, send_content_md5: true)
|
|
194
194
|
|
|
195
195
|
delete_file(file, if_match: nil)
|
|
196
196
|
|
|
197
|
-
upload_new_version_of_file(path_to_file, file, content_modified_at: nil, send_content_md5: true,
|
|
197
|
+
upload_new_version_of_file(path_to_file, file, content_modified_at: nil, send_content_md5: true,
|
|
198
198
|
preflight_check: true, if_match: nil)
|
|
199
199
|
|
|
200
200
|
versions_of_file(file)
|
|
@@ -217,67 +217,67 @@ delete_trashed_file(file)
|
|
|
217
217
|
|
|
218
218
|
restore_trashed_file(file, name: nil, parent: nil)
|
|
219
219
|
```
|
|
220
|
-
#### [Comments](https://
|
|
220
|
+
#### [Comments](https://box-content.readme.io/reference#comment-object)
|
|
221
221
|
```ruby
|
|
222
222
|
file_comments(file, fields: [], offset: 0, limit: DEFAULT_LIMIT)
|
|
223
|
-
|
|
223
|
+
|
|
224
224
|
add_comment_to_file(file, message: nil, tagged_message: nil)
|
|
225
|
-
|
|
225
|
+
|
|
226
226
|
reply_to_comment(comment, message: nil, tagged_message: nil)
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
change_comment(comment, message)
|
|
229
|
-
|
|
229
|
+
|
|
230
230
|
comment_from_id(comment_id, fields: [])
|
|
231
231
|
alias :comment :comment_from_id
|
|
232
|
-
|
|
232
|
+
|
|
233
233
|
delete_comment(comment)
|
|
234
234
|
```
|
|
235
|
-
#### [Collaborations](https://
|
|
235
|
+
#### [Collaborations](https://box-content.readme.io/reference#collaboration-object)
|
|
236
236
|
```ruby
|
|
237
237
|
folder_collaborations(folder)
|
|
238
|
-
|
|
238
|
+
|
|
239
239
|
add_collaboration(folder, accessible_by, role, fields: [], notify: nil)
|
|
240
|
-
|
|
240
|
+
|
|
241
241
|
edit_collaboration(collaboration, role: nil, status: nil)
|
|
242
|
-
|
|
242
|
+
|
|
243
243
|
remove_collaboration(collaboration)
|
|
244
|
-
|
|
244
|
+
|
|
245
245
|
collaboration_from_id(collaboration_id, fields: [], status: nil)
|
|
246
246
|
alias :collaboration :collaboration_from_id
|
|
247
|
-
|
|
247
|
+
|
|
248
248
|
pending_collaborations()
|
|
249
249
|
```
|
|
250
|
-
#### [Events](https://
|
|
250
|
+
#### [Events](https://box-content.readme.io/reference#events)
|
|
251
251
|
```ruby
|
|
252
252
|
user_events(stream_position, stream_type: :all, limit: 800)
|
|
253
|
-
|
|
253
|
+
|
|
254
254
|
enterprise_events(created_after: nil, created_before: nil, stream_position: 0, event_type: nil, limit: 500)
|
|
255
255
|
|
|
256
256
|
enterprise_events_stream(initial_stream_position, event_type: nil, limit: 500, refresh_period: 300)
|
|
257
257
|
```
|
|
258
|
-
#### [Shared Items](https://
|
|
258
|
+
#### [Shared Items](https://box-content.readme.io/reference#get-a-shared-item)
|
|
259
259
|
```ruby
|
|
260
260
|
shared_item(shared_link, shared_link_password: nil)
|
|
261
261
|
```
|
|
262
|
-
#### [Search](https://
|
|
262
|
+
#### [Search](https://box-content.readme.io/reference#searching-for-content)
|
|
263
263
|
```ruby
|
|
264
|
-
search( query=nil, scope: nil, file_extensions: [],
|
|
264
|
+
search( query=nil, scope: nil, file_extensions: [],
|
|
265
265
|
created_at_range_from_date: nil, created_at_range_to_date: nil,
|
|
266
266
|
updated_at_range_from_date: nil, updated_at_range_to_date: nil,
|
|
267
|
-
size_range_lower_bound_bytes: nil, size_range_upper_bound_bytes: nil,
|
|
268
|
-
owner_user_ids: [], ancestor_folder_ids: [], content_types: [], trash_content: nil,
|
|
267
|
+
size_range_lower_bound_bytes: nil, size_range_upper_bound_bytes: nil,
|
|
268
|
+
owner_user_ids: [], ancestor_folder_ids: [], content_types: [], trash_content: nil,
|
|
269
269
|
mdfilters: nil, type: nil, limit: 30, offset: 0)
|
|
270
270
|
```
|
|
271
|
-
#### [Users](https://
|
|
271
|
+
#### [Users](https://box-content.readme.io/reference#user-object)
|
|
272
272
|
```ruby
|
|
273
273
|
current_user(fields: [])
|
|
274
274
|
alias :me :current_user
|
|
275
275
|
|
|
276
276
|
user_from_id(user_id, fields: [])
|
|
277
277
|
alias :user :user_from_id
|
|
278
|
-
|
|
278
|
+
|
|
279
279
|
all_users(filter_term: nil, fields: [], offset: 0, limit: DEFAULT_LIMIT)
|
|
280
|
-
|
|
280
|
+
|
|
281
281
|
create_user(login, name, role: nil, language: nil, is_sync_enabled: nil, job_title: nil,
|
|
282
282
|
phone: nil, address: nil, space_amount: nil, tracking_codes: nil,
|
|
283
283
|
can_see_managed_users: nil, is_external_collab_restricted: nil, status: nil, timezone: nil,
|
|
@@ -297,68 +297,72 @@ remove_email_alias_for_user(user, email_alias)
|
|
|
297
297
|
|
|
298
298
|
delete_user(user, notify: nil, force: nil)
|
|
299
299
|
```
|
|
300
|
-
#### [Groups](https://
|
|
300
|
+
#### [Groups](https://box-content.readme.io/reference#group-object)
|
|
301
301
|
```ruby
|
|
302
302
|
groups(fields: [], offset: 0, limit: DEFAULT_LIMIT)
|
|
303
|
-
|
|
303
|
+
|
|
304
304
|
create_group(name)
|
|
305
|
-
|
|
305
|
+
|
|
306
306
|
update_group(group, name)
|
|
307
307
|
alias :rename_group :update_group
|
|
308
308
|
|
|
309
309
|
delete_group(group)
|
|
310
|
-
|
|
310
|
+
|
|
311
311
|
group_memberships(group, offset: 0, limit: DEFAULT_LIMIT)
|
|
312
|
-
|
|
312
|
+
|
|
313
313
|
group_memberships_for_user(user, offset: 0, limit: DEFAULT_LIMIT)
|
|
314
|
-
|
|
314
|
+
|
|
315
315
|
group_memberships_for_me(offset: 0, limit: DEFAULT_LIMIT)
|
|
316
|
-
|
|
316
|
+
|
|
317
317
|
group_membership_from_id(membership_id)
|
|
318
318
|
alias :group_membership :group_membership_from_id
|
|
319
|
-
|
|
319
|
+
|
|
320
320
|
add_user_to_group(user, group, role: nil)
|
|
321
|
-
|
|
321
|
+
|
|
322
322
|
update_group_membership(membership, role)
|
|
323
|
-
|
|
323
|
+
|
|
324
324
|
delete_group_membership(membership)
|
|
325
|
-
|
|
325
|
+
|
|
326
326
|
group_collaborations(group, offset: 0, limit: DEFAULT_LIMIT)
|
|
327
327
|
```
|
|
328
|
-
#### [Tasks](https://
|
|
328
|
+
#### [Tasks](https://box-content.readme.io/reference#task-object-1)
|
|
329
329
|
```ruby
|
|
330
330
|
file_tasks(file, fields: [])
|
|
331
|
-
|
|
331
|
+
|
|
332
332
|
create_task(file, action: :review, message: nil, due_at: nil)
|
|
333
|
-
|
|
333
|
+
|
|
334
334
|
task_from_id(task_id)
|
|
335
335
|
alias :task :task_from_id
|
|
336
|
-
|
|
336
|
+
|
|
337
337
|
update_task(task, action: :review, message: nil, due_at: nil)
|
|
338
|
-
|
|
338
|
+
|
|
339
339
|
delete_task(task)
|
|
340
|
-
|
|
340
|
+
|
|
341
341
|
task_assignments(task)
|
|
342
|
-
|
|
342
|
+
|
|
343
343
|
create_task_assignment(task, assign_to: nil, assign_to_login: nil)
|
|
344
|
-
|
|
344
|
+
|
|
345
345
|
task_assignment(task)
|
|
346
|
-
|
|
346
|
+
|
|
347
347
|
delete_task_assignment(task)
|
|
348
|
-
|
|
348
|
+
|
|
349
349
|
update_task_assignment(task, message: nil, resolution_state: nil)
|
|
350
350
|
```
|
|
351
|
-
#### [Metadata](https://
|
|
351
|
+
#### [Metadata](https://box-content.readme.io/reference#metadata-object)
|
|
352
352
|
```ruby
|
|
353
353
|
create_metadata(file, metadata, scope: :global, template: :properties)
|
|
354
|
+
create_folder_metadata(folder, metadata, scope, template)
|
|
354
355
|
|
|
355
356
|
metadata(file, scope: :global, template: :properties)
|
|
357
|
+
folder_metadata(folder, scope, template)
|
|
356
358
|
|
|
357
359
|
all_metadata(file)
|
|
358
360
|
|
|
359
361
|
update_metadata(file, updates, scope: :global, template: :properties)
|
|
362
|
+
update_folder_metadata(folder, updates, scope, template)
|
|
360
363
|
|
|
361
364
|
delete_metadata(file, scope: :global, template: :properties)
|
|
365
|
+
delete_folder_metadata(folder, scope, template)
|
|
362
366
|
|
|
363
367
|
enterprise_metadata
|
|
364
368
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'dotenv'; Dotenv.load("../.env")
|
|
2
|
+
require 'awesome_print'
|
|
3
|
+
require 'boxr'
|
|
4
|
+
|
|
5
|
+
box_client = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
|
|
6
|
+
|
|
7
|
+
mdfilters = [
|
|
8
|
+
{
|
|
9
|
+
"templateKey" => "test1",
|
|
10
|
+
"scope" => "enterprise",
|
|
11
|
+
"filters" => {
|
|
12
|
+
"attrone" => "blah",
|
|
13
|
+
"attrtwo" => {"gt" => "4", "lt" => "7"}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
results = box_client.search(mdfilters: mdfilters)
|
|
19
|
+
ap results
|
data/lib/boxr/client.rb
CHANGED
|
@@ -22,7 +22,8 @@ module Boxr
|
|
|
22
22
|
TASKS_URI = "#{API_URI}/tasks"
|
|
23
23
|
TASK_ASSIGNMENTS_URI = "#{API_URI}/task_assignments"
|
|
24
24
|
SHARED_ITEMS_URI = "#{API_URI}/shared_items"
|
|
25
|
-
|
|
25
|
+
FILE_METADATA_URI = "#{API_URI}/files"
|
|
26
|
+
FOLDER_METADATA_URI = "#{API_URI}/folders"
|
|
26
27
|
METADATA_TEMPLATES_URI = "#{API_URI}/metadata_templates"
|
|
27
28
|
EVENTS_URI = "#{API_URI}/events"
|
|
28
29
|
|
data/lib/boxr/metadata.rb
CHANGED
|
@@ -3,28 +3,53 @@ module Boxr
|
|
|
3
3
|
|
|
4
4
|
def create_metadata(file, metadata, scope: :global, template: :properties)
|
|
5
5
|
file_id = ensure_id(file)
|
|
6
|
-
uri = "#{
|
|
6
|
+
uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}"
|
|
7
|
+
metadata, response = post(uri, metadata, content_type: "application/json")
|
|
8
|
+
metadata
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def create_folder_metadata(folder, metadata, scope, template)
|
|
12
|
+
folder_id = ensure_id(folder)
|
|
13
|
+
uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}"
|
|
7
14
|
metadata, response = post(uri, metadata, content_type: "application/json")
|
|
8
15
|
metadata
|
|
9
16
|
end
|
|
10
17
|
|
|
11
18
|
def metadata(file, scope: :global, template: :properties)
|
|
12
19
|
file_id = ensure_id(file)
|
|
13
|
-
uri = "#{
|
|
20
|
+
uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}"
|
|
21
|
+
metadata, response = get(uri)
|
|
22
|
+
metadata
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def folder_metadata(folder, scope, template)
|
|
26
|
+
folder_id = ensure_id(folder)
|
|
27
|
+
uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}"
|
|
14
28
|
metadata, response = get(uri)
|
|
15
29
|
metadata
|
|
16
30
|
end
|
|
17
31
|
|
|
18
32
|
def all_metadata(file)
|
|
19
33
|
file_id = ensure_id(file)
|
|
20
|
-
uri = "#{
|
|
34
|
+
uri = "#{FILE_METADATA_URI}/#{file_id}/metadata"
|
|
21
35
|
all_metadata, response = get(uri)
|
|
22
36
|
all_metadata
|
|
23
37
|
end
|
|
24
38
|
|
|
25
39
|
def update_metadata(file, updates, scope: :global, template: :properties)
|
|
26
40
|
file_id = ensure_id(file)
|
|
27
|
-
uri = "#{
|
|
41
|
+
uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}"
|
|
42
|
+
|
|
43
|
+
#in the event just one update is specified ensure that it is packaged inside an array
|
|
44
|
+
updates = [updates] unless updates.is_a? Array
|
|
45
|
+
|
|
46
|
+
metadata, response = put(uri, updates, content_type: "application/json-patch+json")
|
|
47
|
+
metadata
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def update_folder_metadata(folder, updates, scope, template)
|
|
51
|
+
folder_id = ensure_id(folder)
|
|
52
|
+
uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}"
|
|
28
53
|
|
|
29
54
|
#in the event just one update is specified ensure that it is packaged inside an array
|
|
30
55
|
updates = [updates] unless updates.is_a? Array
|
|
@@ -35,7 +60,14 @@ module Boxr
|
|
|
35
60
|
|
|
36
61
|
def delete_metadata(file, scope: :global, template: :properties)
|
|
37
62
|
file_id = ensure_id(file)
|
|
38
|
-
uri = "#{
|
|
63
|
+
uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}"
|
|
64
|
+
result, response = delete(uri)
|
|
65
|
+
result
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def delete_folder_metadata(folder, scope, template)
|
|
69
|
+
folder_id = ensure_id(folder)
|
|
70
|
+
uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}"
|
|
39
71
|
result, response = delete(uri)
|
|
40
72
|
result
|
|
41
73
|
end
|
data/lib/boxr/version.rb
CHANGED
data/spec/boxr_spec.rb
CHANGED
|
@@ -468,8 +468,8 @@ describe Boxr::Client do
|
|
|
468
468
|
expect(result).to eq({})
|
|
469
469
|
end
|
|
470
470
|
|
|
471
|
-
#rake spec SPEC_OPTS="-e \"invokes metadata operations"\"
|
|
472
|
-
it "invokes metadata operations" do
|
|
471
|
+
#rake spec SPEC_OPTS="-e \"invokes file metadata operations"\"
|
|
472
|
+
it "invokes file metadata operations" do
|
|
473
473
|
test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
|
474
474
|
|
|
475
475
|
puts "create metadata"
|
|
@@ -492,6 +492,31 @@ describe Boxr::Client do
|
|
|
492
492
|
expect(result).to eq({})
|
|
493
493
|
end
|
|
494
494
|
|
|
495
|
+
#rake spec SPEC_OPTS="-e \"invokes folder metadata operations"\"
|
|
496
|
+
#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
|
|
497
|
+
it "invokes folder metadata operations" do
|
|
498
|
+
new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @test_folder)
|
|
499
|
+
|
|
500
|
+
puts "create folder metadata"
|
|
501
|
+
meta = {"a" => "hello", "b" => "world"}
|
|
502
|
+
metadata = BOX_CLIENT.create_folder_metadata(new_folder, meta, "enterprise", "test")
|
|
503
|
+
expect(metadata.a).to eq("hello")
|
|
504
|
+
|
|
505
|
+
puts "update folder metadata"
|
|
506
|
+
metadata = BOX_CLIENT.update_folder_metadata(new_folder, {op: :replace, path: "/b", value: "there"}, "enterprise", "test")
|
|
507
|
+
expect(metadata.b).to eq("there")
|
|
508
|
+
metadata = BOX_CLIENT.update_folder_metadata(new_folder, [{op: :replace, path: "/b", value: "friend"}], "enterprise", "test")
|
|
509
|
+
expect(metadata.b).to eq("friend")
|
|
510
|
+
|
|
511
|
+
puts "get folder metadata"
|
|
512
|
+
metadata = BOX_CLIENT.folder_metadata(new_folder, "enterprise", "test")
|
|
513
|
+
expect(metadata.a).to eq("hello")
|
|
514
|
+
|
|
515
|
+
puts "delete folder metadata"
|
|
516
|
+
result = BOX_CLIENT.delete_folder_metadata(new_folder, "enterprise", "test")
|
|
517
|
+
expect(result).to eq({})
|
|
518
|
+
end
|
|
519
|
+
|
|
495
520
|
#rake spec SPEC_OPTS="-e \"invokes search operations"\"
|
|
496
521
|
it "invokes search operations" do
|
|
497
522
|
#the issue with this test is that Box can take between 5-10 minutes to index any content uploaded; this is just a smoke test
|
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.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chad Burnette
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-05-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -196,6 +196,7 @@ files:
|
|
|
196
196
|
- boxr.gemspec
|
|
197
197
|
- examples/enterprise_events.rb
|
|
198
198
|
- examples/jwt_auth.rb
|
|
199
|
+
- examples/metadata_search.rb
|
|
199
200
|
- examples/oauth.rb
|
|
200
201
|
- examples/remove_collaborators.rb
|
|
201
202
|
- examples/use_events_to_send_sms.rb
|