boxr 1.22.0 → 1.23.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/.github/workflows/ruby-tests.yml +52 -0
- data/.gitignore +1 -0
- data/.rspec +0 -1
- data/.rubocop.yml +22 -0
- data/README.md +34 -5
- data/Rakefile +3 -4
- data/bin/boxr +5 -2
- data/boxr.gemspec +30 -25
- data/examples/enterprise_events.rb +15 -11
- data/examples/jwt_auth.rb +6 -5
- data/examples/metadata_search.rb +12 -11
- data/examples/oauth.rb +8 -11
- data/examples/remove_collaborators.rb +6 -5
- data/examples/use_events_to_send_sms.rb +35 -34
- data/examples/use_events_to_warn_about_sharing.rb +35 -31
- data/examples/user_events.rb +8 -7
- data/lib/boxr/auth.rb +41 -36
- data/lib/boxr/chunked_uploads.rb +56 -32
- data/lib/boxr/client.rb +117 -102
- data/lib/boxr/collaborations.rb +21 -14
- data/lib/boxr/collections.rb +5 -5
- data/lib/boxr/comments.rb +13 -13
- data/lib/boxr/errors.rb +25 -21
- data/lib/boxr/files.rb +87 -73
- data/lib/boxr/folders.rb +32 -29
- data/lib/boxr/groups.rb +22 -22
- data/lib/boxr/metadata.rb +23 -22
- data/lib/boxr/search.rb +34 -28
- data/lib/boxr/shared_items.rb +7 -5
- data/lib/boxr/tasks.rb +18 -18
- data/lib/boxr/users.rb +63 -38
- data/lib/boxr/version.rb +3 -1
- data/lib/boxr/watermarking.rb +10 -17
- data/lib/boxr/web_links.rb +14 -17
- data/lib/boxr/webhooks.rb +8 -7
- data/lib/boxr.rb +13 -11
- metadata +86 -28
data/lib/boxr/files.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Boxr
|
2
4
|
class Client
|
3
|
-
|
4
5
|
def file_from_path(path)
|
5
|
-
if
|
6
|
-
path = path.slice(1..-1)
|
7
|
-
end
|
6
|
+
path = path.slice(1..-1) if path.start_with?('/')
|
8
7
|
|
9
8
|
path_items = path.split('/')
|
10
9
|
file_name = path_items.slice!(-1)
|
11
10
|
|
12
11
|
folder = folder_from_path(path_items.join('/'))
|
13
12
|
|
14
|
-
files = folder_items(folder, fields: [
|
15
|
-
file = files.select{|f| f.name.casecmp?(file_name) }.first
|
13
|
+
files = folder_items(folder, fields: %i[id name]).files
|
14
|
+
file = files.select { |f| f.name.casecmp?(file_name) }.first
|
16
15
|
raise BoxrError.new(boxr_message: "File not found: '#{file_name}'") if file.nil?
|
16
|
+
|
17
17
|
file
|
18
18
|
end
|
19
19
|
|
@@ -21,21 +21,21 @@ module Boxr
|
|
21
21
|
file_id = ensure_id(file_id)
|
22
22
|
uri = "#{FILES_URI}/#{file_id}"
|
23
23
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
24
|
-
file,
|
24
|
+
file, = get(uri, query: query)
|
25
25
|
file
|
26
26
|
end
|
27
|
-
alias
|
27
|
+
alias file file_from_id
|
28
28
|
|
29
29
|
def embed_url(file, show_download: false, show_annotations: false)
|
30
|
-
file_info = file_from_id(file, fields:[:expiring_embed_link])
|
31
|
-
|
32
|
-
url
|
30
|
+
file_info = file_from_id(file, fields: [:expiring_embed_link])
|
31
|
+
file_info.expiring_embed_link.url + "?showDownload=#{show_download}&showAnnotations=#{show_annotations}"
|
33
32
|
end
|
34
|
-
alias
|
35
|
-
alias
|
36
|
-
alias
|
33
|
+
alias embed_link embed_url
|
34
|
+
alias preview_url embed_url
|
35
|
+
alias preview_link embed_url
|
37
36
|
|
38
|
-
def update_file(file, name: nil, description: nil, parent: nil, shared_link: nil, tags: nil,
|
37
|
+
def update_file(file, name: nil, description: nil, parent: nil, shared_link: nil, tags: nil,
|
38
|
+
lock: nil, if_match: nil)
|
39
39
|
file_id = ensure_id(file)
|
40
40
|
parent_id = ensure_id(parent)
|
41
41
|
uri = "#{FILES_URI}/#{file_id}"
|
@@ -43,17 +43,17 @@ module Boxr
|
|
43
43
|
attributes = {}
|
44
44
|
attributes[:name] = name unless name.nil?
|
45
45
|
attributes[:description] = description unless description.nil?
|
46
|
-
attributes[:parent] = {id: parent_id} unless parent_id.nil?
|
46
|
+
attributes[:parent] = { id: parent_id } unless parent_id.nil?
|
47
47
|
attributes[:shared_link] = shared_link unless shared_link.nil?
|
48
48
|
attributes[:tags] = tags unless tags.nil?
|
49
49
|
attributes[:lock] = lock unless lock.nil?
|
50
50
|
|
51
|
-
updated_file,
|
51
|
+
updated_file, = put(uri, attributes, if_match: if_match)
|
52
52
|
updated_file
|
53
53
|
end
|
54
54
|
|
55
55
|
def lock_file(file, expires_at: nil, is_download_prevented: false, if_match: nil)
|
56
|
-
lock = {type:
|
56
|
+
lock = { type: 'lock' }
|
57
57
|
lock[:expires_at] = expires_at.to_datetime.rfc3339 unless expires_at.nil?
|
58
58
|
lock[:is_download_prevented] = is_download_prevented unless is_download_prevented.nil?
|
59
59
|
|
@@ -63,9 +63,9 @@ module Boxr
|
|
63
63
|
def unlock_file(file, if_match: nil)
|
64
64
|
file_id = ensure_id(file)
|
65
65
|
uri = "#{FILES_URI}/#{file_id}"
|
66
|
-
attributes = {lock: nil}
|
66
|
+
attributes = { lock: nil }
|
67
67
|
|
68
|
-
updated_file,
|
68
|
+
updated_file, = put(uri, attributes, if_match: if_match)
|
69
69
|
updated_file
|
70
70
|
end
|
71
71
|
|
@@ -76,26 +76,26 @@ module Boxr
|
|
76
76
|
def download_file(file, version: nil, follow_redirect: true)
|
77
77
|
file_id = ensure_id(file)
|
78
78
|
|
79
|
-
|
79
|
+
loop do
|
80
80
|
uri = "#{FILES_URI}/#{file_id}/content"
|
81
81
|
query = {}
|
82
82
|
query[:version] = version unless version.nil?
|
83
|
-
|
84
|
-
|
85
|
-
if(response.status==302)
|
83
|
+
_, response = get(uri, query: query, success_codes: [302, 202], process_response: false, follow_redirect: false) # we don't want httpclient to automatically follow the redirect; we need to grab it
|
84
|
+
if response.status == 302
|
86
85
|
location = response.header['Location'][0]
|
86
|
+
return location unless follow_redirect
|
87
|
+
|
88
|
+
file_content, = get(location, process_response: false)
|
89
|
+
return file_content
|
90
|
+
|
91
|
+
# simply return the url
|
87
92
|
|
88
|
-
|
89
|
-
file_content, response = get(location, process_response: false)
|
90
|
-
return file_content
|
91
|
-
else
|
92
|
-
return location #simply return the url
|
93
|
-
end
|
94
|
-
elsif(response.status==202)
|
93
|
+
elsif response.status == 202
|
95
94
|
retry_after_seconds = response.header['Retry-After'][0]
|
96
95
|
sleep retry_after_seconds.to_i
|
97
96
|
end
|
98
|
-
|
97
|
+
break if file_content
|
98
|
+
end
|
99
99
|
end
|
100
100
|
|
101
101
|
def download_url(file, version: nil)
|
@@ -104,14 +104,16 @@ 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
|
-
filename = name
|
107
|
+
filename = name || File.basename(path_to_file)
|
108
108
|
|
109
109
|
File.open(path_to_file) do |file|
|
110
|
-
upload_file_from_io(file, parent, name: filename, content_created_at: content_created_at,
|
110
|
+
upload_file_from_io(file, parent, name: filename, content_created_at: content_created_at,
|
111
|
+
content_modified_at: content_modified_at, preflight_check: preflight_check, send_content_md5: send_content_md5)
|
111
112
|
end
|
112
113
|
end
|
113
114
|
|
114
|
-
def upload_file_from_io(io, parent, name:, content_created_at: nil, content_modified_at: nil,
|
115
|
+
def upload_file_from_io(io, parent, name:, content_created_at: nil, content_modified_at: nil,
|
116
|
+
preflight_check: true, send_content_md5: true)
|
115
117
|
parent_id = ensure_id(parent)
|
116
118
|
|
117
119
|
preflight_check(io, name, parent_id) if preflight_check
|
@@ -121,49 +123,58 @@ module Boxr
|
|
121
123
|
io.rewind
|
122
124
|
end
|
123
125
|
|
124
|
-
attributes = {name: name, parent: {id: parent_id}}
|
125
|
-
|
126
|
-
|
126
|
+
attributes = { name: name, parent: { id: parent_id } }
|
127
|
+
unless content_created_at.nil?
|
128
|
+
attributes[:content_created_at] =
|
129
|
+
content_created_at.to_datetime.rfc3339
|
130
|
+
end
|
131
|
+
unless content_modified_at.nil?
|
132
|
+
attributes[:content_modified_at] =
|
133
|
+
content_modified_at.to_datetime.rfc3339
|
134
|
+
end
|
127
135
|
|
128
|
-
body = {attributes: JSON.dump(attributes), file: io}
|
136
|
+
body = { attributes: JSON.dump(attributes), file: io }
|
129
137
|
|
130
|
-
file_info,
|
138
|
+
file_info, = post(FILES_UPLOAD_URI, body, process_body: false,
|
139
|
+
content_md5: content_md5)
|
131
140
|
|
132
141
|
file_info.entries[0]
|
133
142
|
end
|
134
143
|
|
135
144
|
def upload_new_version_of_file(path_to_file, file, content_modified_at: nil, send_content_md5: true,
|
136
|
-
|
137
|
-
filename = name
|
145
|
+
preflight_check: true, if_match: nil, name: nil)
|
146
|
+
filename = name || File.basename(path_to_file)
|
138
147
|
|
139
148
|
File.open(path_to_file) do |io|
|
140
|
-
upload_new_version_of_file_from_io(io, file, name: filename,
|
149
|
+
upload_new_version_of_file_from_io(io, file, name: filename,
|
150
|
+
content_modified_at: content_modified_at, preflight_check: preflight_check, send_content_md5: send_content_md5, if_match: if_match)
|
141
151
|
end
|
142
152
|
end
|
143
153
|
|
144
154
|
def upload_new_version_of_file_from_io(io, file, name: nil, content_modified_at: nil, send_content_md5: true,
|
145
|
-
|
146
|
-
|
147
|
-
filename = name ? name : file.name
|
155
|
+
preflight_check: true, if_match: nil)
|
156
|
+
name || file.name
|
148
157
|
|
149
158
|
file_id = ensure_id(file)
|
150
159
|
preflight_check_new_version_of_file(io, file_id) if preflight_check
|
151
160
|
|
152
161
|
uri = "#{UPLOAD_URI}/files/#{file_id}/content"
|
153
|
-
file_info = nil
|
154
|
-
response = nil
|
155
162
|
|
156
163
|
if send_content_md5
|
157
164
|
content_md5 = Digest::SHA1.hexdigest(io.read)
|
158
165
|
io.rewind
|
159
166
|
end
|
160
167
|
|
161
|
-
attributes = {name: name}
|
162
|
-
|
168
|
+
attributes = { name: name }
|
169
|
+
unless content_modified_at.nil?
|
170
|
+
attributes[:content_modified_at] =
|
171
|
+
content_modified_at.to_datetime.rfc3339
|
172
|
+
end
|
163
173
|
|
164
|
-
body = {attributes: JSON.dump(attributes), file: io}
|
174
|
+
body = { attributes: JSON.dump(attributes), file: io }
|
165
175
|
|
166
|
-
file_info,
|
176
|
+
file_info, = post(uri, body, process_body: false, content_md5: content_md5,
|
177
|
+
if_match: if_match)
|
167
178
|
|
168
179
|
file_info.entries[0]
|
169
180
|
end
|
@@ -171,7 +182,7 @@ module Boxr
|
|
171
182
|
def versions_of_file(file)
|
172
183
|
file_id = ensure_id(file)
|
173
184
|
uri = "#{FILES_URI}/#{file_id}/versions"
|
174
|
-
versions,
|
185
|
+
versions, = get(uri)
|
175
186
|
versions.entries
|
176
187
|
end
|
177
188
|
|
@@ -180,15 +191,15 @@ module Boxr
|
|
180
191
|
file_version_id = ensure_id(file_version)
|
181
192
|
|
182
193
|
uri = "#{FILES_URI}/#{file_id}/versions/current"
|
183
|
-
attributes = {:
|
184
|
-
new_version,
|
194
|
+
attributes = { type: 'file_version', id: file_version_id }
|
195
|
+
new_version, = post(uri, attributes)
|
185
196
|
new_version
|
186
197
|
end
|
187
198
|
|
188
199
|
def delete_file(file, if_match: nil)
|
189
200
|
file_id = ensure_id(file)
|
190
201
|
uri = "#{FILES_URI}/#{file_id}"
|
191
|
-
result,
|
202
|
+
result, = delete(uri, if_match: if_match)
|
192
203
|
result
|
193
204
|
end
|
194
205
|
|
@@ -197,18 +208,20 @@ module Boxr
|
|
197
208
|
file_version_id = ensure_id(file_version)
|
198
209
|
|
199
210
|
uri = "#{FILES_URI}/#{file_id}/versions/#{file_version_id}"
|
200
|
-
result,
|
211
|
+
result, = delete(uri, if_match: if_match)
|
201
212
|
result
|
202
213
|
end
|
203
214
|
|
204
|
-
def copy_file(file, parent, name: nil)
|
215
|
+
def copy_file(file, parent, name: nil, version: nil)
|
205
216
|
file_id = ensure_id(file)
|
206
217
|
parent_id = ensure_id(parent)
|
218
|
+
version_id = ensure_id(version) unless version.nil?
|
207
219
|
|
208
220
|
uri = "#{FILES_URI}/#{file_id}/copy"
|
209
|
-
attributes = {:
|
221
|
+
attributes = { parent: { id: parent_id } }
|
210
222
|
attributes[:name] = name unless name.nil?
|
211
|
-
|
223
|
+
attributes[:version] = version_id unless version_id.nil?
|
224
|
+
new_file, = post(uri, attributes)
|
212
225
|
new_file
|
213
226
|
end
|
214
227
|
|
@@ -220,19 +233,21 @@ module Boxr
|
|
220
233
|
query[:min_width] = min_width unless min_width.nil?
|
221
234
|
query[:max_height] = max_height unless max_height.nil?
|
222
235
|
query[:max_width] = max_width unless max_width.nil?
|
223
|
-
body, response = get(uri, query: query, success_codes: [302,202,200],
|
236
|
+
body, response = get(uri, query: query, success_codes: [302, 202, 200],
|
237
|
+
process_response: false)
|
224
238
|
|
225
|
-
if
|
239
|
+
if [202, 302].include?(response.status)
|
226
240
|
location = response.header['Location'][0]
|
227
|
-
thumbnail,
|
228
|
-
else #200
|
241
|
+
thumbnail, = get(location, process_response: false)
|
242
|
+
else # 200
|
229
243
|
thumbnail = body
|
230
244
|
end
|
231
245
|
|
232
246
|
thumbnail
|
233
247
|
end
|
234
248
|
|
235
|
-
def create_shared_link_for_file(file, access: nil, unshared_at: nil, can_download: nil,
|
249
|
+
def create_shared_link_for_file(file, access: nil, unshared_at: nil, can_download: nil,
|
250
|
+
can_preview: nil, password: nil)
|
236
251
|
file_id = ensure_id(file)
|
237
252
|
uri = "#{FILES_URI}/#{file_id}"
|
238
253
|
create_shared_link(uri, file_id, access, unshared_at, can_download, can_preview, password)
|
@@ -249,7 +264,7 @@ module Boxr
|
|
249
264
|
uri = "#{FILES_URI}/#{file_id}/trash"
|
250
265
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
251
266
|
|
252
|
-
trashed_file,
|
267
|
+
trashed_file, = get(uri, query: query)
|
253
268
|
trashed_file
|
254
269
|
end
|
255
270
|
|
@@ -257,7 +272,7 @@ module Boxr
|
|
257
272
|
file_id = ensure_id(file)
|
258
273
|
uri = "#{FILES_URI}/#{file_id}/trash"
|
259
274
|
|
260
|
-
result,
|
275
|
+
result, = delete(uri)
|
261
276
|
result
|
262
277
|
end
|
263
278
|
|
@@ -274,16 +289,15 @@ module Boxr
|
|
274
289
|
def preflight_check(io, filename, parent_id)
|
275
290
|
size = io.size
|
276
291
|
|
277
|
-
#TODO: need to make sure that figuring out the filename from the path_to_file works for people using Windows
|
278
|
-
attributes = {name: filename, parent: {id:
|
279
|
-
|
292
|
+
# TODO: need to make sure that figuring out the filename from the path_to_file works for people using Windows
|
293
|
+
attributes = { name: filename, parent: { id: parent_id.to_s }, size: size }
|
294
|
+
options("#{FILES_URI}/content", attributes)
|
280
295
|
end
|
281
296
|
|
282
297
|
def preflight_check_new_version_of_file(io, file_id)
|
283
298
|
size = io.size
|
284
|
-
attributes = {size: size}
|
285
|
-
|
299
|
+
attributes = { size: size }
|
300
|
+
options("#{FILES_URI}/#{file_id}/content", attributes)
|
286
301
|
end
|
287
|
-
|
288
302
|
end
|
289
303
|
end
|
data/lib/boxr/folders.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Boxr
|
2
4
|
class Client
|
3
|
-
|
4
5
|
def folder_from_path(path)
|
5
|
-
if
|
6
|
-
path = path.slice(1..-1)
|
7
|
-
end
|
6
|
+
path = path.slice(1..-1) if path.start_with?('/')
|
8
7
|
|
9
8
|
path_folders = path.split('/')
|
10
9
|
|
11
10
|
folder = path_folders.inject(Boxr::ROOT) do |parent_folder, folder_name|
|
12
|
-
folders = folder_items(parent_folder, fields: [
|
13
|
-
folder = folders.select{|f| f.name.casecmp?(folder_name) }.first
|
11
|
+
folders = folder_items(parent_folder, fields: %i[id name]).folders
|
12
|
+
folder = folders.select { |f| f.name.casecmp?(folder_name) }.first
|
14
13
|
raise BoxrError.new(boxr_message: "Folder not found: '#{folder_name}'") if folder.nil?
|
14
|
+
|
15
15
|
folder
|
16
16
|
end
|
17
17
|
end
|
@@ -21,10 +21,10 @@ module Boxr
|
|
21
21
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
22
22
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
23
23
|
|
24
|
-
folder,
|
24
|
+
folder, = get(uri, query: query)
|
25
25
|
folder
|
26
26
|
end
|
27
|
-
alias
|
27
|
+
alias folder folder_from_id
|
28
28
|
|
29
29
|
def folder_items(folder, fields: [], offset: nil, limit: nil)
|
30
30
|
folder_id = ensure_id(folder)
|
@@ -32,11 +32,11 @@ module Boxr
|
|
32
32
|
uri = "#{FOLDERS_URI}/#{folder_id}/items"
|
33
33
|
|
34
34
|
if offset.nil? || limit.nil?
|
35
|
-
|
35
|
+
get_all_with_pagination(uri, query: query, offset: 0, limit: FOLDER_ITEMS_LIMIT)
|
36
36
|
else
|
37
37
|
query[:offset] = offset
|
38
38
|
query[:limit] = limit
|
39
|
-
items,
|
39
|
+
items, = get(uri, query: query)
|
40
40
|
items['entries']
|
41
41
|
end
|
42
42
|
end
|
@@ -48,16 +48,16 @@ module Boxr
|
|
48
48
|
def create_folder(name, parent)
|
49
49
|
parent_id = ensure_id(parent)
|
50
50
|
|
51
|
-
uri =
|
52
|
-
attributes = {:
|
51
|
+
uri = FOLDERS_URI.to_s
|
52
|
+
attributes = { name: name, parent: { id: parent_id } }
|
53
53
|
|
54
|
-
created_folder,
|
54
|
+
created_folder, = post(uri, attributes)
|
55
55
|
created_folder
|
56
56
|
end
|
57
57
|
|
58
58
|
def update_folder(folder, name: nil, description: nil, parent: nil, shared_link: nil,
|
59
|
-
|
60
|
-
|
59
|
+
folder_upload_email_access: nil, owned_by: nil, sync_state: nil, tags: nil,
|
60
|
+
can_non_owners_invite: nil, if_match: nil)
|
61
61
|
folder_id = ensure_id(folder)
|
62
62
|
parent_id = ensure_id(parent)
|
63
63
|
owned_by_id = ensure_id(owned_by)
|
@@ -66,15 +66,18 @@ module Boxr
|
|
66
66
|
attributes = {}
|
67
67
|
attributes[:name] = name unless name.nil?
|
68
68
|
attributes[:description] = description unless description.nil?
|
69
|
-
attributes[:parent] = {id: parent_id} unless parent_id.nil?
|
69
|
+
attributes[:parent] = { id: parent_id } unless parent_id.nil?
|
70
70
|
attributes[:shared_link] = shared_link unless shared_link.nil?
|
71
|
-
|
72
|
-
|
71
|
+
unless folder_upload_email_access.nil?
|
72
|
+
attributes[:folder_upload_email] =
|
73
|
+
{ access: folder_upload_email_access }
|
74
|
+
end
|
75
|
+
attributes[:owned_by] = { id: owned_by_id } unless owned_by_id.nil?
|
73
76
|
attributes[:sync_state] = sync_state unless sync_state.nil?
|
74
77
|
attributes[:tags] = tags unless tags.nil?
|
75
78
|
attributes[:can_non_owners_invite] = can_non_owners_invite unless can_non_owners_invite.nil?
|
76
79
|
|
77
|
-
updated_folder,
|
80
|
+
updated_folder, = put(uri, attributes, if_match: if_match)
|
78
81
|
updated_folder
|
79
82
|
end
|
80
83
|
|
@@ -85,9 +88,9 @@ module Boxr
|
|
85
88
|
def delete_folder(folder, recursive: false, if_match: nil)
|
86
89
|
folder_id = ensure_id(folder)
|
87
90
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
88
|
-
query = {:recursive
|
91
|
+
query = { recursive: recursive }
|
89
92
|
|
90
|
-
result,
|
93
|
+
result, = delete(uri, query: query, if_match: if_match)
|
91
94
|
result
|
92
95
|
end
|
93
96
|
|
@@ -96,14 +99,15 @@ module Boxr
|
|
96
99
|
dest_folder_id = ensure_id(dest_folder)
|
97
100
|
|
98
101
|
uri = "#{FOLDERS_URI}/#{folder_id}/copy"
|
99
|
-
attributes = {:
|
102
|
+
attributes = { parent: { id: dest_folder_id } }
|
100
103
|
attributes[:name] = name unless name.nil?
|
101
104
|
|
102
|
-
new_folder,
|
105
|
+
new_folder, = post(uri, attributes)
|
103
106
|
new_folder
|
104
107
|
end
|
105
108
|
|
106
|
-
def create_shared_link_for_folder(folder, access: nil, unshared_at: nil, can_download: nil,
|
109
|
+
def create_shared_link_for_folder(folder, access: nil, unshared_at: nil, can_download: nil,
|
110
|
+
can_preview: nil, password: nil)
|
107
111
|
folder_id = ensure_id(folder)
|
108
112
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
109
113
|
create_shared_link(uri, folder_id, access, unshared_at, can_download, can_preview, password)
|
@@ -120,11 +124,11 @@ module Boxr
|
|
120
124
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
121
125
|
|
122
126
|
if offset.nil? || limit.nil?
|
123
|
-
|
127
|
+
get_all_with_pagination(uri, query: query, offset: 0, limit: FOLDER_ITEMS_LIMIT)
|
124
128
|
else
|
125
129
|
query[:offset] = offset
|
126
130
|
query[:limit] = limit
|
127
|
-
items,
|
131
|
+
items, = get(uri, query: query)
|
128
132
|
items['entries']
|
129
133
|
end
|
130
134
|
end
|
@@ -134,14 +138,14 @@ module Boxr
|
|
134
138
|
uri = "#{FOLDERS_URI}/#{folder_id}/trash"
|
135
139
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
136
140
|
|
137
|
-
folder,
|
141
|
+
folder, = get(uri, query: query)
|
138
142
|
folder
|
139
143
|
end
|
140
144
|
|
141
145
|
def delete_trashed_folder(folder)
|
142
146
|
folder_id = ensure_id(folder)
|
143
147
|
uri = "#{FOLDERS_URI}/#{folder_id}/trash"
|
144
|
-
result,
|
148
|
+
result, = delete(uri)
|
145
149
|
result
|
146
150
|
end
|
147
151
|
|
@@ -152,6 +156,5 @@ module Boxr
|
|
152
156
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
153
157
|
restore_trashed_item(uri, name, parent_id)
|
154
158
|
end
|
155
|
-
|
156
159
|
end
|
157
160
|
end
|
data/lib/boxr/groups.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Boxr
|
2
4
|
class Client
|
3
|
-
|
4
5
|
def groups(fields: [], offset: 0, limit: DEFAULT_LIMIT)
|
5
6
|
query = build_fields_query(fields, GROUP_FIELDS_QUERY)
|
6
|
-
|
7
|
+
get_all_with_pagination(GROUPS_URI, query: query, offset: offset, limit: limit)
|
7
8
|
end
|
8
9
|
|
9
10
|
def group_from_id(group_id, fields: [])
|
@@ -11,83 +12,82 @@ module Boxr
|
|
11
12
|
uri = "#{GROUPS_URI}/#{group_id}"
|
12
13
|
query = build_fields_query(fields, GROUP_FIELDS_QUERY)
|
13
14
|
|
14
|
-
group,
|
15
|
+
group, = get(uri, query: query)
|
15
16
|
group
|
16
17
|
end
|
17
|
-
alias
|
18
|
+
alias group group_from_id
|
18
19
|
|
19
20
|
def create_group(name)
|
20
|
-
attributes = {name: name}
|
21
|
-
new_group,
|
22
|
-
new_group
|
21
|
+
attributes = { name: name }
|
22
|
+
new_group, = post(GROUPS_URI, attributes)
|
23
|
+
new_group
|
23
24
|
end
|
24
25
|
|
25
26
|
def update_group(group, name)
|
26
27
|
group_id = ensure_id(group)
|
27
28
|
uri = "#{GROUPS_URI}/#{group_id}"
|
28
|
-
attributes = {name: name}
|
29
|
+
attributes = { name: name }
|
29
30
|
|
30
|
-
updated_group,
|
31
|
+
updated_group, = put(uri, attributes)
|
31
32
|
updated_group
|
32
33
|
end
|
33
|
-
alias
|
34
|
+
alias rename_group update_group
|
34
35
|
|
35
36
|
def delete_group(group)
|
36
37
|
group_id = ensure_id(group)
|
37
38
|
uri = "#{GROUPS_URI}/#{group_id}"
|
38
|
-
result,
|
39
|
+
result, = delete(uri)
|
39
40
|
result
|
40
41
|
end
|
41
42
|
|
42
43
|
def group_memberships(group, offset: 0, limit: DEFAULT_LIMIT)
|
43
44
|
group_id = ensure_id(group)
|
44
45
|
uri = "#{GROUPS_URI}/#{group_id}/memberships"
|
45
|
-
|
46
|
+
get_all_with_pagination(uri, offset: offset, limit: limit)
|
46
47
|
end
|
47
48
|
|
48
49
|
def group_memberships_for_user(user, offset: 0, limit: DEFAULT_LIMIT)
|
49
50
|
user_id = ensure_id(user)
|
50
51
|
uri = "#{USERS_URI}/#{user_id}/memberships"
|
51
|
-
|
52
|
+
get_all_with_pagination(uri, offset: offset, limit: limit)
|
52
53
|
end
|
53
54
|
|
54
55
|
def group_memberships_for_me(offset: 0, limit: DEFAULT_LIMIT)
|
55
56
|
uri = "#{USERS_URI}/me/memberships"
|
56
|
-
|
57
|
+
get_all_with_pagination(uri, offset: offset, limit: limit)
|
57
58
|
end
|
58
59
|
|
59
60
|
def group_membership_from_id(membership_id)
|
60
61
|
membership_id = ensure_id(membership_id)
|
61
62
|
uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
|
62
|
-
membership,
|
63
|
+
membership, = get(uri)
|
63
64
|
membership
|
64
65
|
end
|
65
|
-
alias
|
66
|
+
alias group_membership group_membership_from_id
|
66
67
|
|
67
68
|
def add_user_to_group(user, group, role: nil)
|
68
69
|
user_id = ensure_id(user)
|
69
70
|
group_id = ensure_id(group)
|
70
71
|
|
71
|
-
attributes = {user: {id: user_id}, group: {id: group_id}}
|
72
|
+
attributes = { user: { id: user_id }, group: { id: group_id } }
|
72
73
|
attributes[:role] = role unless role.nil?
|
73
|
-
membership,
|
74
|
+
membership, = post(GROUP_MEMBERSHIPS_URI, attributes)
|
74
75
|
membership
|
75
76
|
end
|
76
77
|
|
77
78
|
def update_group_membership(membership, role)
|
78
79
|
membership_id = ensure_id(membership)
|
79
80
|
uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
|
80
|
-
attributes = {role: role}
|
81
|
-
updated_membership,
|
81
|
+
attributes = { role: role }
|
82
|
+
updated_membership, = put(uri, attributes)
|
82
83
|
updated_membership
|
83
84
|
end
|
84
85
|
|
85
86
|
def delete_group_membership(membership)
|
86
87
|
membership_id = ensure_id(membership)
|
87
88
|
uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
|
88
|
-
result,
|
89
|
+
result, = delete(uri)
|
89
90
|
result
|
90
91
|
end
|
91
|
-
|
92
92
|
end
|
93
93
|
end
|