class Boxr::Client
Constants
- API_URI
API_URI
= “wcheng.inside-box.net/api/2.0”UPLOAD_URI
= “upload.wcheng.inside-box.net/api/2.0”- AUTH_URI
- COLLABORATIONS_URI
- COLLABORATION_FIELDS
- COLLABORATION_FIELDS_QUERY
- COLLECTIONS_URI
- COMMENTS_URI
- COMMENT_FIELDS
- COMMENT_FIELDS_QUERY
- DEFAULT_LIMIT
- EVENTS_URI
- FILES_UPLOAD_URI
- FILES_URI
- FILE_METADATA_URI
- FOLDERS_URI
- FOLDER_AND_FILE_FIELDS
- FOLDER_AND_FILE_FIELDS_QUERY
- FOLDER_ITEMS_LIMIT
- FOLDER_METADATA_URI
- GROUPS_URI
- GROUP_FIELDS
- GROUP_FIELDS_QUERY
- GROUP_MEMBERSHIPS_URI
- METADATA_TEMPLATES_URI
- PARALLEL_GEM_REQUIREMENT
- REVOKE_AUTH_URI
- SEARCH_URI
- SHARED_ITEMS_URI
- TASKS_URI
- TASK_ASSIGNMENTS_URI
- TASK_FIELDS
- TASK_FIELDS_QUERY
- UPLOAD_URI
- USERS_URI
- USER_FIELDS
- USER_FIELDS_QUERY
- VALID_COLLABORATION_ROLES
- WEBHOOKS_URI
- WEB_LINKS_URI
- WEB_LINK_FIELDS
- WEB_LINK_FIELDS_QUERY
- ZIP_DOWNLOADS_URI
Attributes
access_token[R]
as_user_id[R]
client_id[R]
client_secret[R]
identifier[R]
refresh_token[R]
Public Class Methods
new( access_token=ENV['BOX_DEVELOPER_TOKEN'], refresh_token: nil, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'], enterprise_id: ENV['BOX_ENTERPRISE_ID'], jwt_private_key: ENV['JWT_PRIVATE_KEY'], jwt_private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'], jwt_public_key_id: ENV['JWT_PUBLIC_KEY_ID'], identifier: nil, as_user: nil, &token_refresh_listener)
click to toggle source
# File lib/boxr/client.rb, line 70 def initialize( access_token=ENV['BOX_DEVELOPER_TOKEN'], refresh_token: nil, client_id: ENV['BOX_CLIENT_ID'], client_secret: ENV['BOX_CLIENT_SECRET'], enterprise_id: ENV['BOX_ENTERPRISE_ID'], jwt_private_key: ENV['JWT_PRIVATE_KEY'], jwt_private_key_password: ENV['JWT_PRIVATE_KEY_PASSWORD'], jwt_public_key_id: ENV['JWT_PUBLIC_KEY_ID'], identifier: nil, as_user: nil, &token_refresh_listener) @access_token = access_token raise BoxrError.new(boxr_message: "Access token cannot be nil") if @access_token.nil? @refresh_token = refresh_token @client_id = client_id @client_secret = client_secret @enterprise_id = enterprise_id @jwt_private_key = jwt_private_key @jwt_private_key_password = jwt_private_key_password @jwt_public_key_id = jwt_public_key_id @identifier = identifier @as_user_id = ensure_id(as_user) @token_refresh_listener = token_refresh_listener end
Public Instance Methods
add_collaboration(item, accessible_by, role, fields: [], notify: nil, type: :folder)
click to toggle source
# File lib/boxr/collaborations.rb, line 30 def add_collaboration(item, accessible_by, role, fields: [], notify: nil, type: :folder) item_id = ensure_id(item) query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY) query[:notify] = notify unless notify.nil? attributes = {item: {id: item_id, type: type}} attributes[:accessible_by] = accessible_by attributes[:role] = validate_role(role) collaboration, response = post(COLLABORATIONS_URI, attributes, query: query) collaboration end
add_comment_to_file(file, message: nil, tagged_message: nil)
click to toggle source
# File lib/boxr/comments.rb, line 12 def add_comment_to_file(file, message: nil, tagged_message: nil) file_id = ensure_id(file) add_comment(:file, file_id, message, tagged_message) end
add_email_alias_for_user(user, email)
click to toggle source
# File lib/boxr/users.rb, line 131 def add_email_alias_for_user(user, email) user_id = ensure_id(user) uri = "#{USERS_URI}/#{user_id}/email_aliases" attributes = {email: email} updated_user, response = post(uri, attributes) updated_user end
add_user_to_group(user, group, role: nil)
click to toggle source
# File lib/boxr/groups.rb, line 67 def add_user_to_group(user, group, role: nil) user_id = ensure_id(user) group_id = ensure_id(group) attributes = {user: {id: user_id}, group: {id: group_id}} attributes[:role] = role unless role.nil? membership, response = post(GROUP_MEMBERSHIPS_URI, attributes) membership end
all_folder_metadata(folder)
click to toggle source
# File lib/boxr/metadata.rb, line 32 def all_folder_metadata(folder) folder_id = ensure_id(folder) uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata" all_metadata, response = get(uri) all_metadata end
all_metadata(file)
click to toggle source
# File lib/boxr/metadata.rb, line 39 def all_metadata(file) file_id = ensure_id(file) uri = "#{FILE_METADATA_URI}/#{file_id}/metadata" all_metadata, response = get(uri) all_metadata end
all_users(filter_term: nil, fields: [], offset: nil, limit: nil)
click to toggle source
# File lib/boxr/users.rb, line 23 def all_users(filter_term: nil, fields: [], offset: nil, limit: nil) uri = USERS_URI query = build_fields_query(fields, USER_FIELDS_QUERY) query[:filter_term] = filter_term unless filter_term.nil? if offset.nil? || limit.nil? users = get_all_with_pagination(uri, query: query, offset: 0, limit: DEFAULT_LIMIT) else query[:offset] = offset query[:limit] = limit users, response = get(uri, query: query) users['entries'] end end
apply_watermark_on_file(file)
click to toggle source
# File lib/boxr/watermarking.rb, line 13 def apply_watermark_on_file(file) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/watermark" attributes = {} attributes[:watermark] = {:imprint => "default"} file, response = put(uri, attributes, content_type: "application/json") file end
apply_watermark_on_folder(folder)
click to toggle source
# File lib/boxr/watermarking.rb, line 43 def apply_watermark_on_folder(folder) folder_id = ensure_id(folder) uri = "#{FOLDERS_URI}/#{folder_id}/watermark" attributes = {} attributes[:watermark] = {:imprint => "default"} folder, response = put(uri, attributes, content_type: "application/json") folder end
change_comment(comment, message)
click to toggle source
# File lib/boxr/comments.rb, line 22 def change_comment(comment, message) comment_id = ensure_id(comment) uri = "#{COMMENTS_URI}/#{comment_id}" attributes = {message: message} updated_comment, response = put(uri, attributes) updated_comment end
chunked_upload_abort_session(session_id)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 107 def chunked_upload_abort_session(session_id) uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}" abort_info, response = delete(uri) abort_info end
chunked_upload_commit(path_to_file, session_id, parts, content_created_at: nil, content_modified_at: nil, if_match: nil, if_non_match: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 78 def chunked_upload_commit(path_to_file, session_id, parts, content_created_at: nil, content_modified_at: nil, if_match: nil, if_non_match: nil) File.open(path_to_file) do |file| chunked_upload_commit_from_io(file, session_id, parts, content_created_at: content_created_at, content_modified_at: content_modified_at, if_match: if_match, if_non_match: if_non_match) end end
chunked_upload_commit_from_io(io, session_id, parts, content_created_at: nil, content_modified_at: nil, if_match: nil, if_non_match: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 84 def chunked_upload_commit_from_io(io, session_id, parts, content_created_at: nil, content_modified_at: nil, if_match: nil, if_non_match: nil) io.pos = 0 digest = Digest::SHA1.new while (buf = io.read(8 * 1024**2)) && buf.size > 0 digest.update(buf) end io.rewind digest = "sha=#{digest.base64digest}" attributes = {} attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil? attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil? uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}/commit" body = { parts: parts, attributes: attributes } commit_info, response = post(uri, body, process_body: true, digest: digest, content_type: "application/json", if_match: if_match, if_non_match: if_non_match, success_codes: [200,201,202]) commit_info end
chunked_upload_create_session_new_file(path_to_file, parent, name: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 4 def chunked_upload_create_session_new_file(path_to_file, parent, name: nil) filename = name ? name : File.basename(path_to_file) File.open(path_to_file) do |file| chunked_upload_create_session_new_file_from_io(file, parent, filename) end end
chunked_upload_create_session_new_file_from_io(io, parent, name)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 12 def chunked_upload_create_session_new_file_from_io(io, parent, name) parent_id = ensure_id(parent) uri = "#{UPLOAD_URI}/files/upload_sessions" body = {folder_id: parent_id, file_size: io.size, file_name: name} session_info, response = post(uri, body, content_type: "application/json", success_codes: [200,201,202]) session_info end
chunked_upload_create_session_new_version(path_to_file, file, name: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 22 def chunked_upload_create_session_new_version(path_to_file, file, name: nil) filename = name ? name : File.basename(path_to_file) File.open(path_to_file) do |io| chunked_upload_create_session_new_version_from_io(io, file, filename) end end
chunked_upload_create_session_new_version_from_io(io, file, name)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 30 def chunked_upload_create_session_new_version_from_io(io, file, name) file_id = ensure_id(file) uri = "#{UPLOAD_URI}/files/#{file_id}/upload_sessions" body = {file_size: io.size, file_name: name} session_info, response = post(uri, body, content_type: "application/json", success_codes: [200,201,202]) session_info end
chunked_upload_file(path_to_file, parent, name: nil, n_threads: 1, content_created_at: nil, content_modified_at: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 114 def chunked_upload_file(path_to_file, parent, name: nil, n_threads: 1, content_created_at: nil, content_modified_at: nil) filename = name ? name : File.basename(path_to_file) File.open(path_to_file) do |file| chunked_upload_file_from_io(file, parent, filename, n_threads: n_threads, content_created_at: content_created_at, content_modified_at: content_modified_at) end end
chunked_upload_file_from_io(io, parent, name, n_threads: 1, content_created_at: nil, content_modified_at: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 122 def chunked_upload_file_from_io(io, parent, name, n_threads: 1, content_created_at: nil, content_modified_at: nil) session = nil file_info = nil session = chunked_upload_create_session_new_file_from_io(io, parent, name) file_info = chunked_upload_to_session_from_io(io, session, n_threads: n_threads, content_created_at: nil, content_modified_at: nil) file_info ensure chunked_upload_abort_session(session.id) if file_info.nil? && !session.nil? end
chunked_upload_get_session(session_id)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 39 def chunked_upload_get_session(session_id) uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}" session_info, response = get(uri) session_info end
chunked_upload_list_parts(session_id, limit: nil, offset: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 68 def chunked_upload_list_parts(session_id, limit: nil, offset: nil) uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}/parts" query = {} query[:limit] = limit unless limit.nil? query[:offset] = offset unless offset.nil? parts_info, response = get(uri, query: query) parts_info.entries end
chunked_upload_new_version_of_file(path_to_file, file, name: nil, n_threads: 1, content_created_at: nil, content_modified_at: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 134 def chunked_upload_new_version_of_file(path_to_file, file, name: nil, n_threads: 1, content_created_at: nil, content_modified_at: nil) filename = name ? name : File.basename(path_to_file) File.open(path_to_file) do |io| chunked_upload_new_version_of_file_from_io(io, file, filename, n_threads: n_threads, content_created_at: content_created_at, content_modified_at: content_modified_at) end end
chunked_upload_new_version_of_file_from_io(io, file, name, n_threads: 1, content_created_at: nil, content_modified_at: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 142 def chunked_upload_new_version_of_file_from_io(io, file, name, n_threads: 1, content_created_at: nil, content_modified_at: nil) session = nil file_info = nil session = chunked_upload_create_session_new_version_from_io(io, file, name) file_info = chunked_upload_to_session_from_io(io, session, n_threads: n_threads, content_created_at: nil, content_modified_at: nil) file_info ensure chunked_upload_abort_session(session.id) if file_info.nil? && !session.nil? end
chunked_upload_part(path_to_file, session_id, content_range)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 46 def chunked_upload_part(path_to_file, session_id, content_range) File.open(path_to_file) do |file| chunked_upload_part_from_io(file, session_id, content_range) end end
chunked_upload_part_from_io(io, session_id, content_range)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 52 def chunked_upload_part_from_io(io, session_id, content_range) io.pos = content_range.min part_size = content_range.max - content_range.min + 1 data = io.read(part_size) io.rewind digest = "sha=#{Digest::SHA1.base64digest(data)}" range = "bytes #{content_range.min}-#{content_range.max}/#{io.size}" uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}" body = data part_info, response = put(uri, body, process_body: false, digest: digest, content_type: "application/octet-stream", content_range: range, success_codes: [200,201,202]) part_info.part end
collaboration(collaboration_id, fields: [], status: nil)
click to toggle source
# File lib/boxr/collaborations.rb, line 61 def collaboration(collaboration_id, fields: [], status: nil) collaboration_id = ensure_id(collaboration_id) uri = "#{COLLABORATIONS_URI}/#{collaboration_id}" query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY) query[:status] = status unless status.nil? collaboration, response = get(uri, query: query) collaboration end
collection_items(collection, fields: [])
click to toggle source
# File lib/boxr/collections.rb, line 8 def collection_items(collection, fields: []) collection_id = ensure_id(collection) uri = "#{COLLECTIONS_URI}/#{collection_id}/items" query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY) items = get_all_with_pagination(uri, query: query, offset: 0, limit: DEFAULT_LIMIT) end
collections()
click to toggle source
# File lib/boxr/collections.rb, line 4 def collections collections = get_all_with_pagination(COLLECTIONS_URI, offset: 0, limit: DEFAULT_LIMIT) end
comment_from_id(comment_id, fields: [])
click to toggle source
# File lib/boxr/comments.rb, line 30 def comment_from_id(comment_id, fields: []) comment_id = ensure_id(comment_id) uri ="#{COMMENTS_URI}/#{comment_id}" comment, response = get(uri) comment end
Also aliased as: comment
copy_file(file, parent, name: nil)
click to toggle source
# File lib/boxr/files.rb, line 204 def copy_file(file, parent, name: nil) file_id = ensure_id(file) parent_id = ensure_id(parent) uri = "#{FILES_URI}/#{file_id}/copy" attributes = {:parent => {:id => parent_id}} attributes[:name] = name unless name.nil? new_file, res = post(uri, attributes) new_file end
copy_folder(folder, dest_folder, name: nil)
click to toggle source
# File lib/boxr/folders.rb, line 94 def copy_folder(folder, dest_folder, name: nil) folder_id = ensure_id(folder) dest_folder_id = ensure_id(dest_folder) uri = "#{FOLDERS_URI}/#{folder_id}/copy" attributes = {:parent => {:id => dest_folder_id}} attributes[:name] = name unless name.nil? new_folder, response = post(uri, attributes) new_folder end
create_folder(name, parent)
click to toggle source
# File lib/boxr/folders.rb, line 48 def create_folder(name, parent) parent_id = ensure_id(parent) uri = "#{FOLDERS_URI}" attributes = {:name => name, :parent => {:id => parent_id}} created_folder, response = post(uri, attributes) created_folder end
create_folder_metadata(folder, metadata, scope, template)
click to toggle source
# File lib/boxr/metadata.rb, line 11 def create_folder_metadata(folder, metadata, scope, template) folder_id = ensure_id(folder) uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}" metadata, response = post(uri, metadata, content_type: "application/json") metadata end
create_group(name)
click to toggle source
# File lib/boxr/groups.rb, line 19 def create_group(name) attributes = {name: name} new_group, response = post(GROUPS_URI, attributes) new_group end
create_metadata(file, metadata, scope: :global, template: :properties)
click to toggle source
# File lib/boxr/metadata.rb, line 4 def create_metadata(file, metadata, scope: :global, template: :properties) file_id = ensure_id(file) uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}" metadata, response = post(uri, metadata, content_type: "application/json") metadata end
create_metadata_template(display_name, template_key: nil, fields: [], hidden: nil)
click to toggle source
# File lib/boxr/metadata.rb, line 103 def create_metadata_template(display_name, template_key: nil, fields: [], hidden: nil) uri = "#{METADATA_TEMPLATES_URI}/schema" schema = { scope: "enterprise", displayName: display_name, } schema[:templateKey] = template_key unless template_key.nil? schema[:hidden] = hidden unless hidden.nil? schema[:fields] = fields unless fields.empty? metadata_template, response = post(uri, schema, content_type: "application/json") metadata_template end
create_task(file, action: :review, message: nil, due_at: nil)
click to toggle source
# File lib/boxr/tasks.rb, line 13 def create_task(file, action: :review, message: nil, due_at: nil) file_id = ensure_id(file) attributes = {item: {type: :file, id: file_id}} attributes[:action] = action unless action.nil? attributes[:message] = message unless message.nil? attributes[:due_at] = due_at.to_datetime.rfc3339 unless due_at.nil? new_task, response = post(TASKS_URI, attributes) new_task end
create_task_assignment(task, assign_to: nil, assign_to_login: nil)
click to toggle source
# File lib/boxr/tasks.rb, line 58 def create_task_assignment(task, assign_to: nil, assign_to_login: nil) task_id = ensure_id(task) assign_to_id = ensure_id(assign_to) attributes = {task: {type: :task, id: "#{task_id}"}} attributes[:assign_to] = {} attributes[:assign_to][:login] = assign_to_login unless assign_to_login.nil? attributes[:assign_to][:id] = assign_to_id unless assign_to_id.nil? new_task_assignment, response = post(TASK_ASSIGNMENTS_URI, attributes) new_task_assignment end
create_user(name, login: nil, role: nil, language: nil, is_sync_enabled: nil, job_title: nil, phone: nil, address: nil, space_amount: nil, tracking_codes: nil, can_see_managed_users: nil, is_external_collab_restricted: nil, status: nil, timezone: nil, is_exempt_from_device_limits: nil, is_exempt_from_login_verification: nil, is_platform_access_only: nil)
click to toggle source
# File lib/boxr/users.rb, line 39 def create_user(name, login: nil, role: nil, language: nil, is_sync_enabled: nil, job_title: nil, phone: nil, address: nil, space_amount: nil, tracking_codes: nil, can_see_managed_users: nil, is_external_collab_restricted: nil, status: nil, timezone: nil, is_exempt_from_device_limits: nil, is_exempt_from_login_verification: nil, is_platform_access_only: nil) uri = USERS_URI attributes = {name: name} attributes[:login] = login unless login.nil? #login is not required for platform users, so needed to make this optional attributes[:role] = role unless role.nil? attributes[:language] = language unless language.nil? attributes[:is_sync_enabled] = is_sync_enabled unless is_sync_enabled.nil? attributes[:job_title] = job_title unless job_title.nil? attributes[:phone] = phone unless phone.nil? attributes[:address] = address unless address.nil? attributes[:space_amount] = space_amount unless space_amount.nil? attributes[:tracking_codes] = tracking_codes unless tracking_codes.nil? attributes[:can_see_managed_users] = can_see_managed_users unless can_see_managed_users.nil? attributes[:is_external_collab_restricted] = is_external_collab_restricted unless is_external_collab_restricted.nil? attributes[:status] = status unless status.nil? attributes[:timezone] = timezone unless timezone.nil? attributes[:is_exempt_from_device_limits] = is_exempt_from_device_limits unless is_exempt_from_device_limits.nil? attributes[:is_exempt_from_login_verification] = is_exempt_from_login_verification unless is_exempt_from_login_verification.nil? attributes[:is_platform_access_only] = is_platform_access_only unless is_platform_access_only.nil? new_user, response = post(uri, attributes) new_user end
create_web_link(url, parent, name: nil, description: nil)
click to toggle source
# File lib/boxr/web_links.rb, line 4 def create_web_link(url, parent, name: nil, description: nil) parent_id = ensure_id(parent) web_link_url = verify_url(url) uri = "#{WEB_LINKS_URI}" attributes = {} attributes[:url] = web_link_url attributes[:parent] = {:id => parent_id} attributes[:name] = name unless name.nil? attributes[:description] = description unless description.nil? created_link, response = post(uri, attributes) created_link end
create_webhook(target_id, target_type, triggers, address)
click to toggle source
# File lib/boxr/webhooks.rb, line 5 def create_webhook(target_id, target_type, triggers, address) attributes = { target: { id: target_id, type: target_type }, triggers: triggers, address: address } new_webhook, response = post(WEBHOOKS_URI, attributes) new_webhook end
create_zip_download(targets, download_file_name: nil)
click to toggle source
# File lib/boxr/zip_downloads.rb, line 5 def create_zip_download(targets, download_file_name: nil) attributes = { download_file_name: download_file_name, items: targets } zip_download, _response = post(ZIP_DOWNLOADS_URI, attributes, success_codes: [200, 202]) zip_download end
current_user(fields: [])
click to toggle source
# File lib/boxr/users.rb, line 4 def current_user(fields: []) uri = "#{USERS_URI}/me" query = build_fields_query(fields, USER_FIELDS_QUERY) user, response = get(uri, query: query) user end
Also aliased as: me
delete_comment(comment)
click to toggle source
# File lib/boxr/comments.rb, line 38 def delete_comment(comment) comment_id = ensure_id(comment) uri = "#{COMMENTS_URI}/#{comment_id}" result, response = delete(uri) result end
delete_file(file, if_match: nil)
click to toggle source
# File lib/boxr/files.rb, line 188 def delete_file(file, if_match: nil) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}" result, response = delete(uri, if_match: if_match) result end
delete_folder(folder, recursive: false, if_match: nil)
click to toggle source
# File lib/boxr/folders.rb, line 85 def delete_folder(folder, recursive: false, if_match: nil) folder_id = ensure_id(folder) uri = "#{FOLDERS_URI}/#{folder_id}" query = {:recursive => recursive} result, response = delete(uri, query: query, if_match: if_match) result end
delete_folder_metadata(folder, scope, template)
click to toggle source
# File lib/boxr/metadata.rb, line 75 def delete_folder_metadata(folder, scope, template) folder_id = ensure_id(folder) uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}" result, response = delete(uri) result end
delete_group(group)
click to toggle source
# File lib/boxr/groups.rb, line 35 def delete_group(group) group_id = ensure_id(group) uri = "#{GROUPS_URI}/#{group_id}" result, response = delete(uri) result end
delete_group_membership(membership)
click to toggle source
# File lib/boxr/groups.rb, line 85 def delete_group_membership(membership) membership_id = ensure_id(membership) uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}" result, response = delete(uri) result end
delete_metadata(file, scope: :global, template: :properties)
click to toggle source
# File lib/boxr/metadata.rb, line 68 def delete_metadata(file, scope: :global, template: :properties) file_id = ensure_id(file) uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}" result, response = delete(uri) result end
delete_metadata_template(scope, template_key)
click to toggle source
# File lib/boxr/metadata.rb, line 117 def delete_metadata_template(scope, template_key) uri = "#{METADATA_TEMPLATES_URI}/#{scope}/#{template_key}/schema" result, response = delete(uri) result end
delete_old_version_of_file(file, file_version, if_match: nil)
click to toggle source
# File lib/boxr/files.rb, line 195 def delete_old_version_of_file(file, file_version, if_match: nil) file_id = ensure_id(file) file_version_id = ensure_id(file_version) uri = "#{FILES_URI}/#{file_id}/versions/#{file_version_id}" result, response = delete(uri, if_match: if_match) result end
delete_task(task)
click to toggle source
# File lib/boxr/tasks.rb, line 44 def delete_task(task) task_id = ensure_id(task) uri = "#{TASKS_URI}/#{task_id}" result, response = delete(uri) result end
delete_task_assignment(task)
click to toggle source
# File lib/boxr/tasks.rb, line 78 def delete_task_assignment(task) task_id = ensure_id(task) uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}" result, response = delete(uri) result end
delete_trashed_file(file)
click to toggle source
# File lib/boxr/files.rb, line 256 def delete_trashed_file(file) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/trash" result, response = delete(uri) result end
delete_trashed_folder(folder)
click to toggle source
# File lib/boxr/folders.rb, line 141 def delete_trashed_folder(folder) folder_id = ensure_id(folder) uri = "#{FOLDERS_URI}/#{folder_id}/trash" result, response = delete(uri) result end
delete_trashed_web_link(web_link)
click to toggle source
# File lib/boxr/web_links.rb, line 64 def delete_trashed_web_link(web_link) web_link_id = ensure_id(web_link) uri = "#{WEB_LINKS_URI}/#{web_link_id}/trash" result, response = delete(uri) result end
delete_user(user, notify: nil, force: nil)
click to toggle source
# File lib/boxr/users.rb, line 100 def delete_user(user, notify: nil, force: nil) user_id = ensure_id(user) uri = "#{USERS_URI}/#{user_id}" query = {} query[:notify] = notify unless notify.nil? query[:force] = force unless force.nil? result, response = delete(uri, query: query) result end
delete_web_link(web_link)
click to toggle source
# File lib/boxr/web_links.rb, line 45 def delete_web_link(web_link) web_link_id = ensure_id(web_link) uri = "#{WEB_LINKS_URI}/#{web_link_id}" result, response = delete(uri) result end
delete_webhook(webhook)
click to toggle source
# File lib/boxr/webhooks.rb, line 31 def delete_webhook(webhook) webhook_id = ensure_id(webhook) uri = "#{WEBHOOKS_URI}/#{webhook_id}" result, response = delete(uri) result end
download_file(file, version: nil, follow_redirect: true)
click to toggle source
# File lib/boxr/files.rb, line 76 def download_file(file, version: nil, follow_redirect: true) file_id = ensure_id(file) begin uri = "#{FILES_URI}/#{file_id}/content" query = {} query[:version] = version unless version.nil? body_json, 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 if(response.status==302) location = response.header['Location'][0] if(follow_redirect) file_content, response = get(location, process_response: false) return file_content else return location #simply return the url end elsif(response.status==202) retry_after_seconds = response.header['Retry-After'][0] sleep retry_after_seconds.to_i end end until file_content end
download_url(file, version: nil)
click to toggle source
# File lib/boxr/files.rb, line 101 def download_url(file, version: nil) download_file(file, version: version, follow_redirect: false) end
edit_collaboration(collaboration, role: nil, status: nil)
click to toggle source
# File lib/boxr/collaborations.rb, line 43 def edit_collaboration(collaboration, role: nil, status: nil) collaboration_id = ensure_id(collaboration) uri = "#{COLLABORATIONS_URI}/#{collaboration_id}" attributes = {} attributes[:role] = validate_role(role) unless role.nil? attributes[:status] = status unless status.nil? updated_collaboration, response = put(uri, attributes) updated_collaboration end
email_aliases_for_user(user)
click to toggle source
# File lib/boxr/users.rb, line 123 def email_aliases_for_user(user) user_id = ensure_id(user) uri = "#{USERS_URI}/#{user_id}/email_aliases" aliases, response = get(uri) aliases['entries'] end
embed_url(file, show_download: false, show_annotations: false)
click to toggle source
# File lib/boxr/files.rb, line 29 def embed_url(file, show_download: false, show_annotations: false) file_info = file_from_id(file, fields:[:expiring_embed_link]) url = file_info.expiring_embed_link.url + "?showDownload=#{show_download}&showAnnotations=#{show_annotations}" url end
enterprise_events(created_after: nil, created_before: nil, stream_position: 0, event_type: nil, limit: 500)
click to toggle source
# File lib/boxr/events.rb, line 11 def enterprise_events(created_after: nil, created_before: nil, stream_position: 0, event_type: nil, limit: 500) events = [] loop do event_response = get_enterprise_events(created_after, created_before, stream_position, event_type, limit) events.concat(event_response.events) stream_position = event_response.next_stream_position break if event_response.events.empty? end BoxrMash.new({events: events, next_stream_position: stream_position}) end
enterprise_events_stream(initial_stream_position, event_type: nil, limit: 500, refresh_period: 300) { |response| ... }
click to toggle source
# File lib/boxr/events.rb, line 23 def enterprise_events_stream(initial_stream_position, event_type: nil, limit: 500, refresh_period: 300) stream_position = initial_stream_position loop do response = enterprise_events(stream_position: stream_position, event_type: event_type, limit: limit) yield(response) if block_given? stream_position = response.next_stream_position sleep refresh_period end end
enterprise_metadata()
click to toggle source
# File lib/boxr/metadata.rb, line 82 def enterprise_metadata uri = "#{METADATA_TEMPLATES_URI}/enterprise" ent_metadata, response = get(uri) ent_metadata end
Also aliased as: get_enterprise_templates
file_collaborations(file, fields: [], limit: DEFAULT_LIMIT, marker: nil)
click to toggle source
# File lib/boxr/collaborations.rb, line 11 def file_collaborations(file, fields: [], limit: DEFAULT_LIMIT, marker: nil) file_id = ensure_id(file) query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY) query[:limit] = limit query[:marker] = marker unless marker.nil? uri = "#{FILES_URI}/#{file_id}/collaborations" collaborations, response = get(uri, query: query) collaborations['entries'] end
file_comments(file, fields: [])
click to toggle source
# File lib/boxr/comments.rb, line 4 def file_comments(file, fields: []) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/comments" query = build_fields_query(fields, COMMENT_FIELDS_QUERY) comments = get_all_with_pagination(uri, query: query, offset: 0, limit: DEFAULT_LIMIT) end
file_from_id(file_id, fields: [])
click to toggle source
# File lib/boxr/files.rb, line 20 def file_from_id(file_id, fields: []) file_id = ensure_id(file_id) uri = "#{FILES_URI}/#{file_id}" query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY) file, response = get(uri, query: query) file end
Also aliased as: file
file_from_path(path)
click to toggle source
# File lib/boxr/files.rb, line 4 def file_from_path(path) if(path.start_with?('/')) path = path.slice(1..-1) end path_items = path.split('/') file_name = path_items.slice!(-1) folder = folder_from_path(path_items.join('/')) files = folder_items(folder, fields: [:id, :name]).files file = files.select{|f| f.name.casecmp?(file_name) }.first raise BoxrError.new(boxr_message: "File not found: '#{file_name}'") if file.nil? file end
file_tasks(file, fields: [])
click to toggle source
# File lib/boxr/tasks.rb, line 4 def file_tasks(file, fields: []) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/tasks" query = build_fields_query(fields, TASK_FIELDS_QUERY) tasks, response = get(uri, query: query) tasks.entries end
folder_collaborations(folder, fields: [], offset: 0, limit: DEFAULT_LIMIT)
click to toggle source
# File lib/boxr/collaborations.rb, line 4 def folder_collaborations(folder, fields: [], offset: 0, limit: DEFAULT_LIMIT) folder_id = ensure_id(folder) query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY) uri = "#{FOLDERS_URI}/#{folder_id}/collaborations" collaborations = get_all_with_pagination(uri, query: query, offset: offset, limit: limit) end
folder_from_id(folder_id, fields: [])
click to toggle source
# File lib/boxr/folders.rb, line 19 def folder_from_id(folder_id, fields: []) folder_id = ensure_id(folder_id) query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY) uri = "#{FOLDERS_URI}/#{folder_id}" folder, response = get(uri, query: query) folder end
Also aliased as: folder
folder_from_path(path)
click to toggle source
# File lib/boxr/folders.rb, line 4 def folder_from_path(path) if(path.start_with?('/')) path = path.slice(1..-1) end path_folders = path.split('/') folder = path_folders.inject(Boxr::ROOT) do |parent_folder, folder_name| folders = folder_items(parent_folder, fields: [:id, :name]).folders folder = folders.select{|f| f.name.casecmp?(folder_name) }.first raise BoxrError.new(boxr_message: "Folder not found: '#{folder_name}'") if folder.nil? folder end end
folder_items(folder, fields: [], offset: nil, limit: nil)
click to toggle source
# File lib/boxr/folders.rb, line 29 def folder_items(folder, fields: [], offset: nil, limit: nil) folder_id = ensure_id(folder) query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY) uri = "#{FOLDERS_URI}/#{folder_id}/items" if offset.nil? || limit.nil? items = get_all_with_pagination(uri, query: query, offset: 0, limit: FOLDER_ITEMS_LIMIT) else query[:offset] = offset query[:limit] = limit items, response = get(uri, query: query) items['entries'] end end
folder_metadata(folder, scope, template)
click to toggle source
# File lib/boxr/metadata.rb, line 25 def folder_metadata(folder, scope, template) folder_id = ensure_id(folder) uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}" metadata, response = get(uri) metadata end
get_metadata_template_by_id(template_id)
click to toggle source
# File lib/boxr/metadata.rb, line 96 def get_metadata_template_by_id(template_id) template_id = ensure_id(template_id) uri = "#{METADATA_TEMPLATES_URI}/#{template_id}" schema, response = get(uri) schema end
get_watermark_on_file(file)
click to toggle source
# File lib/boxr/watermarking.rb, line 4 def get_watermark_on_file(file) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/watermark" file, response = get(uri) file end
get_watermark_on_folder(folder)
click to toggle source
# File lib/boxr/watermarking.rb, line 34 def get_watermark_on_folder(folder) folder_id = ensure_id(folder) uri = "#{FOLDERS_URI}/#{folder_id}/watermark" folder, response = get(uri) folder end
get_web_link(web_link)
click to toggle source
# File lib/boxr/web_links.rb, line 20 def get_web_link(web_link) web_link_id = ensure_id(web_link) uri = "#{WEB_LINKS_URI}/#{web_link_id}" web_link, response = get(uri) web_link end
get_webhook(webhook)
click to toggle source
# File lib/boxr/webhooks.rb, line 17 def get_webhook(webhook) webhook_id = ensure_id(webhook) uri = "#{WEBHOOKS_URI}/#{webhook_id}" webhook, response = get(uri) webhook end
get_webhooks(marker: nil, limit: nil)
click to toggle source
# File lib/boxr/webhooks.rb, line 11 def get_webhooks(marker: nil, limit: nil) query_params = { marker: marker, limit: limit }.compact webhooks, response = get(WEBHOOKS_URI, query: query_params) webhooks end
group_collaborations(group, offset: 0, limit: DEFAULT_LIMIT)
click to toggle source
# File lib/boxr/collaborations.rb, line 23 def group_collaborations(group, offset: 0, limit: DEFAULT_LIMIT) group_id = ensure_id(group) uri = "#{GROUPS_URI}/#{group_id}/collaborations" collaborations = get_all_with_pagination(uri, offset: offset, limit: limit) end
group_from_id(group_id, fields: [])
click to toggle source
# File lib/boxr/groups.rb, line 9 def group_from_id(group_id, fields: []) group_id = ensure_id(group_id) uri = "#{GROUPS_URI}/#{group_id}" query = build_fields_query(fields, GROUP_FIELDS_QUERY) group, response = get(uri, query: query) group end
Also aliased as: group
group_membership_from_id(membership_id)
click to toggle source
# File lib/boxr/groups.rb, line 59 def group_membership_from_id(membership_id) membership_id = ensure_id(membership_id) uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}" membership, response = get(uri) membership end
Also aliased as: group_membership
group_memberships(group, offset: 0, limit: DEFAULT_LIMIT)
click to toggle source
# File lib/boxr/groups.rb, line 42 def group_memberships(group, offset: 0, limit: DEFAULT_LIMIT) group_id = ensure_id(group) uri = "#{GROUPS_URI}/#{group_id}/memberships" memberships = get_all_with_pagination(uri, offset: offset, limit: limit) end
group_memberships_for_me(offset: 0, limit: DEFAULT_LIMIT)
click to toggle source
# File lib/boxr/groups.rb, line 54 def group_memberships_for_me(offset: 0, limit: DEFAULT_LIMIT) uri = "#{USERS_URI}/me/memberships" memberships = get_all_with_pagination(uri, offset: offset, limit: limit) end
group_memberships_for_user(user, offset: 0, limit: DEFAULT_LIMIT)
click to toggle source
# File lib/boxr/groups.rb, line 48 def group_memberships_for_user(user, offset: 0, limit: DEFAULT_LIMIT) user_id = ensure_id(user) uri = "#{USERS_URI}/#{user_id}/memberships" memberships = get_all_with_pagination(uri, offset: offset, limit: limit) end
groups(fields: [], offset: 0, limit: DEFAULT_LIMIT)
click to toggle source
# File lib/boxr/groups.rb, line 4 def groups(fields: [], offset: 0, limit: DEFAULT_LIMIT) query = build_fields_query(fields, GROUP_FIELDS_QUERY) groups = get_all_with_pagination(GROUPS_URI, query: query, offset: offset, limit: limit) end
lock_file(file, expires_at: nil, is_download_prevented: false, if_match: nil)
click to toggle source
# File lib/boxr/files.rb, line 55 def lock_file(file, expires_at: nil, is_download_prevented: false, if_match: nil) lock = {type: "lock"} lock[:expires_at] = expires_at.to_datetime.rfc3339 unless expires_at.nil? lock[:is_download_prevented] = is_download_prevented unless is_download_prevented.nil? update_file(file, lock: lock, if_match: if_match) end
metadata(file, scope: :global, template: :properties)
click to toggle source
# File lib/boxr/metadata.rb, line 18 def metadata(file, scope: :global, template: :properties) file_id = ensure_id(file) uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}" metadata, response = get(uri) metadata end
metadata_schema(scope, template_key)
click to toggle source
# File lib/boxr/metadata.rb, line 89 def metadata_schema(scope, template_key) uri = "#{METADATA_TEMPLATES_URI}/#{scope}/#{template_key}/schema" schema, response = get(uri) schema end
Also aliased as: get_metadata_template_by_name
move_file(file, new_parent, name: nil, if_match: nil)
click to toggle source
# File lib/boxr/files.rb, line 72 def move_file(file, new_parent, name: nil, if_match: nil) update_file(file, parent: new_parent, name: name, if_match: if_match) end
move_folder(folder, new_parent, name: nil, if_match: nil)
click to toggle source
# File lib/boxr/folders.rb, line 81 def move_folder(folder, new_parent, name: nil, if_match: nil) update_folder(folder, parent: new_parent, name: name, if_match: if_match) end
move_users_folder(user, source_folder = 0, destination_user)
click to toggle source
As of writing, API only supports a root source folder (0)
# File lib/boxr/users.rb, line 112 def move_users_folder(user, source_folder = 0, destination_user) user_id = ensure_id(user) destination_user_id = ensure_id(destination_user) source_folder_id = ensure_id(source_folder) uri = "#{USERS_URI}/#{user_id}/folders/#{source_folder_id}" attributes = {owned_by: {id: destination_user_id}} folder, response = put(uri, attributes) folder end
pending_collaborations(fields: [])
click to toggle source
these are pending collaborations for the current user; use the As-User Header to request for different users
# File lib/boxr/collaborations.rb, line 73 def pending_collaborations(fields: []) query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY) query[:status] = :pending pending_collaborations, response = get(COLLABORATIONS_URI, query: query) pending_collaborations['entries'] end
promote_old_version_of_file(file, file_version)
click to toggle source
# File lib/boxr/files.rb, line 178 def promote_old_version_of_file(file, file_version) file_id = ensure_id(file) file_version_id = ensure_id(file_version) uri = "#{FILES_URI}/#{file_id}/versions/current" attributes = {:type => 'file_version', :id => file_version_id} new_version, res = post(uri, attributes) new_version end
remove_collaboration(collaboration)
click to toggle source
# File lib/boxr/collaborations.rb, line 54 def remove_collaboration(collaboration) collaboration_id = ensure_id(collaboration) uri = "#{COLLABORATIONS_URI}/#{collaboration_id}" result, response = delete(uri) result end
remove_email_alias_for_user(user, email_alias)
click to toggle source
# File lib/boxr/users.rb, line 140 def remove_email_alias_for_user(user, email_alias) user_id = ensure_id(user) email_alias_id = ensure_id(email_alias) uri = "#{USERS_URI}/#{user_id}/email_aliases/#{email_alias_id}" result, response = delete(uri) result end
remove_watermark_on_file(file)
click to toggle source
# File lib/boxr/watermarking.rb, line 25 def remove_watermark_on_file(file) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/watermark" result, response = delete(uri) result end
remove_watermark_on_folder(folder)
click to toggle source
# File lib/boxr/watermarking.rb, line 55 def remove_watermark_on_folder(folder) folder_id = ensure_id(folder) uri = "#{FOLDERS_URI}/#{folder_id}/watermark" result, response = delete(uri) result end
reply_to_comment(comment, message: nil, tagged_message: nil)
click to toggle source
# File lib/boxr/comments.rb, line 17 def reply_to_comment(comment, message: nil, tagged_message: nil) comment_id = ensure_id(comment) add_comment(:comment, comment_id, message, tagged_message) end
restore_trashed_file(file, name: nil, parent: nil)
click to toggle source
# File lib/boxr/files.rb, line 264 def restore_trashed_file(file, name: nil, parent: nil) file_id = ensure_id(file) parent_id = ensure_id(parent) uri = "#{FILES_URI}/#{file_id}" restore_trashed_item(uri, name, parent_id) end
restore_trashed_folder(folder, name: nil, parent: nil)
click to toggle source
# File lib/boxr/folders.rb, line 148 def restore_trashed_folder(folder, name: nil, parent: nil) folder_id = ensure_id(folder) parent_id = ensure_id(parent) uri = "#{FOLDERS_URI}/#{folder_id}" restore_trashed_item(uri, name, parent_id) end
restore_trashed_web_link(web_link, name: nil, parent: nil)
click to toggle source
# File lib/boxr/web_links.rb, line 71 def restore_trashed_web_link(web_link, name: nil, parent: nil) web_link_id = ensure_id(web_link) parent_id = ensure_id(parent) uri = "#{WEB_LINKS_URI}/#{web_link_id}" restore_trashed_item(uri, name, parent_id) end
root_folder_items(fields: [], offset: nil, limit: nil)
click to toggle source
# File lib/boxr/folders.rb, line 44 def root_folder_items(fields: [], offset: nil, limit: nil) folder_items(Boxr::ROOT, fields: fields, offset: offset, limit: limit) end
search( query=nil, scope: nil, file_extensions: [], created_at_range_from_date: nil, created_at_range_to_date: nil, updated_at_range_from_date: nil, updated_at_range_to_date: nil, size_range_lower_bound_bytes: nil, size_range_upper_bound_bytes: nil, owner_user_ids: [], ancestor_folder_ids: [], content_types: [], trash_content: nil, mdfilters: nil, type: nil, limit: 30, offset: 0)
click to toggle source
# File lib/boxr/search.rb, line 4 def search( query=nil, scope: nil, file_extensions: [], created_at_range_from_date: nil, created_at_range_to_date: nil, updated_at_range_from_date: nil, updated_at_range_to_date: nil, size_range_lower_bound_bytes: nil, size_range_upper_bound_bytes: nil, owner_user_ids: [], ancestor_folder_ids: [], content_types: [], trash_content: nil, mdfilters: nil, type: nil, limit: 30, offset: 0) unless mdfilters.nil? unless mdfilters.is_a? String #if a string is passed in assume it is already formatted correctly unless mdfilters.is_a? Array mdfilters = [mdfilters] #if just one mdfilter is specified ensure that it is packaged inside an array end mdfilters = JSON.dump(mdfilters) end end #build range strings created_at_range_string = build_date_range_field(created_at_range_from_date, created_at_range_to_date) updated_at_range_string = build_date_range_field(updated_at_range_from_date, updated_at_range_to_date) size_range_string = build_size_range_field(size_range_lower_bound_bytes, size_range_upper_bound_bytes) #build comma separated strings file_extensions_string = to_comma_separated_string(file_extensions) owner_user_ids_string = to_comma_separated_string(owner_user_ids) ancestor_folder_ids_string = to_comma_separated_string(ancestor_folder_ids) content_types_string = to_comma_separated_string(content_types) search_query = {} search_query[:query] = query unless query.nil? search_query[:scope] = scope unless scope.nil? search_query[:file_extensions] = file_extensions_string unless file_extensions_string.nil? search_query[:created_at_range] = created_at_range_string unless created_at_range_string.nil? search_query[:updated_at_range] = updated_at_range_string unless updated_at_range_string.nil? search_query[:size_range] = size_range_string unless size_range_string.nil? search_query[:owner_user_ids] = owner_user_ids_string unless owner_user_ids_string.nil? search_query[:ancestor_folder_ids] = ancestor_folder_ids_string unless ancestor_folder_ids_string.nil? search_query[:content_types] = content_types_string unless content_types_string.nil? search_query[:trash_content] = trash_content unless trash_content.nil? search_query[:mdfilters] = mdfilters unless mdfilters.nil? search_query[:type] = type unless type.nil? search_query[:limit] = limit unless limit.nil? search_query[:offset] = offset unless offset.nil? results, response = get(SEARCH_URI, query: search_query) results.entries end
task_assignment(task)
click to toggle source
# File lib/boxr/tasks.rb, line 71 def task_assignment(task) task_id = ensure_id(task) uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}" task_assignment, response = get(uri) task_assignment end
task_assignments(task)
click to toggle source
# File lib/boxr/tasks.rb, line 51 def task_assignments(task) task_id = ensure_id(task) uri = "#{TASKS_URI}/#{task_id}/assignments" assignments, response = get(uri) assignments['entries'] end
task_from_id(task_id)
click to toggle source
# File lib/boxr/tasks.rb, line 24 def task_from_id(task_id) task_id = ensure_id(task_id) uri = "#{TASKS_URI}/#{task_id}" task, response = get(uri) task end
Also aliased as: task
thumbnail(file, min_height: nil, min_width: nil, max_height: nil, max_width: nil)
click to toggle source
# File lib/boxr/files.rb, line 215 def thumbnail(file, min_height: nil, min_width: nil, max_height: nil, max_width: nil) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/thumbnail.png" query = {} query[:min_height] = min_height unless min_height.nil? query[:min_width] = min_width unless min_width.nil? query[:max_height] = max_height unless max_height.nil? query[:max_width] = max_width unless max_width.nil? body, response = get(uri, query: query, success_codes: [302,202,200], process_response: false) if(response.status==202 || response.status==302) location = response.header['Location'][0] thumbnail, response = get(location, process_response: false) else #200 thumbnail = body end thumbnail end
trash(fields: [], offset: nil, limit: nil)
click to toggle source
# File lib/boxr/folders.rb, line 118 def trash(fields: [], offset: nil, limit: nil) uri = "#{FOLDERS_URI}/trash/items" query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY) if offset.nil? || limit.nil? items = get_all_with_pagination(uri, query: query, offset: 0, limit: FOLDER_ITEMS_LIMIT) else query[:offset] = offset query[:limit] = limit items, response = get(uri, query: query) items['entries'] end end
trashed_file(file, fields: [])
click to toggle source
# File lib/boxr/files.rb, line 247 def trashed_file(file, fields: []) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/trash" query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY) trashed_file, response = get(uri, query: query) trashed_file end
trashed_folder(folder, fields: [])
click to toggle source
# File lib/boxr/folders.rb, line 132 def trashed_folder(folder, fields: []) folder_id = ensure_id(folder) uri = "#{FOLDERS_URI}/#{folder_id}/trash" query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY) folder, response = get(uri, query: query) folder end
trashed_web_link(web_link, fields: [])
click to toggle source
# File lib/boxr/web_links.rb, line 54 def trashed_web_link(web_link, fields: []) web_link_id = ensure_id(web_link) uri = "#{WEB_LINKS_URI}/#{web_link_id}/trash" query = build_fields_query(fields, WEB_LINK_FIELDS_QUERY) web_link, response = get(uri, query: query) web_link end
Also aliased as: get_trashed_web_link
unlock_file(file, if_match: nil)
click to toggle source
# File lib/boxr/files.rb, line 63 def unlock_file(file, if_match: nil) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}" attributes = {lock: nil} updated_file, response = put(uri, attributes, if_match: if_match) updated_file end
update_file(file, name: nil, description: nil, parent: nil, shared_link: nil, tags: nil, lock: nil, if_match: nil)
click to toggle source
# File lib/boxr/files.rb, line 38 def update_file(file, name: nil, description: nil, parent: nil, shared_link: nil, tags: nil, lock: nil, if_match: nil) file_id = ensure_id(file) parent_id = ensure_id(parent) uri = "#{FILES_URI}/#{file_id}" attributes = {} attributes[:name] = name unless name.nil? attributes[:description] = description unless description.nil? attributes[:parent] = {id: parent_id} unless parent_id.nil? attributes[:shared_link] = shared_link unless shared_link.nil? attributes[:tags] = tags unless tags.nil? attributes[:lock] = lock unless lock.nil? updated_file, response = put(uri, attributes, if_match: if_match) updated_file end
update_folder(folder, name: nil, description: nil, parent: nil, shared_link: nil, folder_upload_email_access: nil, owned_by: nil, sync_state: nil, tags: nil, can_non_owners_invite: nil, if_match: nil)
click to toggle source
# File lib/boxr/folders.rb, line 58 def update_folder(folder, name: nil, description: nil, parent: nil, shared_link: nil, folder_upload_email_access: nil, owned_by: nil, sync_state: nil, tags: nil, can_non_owners_invite: nil, if_match: nil) folder_id = ensure_id(folder) parent_id = ensure_id(parent) owned_by_id = ensure_id(owned_by) uri = "#{FOLDERS_URI}/#{folder_id}" attributes = {} attributes[:name] = name unless name.nil? attributes[:description] = description unless description.nil? attributes[:parent] = {id: parent_id} unless parent_id.nil? attributes[:shared_link] = shared_link unless shared_link.nil? attributes[:folder_upload_email] = {access: folder_upload_email_access} unless folder_upload_email_access.nil? attributes[:owned_by] = {id: owned_by_id} unless owned_by_id.nil? attributes[:sync_state] = sync_state unless sync_state.nil? attributes[:tags] = tags unless tags.nil? attributes[:can_non_owners_invite] = can_non_owners_invite unless can_non_owners_invite.nil? updated_folder, response = put(uri, attributes, if_match: if_match) updated_folder end
update_folder_metadata(folder, updates, scope, template)
click to toggle source
# File lib/boxr/metadata.rb, line 57 def update_folder_metadata(folder, updates, scope, template) folder_id = ensure_id(folder) uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}" #in the event just one update is specified ensure that it is packaged inside an array updates = [updates] unless updates.is_a? Array metadata, response = put(uri, updates, content_type: "application/json-patch+json") metadata end
update_group(group, name)
click to toggle source
# File lib/boxr/groups.rb, line 25 def update_group(group, name) group_id = ensure_id(group) uri = "#{GROUPS_URI}/#{group_id}" attributes = {name: name} updated_group, response = put(uri, attributes) updated_group end
Also aliased as: rename_group
update_group_membership(membership, role)
click to toggle source
# File lib/boxr/groups.rb, line 77 def update_group_membership(membership, role) membership_id = ensure_id(membership) uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}" attributes = {role: role} updated_membership, response = put(uri, attributes) updated_membership end
update_metadata(file, updates, scope: :global, template: :properties)
click to toggle source
# File lib/boxr/metadata.rb, line 46 def update_metadata(file, updates, scope: :global, template: :properties) file_id = ensure_id(file) uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}" #in the event just one update is specified ensure that it is packaged inside an array updates = [updates] unless updates.is_a? Array metadata, response = put(uri, updates, content_type: "application/json-patch+json") metadata end
update_task(task, action: :review, message: nil, due_at: nil)
click to toggle source
# File lib/boxr/tasks.rb, line 32 def update_task(task, action: :review, message: nil, due_at: nil) task_id = ensure_id(task) uri = "#{TASKS_URI}/#{task_id}" attributes = {} attributes[:action] = action unless action.nil? attributes[:message] = message unless message.nil? attributes[:due_at] = due_at.to_datetime.rfc3339 unless due_at.nil? task, response = put(uri, attributes) task end
update_task_assignment(task, message: nil, resolution_state: nil)
click to toggle source
# File lib/boxr/tasks.rb, line 85 def update_task_assignment(task, message: nil, resolution_state: nil) task_id = ensure_id(task) uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}" attributes = {} attributes[:message] = message unless message.nil? attributes[:resolution_state] = resolution_state unless resolution_state.nil? updated_task, response = put(uri, attributes) updated_task end
update_user(user, notify: nil, enterprise: true, name: nil, role: nil, language: nil, is_sync_enabled: nil, job_title: nil, phone: nil, address: nil, space_amount: nil, tracking_codes: nil, can_see_managed_users: nil, status: nil, timezone: nil, is_exempt_from_device_limits: nil, is_exempt_from_login_verification: nil, is_exempt_from_reset_required: nil, is_external_collab_restricted: nil)
click to toggle source
# File lib/boxr/users.rb, line 68 def update_user(user, notify: nil, enterprise: true, name: nil, role: nil, language: nil, is_sync_enabled: nil, job_title: nil, phone: nil, address: nil, space_amount: nil, tracking_codes: nil, can_see_managed_users: nil, status: nil, timezone: nil, is_exempt_from_device_limits: nil, is_exempt_from_login_verification: nil, is_exempt_from_reset_required: nil, is_external_collab_restricted: nil) user_id = ensure_id(user) uri = "#{USERS_URI}/#{user_id}" query = {notify: notify} unless notify.nil? attributes = {} attributes[:enterprise] = nil if enterprise.nil? #this is a special condition where setting this to nil means to roll this user out of the enterprise attributes[:name] = name unless name.nil? attributes[:role] = role unless role.nil? attributes[:language] = language unless language.nil? attributes[:is_sync_enabled] = is_sync_enabled unless is_sync_enabled.nil? attributes[:job_title] = job_title unless job_title.nil? attributes[:phone] = phone unless phone.nil? attributes[:address] = address unless address.nil? attributes[:space_amount] = space_amount unless space_amount.nil? attributes[:tracking_codes] = tracking_codes unless tracking_codes.nil? attributes[:can_see_managed_users] = can_see_managed_users unless can_see_managed_users.nil? attributes[:status] = status unless status.nil? attributes[:timezone] = timezone unless timezone.nil? attributes[:is_exempt_from_device_limits] = is_exempt_from_device_limits unless is_exempt_from_device_limits.nil? attributes[:is_exempt_from_login_verification] = is_exempt_from_login_verification unless is_exempt_from_login_verification.nil? attributes[:is_exempt_from_reset_required] = is_exempt_from_reset_required unless is_exempt_from_reset_required.nil? attributes[:is_external_collab_restricted] = is_external_collab_restricted unless is_external_collab_restricted.nil? updated_user, response = put(uri, attributes, query: query) updated_user end
update_web_link(web_link, url: nil, parent: nil, name: nil, description: nil)
click to toggle source
# File lib/boxr/web_links.rb, line 29 def update_web_link(web_link, url: nil, parent: nil, name: nil, description: nil) web_link_id = ensure_id(web_link) parent_id = ensure_id(parent) uri = "#{WEB_LINKS_URI}/#{web_link_id}" attributes = {} attributes[:url] = url unless url.nil? attributes[:name] = name unless name.nil? attributes[:description] = description unless description.nil? attributes[:parent] = {id: parent_id} unless parent_id.nil? updated_web_link, response = put(uri, attributes) updated_web_link end
update_webhook(webhook, attributes = {})
click to toggle source
# File lib/boxr/webhooks.rb, line 24 def update_webhook(webhook, attributes = {}) webhook_id = ensure_id(webhook) uri = "#{WEBHOOKS_URI}/#{webhook_id}" updated_webhook, response = put(uri, attributes) updated_webhook end
upload_file(path_to_file, parent, name: nil, content_created_at: nil, content_modified_at: nil, preflight_check: true, send_content_md5: true)
click to toggle source
# File lib/boxr/files.rb, line 105 def upload_file(path_to_file, parent, name: nil, content_created_at: nil, content_modified_at: nil, preflight_check: true, send_content_md5: true) filename = name ? name : File.basename(path_to_file) File.open(path_to_file) do |file| 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) end end
upload_file_from_io(io, parent, name:, content_created_at: nil, content_modified_at: nil, preflight_check: true, send_content_md5: true)
click to toggle source
# File lib/boxr/files.rb, line 114 def upload_file_from_io(io, parent, name:, content_created_at: nil, content_modified_at: nil, preflight_check: true, send_content_md5: true) parent_id = ensure_id(parent) preflight_check(io, name, parent_id) if preflight_check if send_content_md5 content_md5 = Digest::SHA1.hexdigest(io.read) io.rewind end attributes = {name: name, parent: {id: parent_id}} attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil? attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil? body = {attributes: JSON.dump(attributes), file: io} file_info, response = post(FILES_UPLOAD_URI, body, process_body: false, content_md5: content_md5) file_info.entries[0] end
upload_new_version_of_file(path_to_file, file, content_modified_at: nil, send_content_md5: true, preflight_check: true, if_match: nil, name: nil)
click to toggle source
# File lib/boxr/files.rb, line 135 def upload_new_version_of_file(path_to_file, file, content_modified_at: nil, send_content_md5: true, preflight_check: true, if_match: nil, name: nil) filename = name ? name : File.basename(path_to_file) File.open(path_to_file) do |io| upload_new_version_of_file_from_io(io, file, name: filename, content_modified_at: content_modified_at, preflight_check: preflight_check, send_content_md5: send_content_md5, if_match: if_match) end end
upload_new_version_of_file_from_io(io, file, name: nil, content_modified_at: nil, send_content_md5: true, preflight_check: true, if_match: nil)
click to toggle source
# File lib/boxr/files.rb, line 144 def upload_new_version_of_file_from_io(io, file, name: nil, content_modified_at: nil, send_content_md5: true, preflight_check: true, if_match: nil) filename = name ? name : file.name file_id = ensure_id(file) preflight_check_new_version_of_file(io, file_id) if preflight_check uri = "#{UPLOAD_URI}/files/#{file_id}/content" file_info = nil response = nil if send_content_md5 content_md5 = Digest::SHA1.hexdigest(io.read) io.rewind end attributes = {name: name} attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil? body = {attributes: JSON.dump(attributes), file: io} file_info, response = post(uri, body, process_body: false, content_md5: content_md5, if_match: if_match) file_info.entries[0] end
user_events(stream_position, stream_type: :all, limit: 800)
click to toggle source
# File lib/boxr/events.rb, line 4 def user_events(stream_position, stream_type: :all, limit: 800) query = {stream_position: stream_position, stream_type: stream_type, limit: limit} events, response = get(EVENTS_URI, query: query) BoxrMash.new({events: events.entries, chunk_size: events.chunk_size, next_stream_position: events.next_stream_position}) end
user_from_id(user_id, fields: [])
click to toggle source
# File lib/boxr/users.rb, line 13 def user_from_id(user_id, fields: []) user_id = ensure_id(user_id) uri = "#{USERS_URI}/#{user_id}" query = build_fields_query(fields, USER_FIELDS_QUERY) user, response = get(uri, query: query) user end
Also aliased as: user
versions_of_file(file)
click to toggle source
# File lib/boxr/files.rb, line 171 def versions_of_file(file) file_id = ensure_id(file) uri = "#{FILES_URI}/#{file_id}/versions" versions, response = get(uri) versions.entries end
Private Instance Methods
add_comment(type, id, message, tagged_message)
click to toggle source
# File lib/boxr/comments.rb, line 48 def add_comment(type, id, message, tagged_message) uri = COMMENTS_URI attributes = {item: {type: type, id: id}} attributes[:message] = message unless message.nil? attributes[:tagged_message] = tagged_message unless tagged_message.nil? new_comment, response = post(uri, attributes) new_comment end
build_date_range_field(from, to)
click to toggle source
# File lib/boxr/search.rb, line 54 def build_date_range_field(from, to) from_string = from.nil? ? "" : from.to_datetime.rfc3339 to_string = to.nil? ? "" : to.to_datetime.rfc3339 build_range_string(from_string, to_string) end
build_fields_query(fields, all_fields_query)
click to toggle source
# File lib/boxr/client.rb, line 259 def build_fields_query(fields, all_fields_query) if fields == :all {:fields => all_fields_query} elsif fields.is_a?(Array) && fields.length > 0 {:fields => fields.join(',')} else {} end end
build_range_string(from, to)
click to toggle source
# File lib/boxr/client.rb, line 279 def build_range_string(from, to) range_string = "#{from},#{to}" range_string = nil if range_string == "," range_string end
build_size_range_field(lower, upper)
click to toggle source
# File lib/boxr/search.rb, line 60 def build_size_range_field(lower, upper) lower_string = lower.nil? ? "" : lower.to_i upper_string = upper.nil? ? "" : upper.to_i build_range_string(lower_string, upper_string) end
check_response_status(res, success_codes)
click to toggle source
# File lib/boxr/client.rb, line 250 def check_response_status(res, success_codes) raise BoxrError.new(status: res.status, body: res.body, header: res.header) unless success_codes.include?(res.status) end
chunked_upload_to_session_from_io(io, session, n_threads: 1, content_created_at: nil, content_modified_at: nil)
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 158 def chunked_upload_to_session_from_io(io, session, n_threads: 1, content_created_at: nil, content_modified_at: nil) content_ranges = [] offset = 0 loop do limit = [offset + session.part_size, io.size].min - 1 content_ranges << (offset..limit) break if limit == io.size - 1 offset = limit + 1 end parts = if n_threads > 1 raise BoxrError.new(boxr_message: "parallel chunked uploads requires gem parallel (#{PARALLEL_GEM_REQUIREMENT}) to be loaded") unless gem_parallel_available? Parallel.map(content_ranges, in_threads: n_threads) do |content_range| File.open(io.path) do |io_dup| chunked_upload_part_from_io(io_dup, session.id, content_range) end end else content_ranges.map do |content_range| chunked_upload_part_from_io(io, session.id, content_range) end end commit_info = chunked_upload_commit_from_io(io, session.id, parts, content_created_at: content_created_at, content_modified_at: content_modified_at) commit_info.entries[0] end
delete(uri, query: nil, success_codes: [204], if_match: nil)
click to toggle source
# File lib/boxr/client.rb, line 185 def delete(uri, query: nil, success_codes: [204], if_match: nil) uri = Addressable::URI.encode(uri) res = with_auto_token_refresh do headers = standard_headers headers['If-Match'] = if_match unless if_match.nil? BOX_CLIENT.delete(uri, query: query, header: headers) end check_response_status(res, success_codes) processed_response(res) end
ensure_id(item)
click to toggle source
# File lib/boxr/client.rb, line 285 def ensure_id(item) # Ruby 2.4 unified Fixnum and Bignum into Integer. This tests for Ruby 2.4 if 1.class == Integer return item if item.class == String || item.class == Integer || item.nil? else return item if item.class == String || item.class == Fixnum || item.class == Bignum || item.nil? end return item.id if item.respond_to?(:id) raise BoxrError.new(boxr_message: "Expecting an id of class String or Fixnum, or object that responds to :id") end
gem_parallel_available?()
click to toggle source
# File lib/boxr/chunked_uploads.rb, line 189 def gem_parallel_available? gem_spec = Gem.loaded_specs['parallel'] return false if gem_spec.nil? PARALLEL_GEM_REQUIREMENT.satisfied_by?(gem_spec.version) && defined?(Parallel) end
get(uri, query: nil, success_codes: [200], process_response: true, if_match: nil, box_api_header: nil, follow_redirect: true)
click to toggle source
# File lib/boxr/client.rb, line 100 def get(uri, query: nil, success_codes: [200], process_response: true, if_match: nil, box_api_header: nil, follow_redirect: true) uri = Addressable::URI.encode(uri) res = with_auto_token_refresh do headers = standard_headers headers['If-Match'] = if_match unless if_match.nil? headers['BoxApi'] = box_api_header unless box_api_header.nil? BOX_CLIENT.get(uri, query: query, header: headers, follow_redirect: follow_redirect) end check_response_status(res, success_codes) if process_response return processed_response(res) else return res.body, res end end
get_all_with_pagination(uri, query: {}, offset: 0, limit: DEFAULT_LIMIT, follow_redirect: true)
click to toggle source
# File lib/boxr/client.rb, line 120 def get_all_with_pagination(uri, query: {}, offset: 0, limit: DEFAULT_LIMIT, follow_redirect: true) uri = Addressable::URI.encode(uri) entries = [] begin query[:limit] = limit query[:offset] = offset res = with_auto_token_refresh do headers = standard_headers BOX_CLIENT.get(uri, query: query, header: headers, follow_redirect: follow_redirect) end if (res.status==200) body_json = JSON.load(res.body) total_count = body_json["total_count"] offset = offset + limit entries << body_json["entries"] else raise BoxrError.new(status: res.status, body: res.body, header: res.header) end end until offset - total_count >= 0 BoxrCollection.new(entries.flatten.map{ |i| BoxrMash.new(i) }) end
get_enterprise_events(created_after, created_before, stream_position, event_type, limit)
click to toggle source
# File lib/boxr/events.rb, line 38 def get_enterprise_events(created_after, created_before, stream_position, event_type, limit) query = {stream_position: stream_position, stream_type: :admin_logs, limit: limit} query['event_type'] = event_type unless event_type.nil? query['created_after'] = created_after.to_datetime.rfc3339 unless created_after.nil? query['created_before'] = created_before.to_datetime.rfc3339 unless created_before.nil? events, response = get(EVENTS_URI, query: query) BoxrMash.new({events: events.entries, chunk_size: events.chunk_size, next_stream_position: events.next_stream_position}) end
options(uri, body, success_codes: [200])
click to toggle source
# File lib/boxr/client.rb, line 200 def options(uri, body, success_codes: [200]) uri = Addressable::URI.encode(uri) res = with_auto_token_refresh do headers = standard_headers BOX_CLIENT.options(uri, body: JSON.dump(body), header: headers) end check_response_status(res, success_codes) processed_response(res) end
post(uri, body, query: nil, success_codes: [201], process_body: true, digest: nil, content_md5: nil, content_type: nil, if_match: nil, if_non_match: nil)
click to toggle source
# File lib/boxr/client.rb, line 146 def post(uri, body, query: nil, success_codes: [201], process_body: true, digest: nil, content_md5: nil, content_type: nil, if_match: nil, if_non_match: nil) uri = Addressable::URI.encode(uri) body = JSON.dump(body) if process_body res = with_auto_token_refresh do headers = standard_headers headers['If-Match'] = if_match unless if_match.nil? headers['If-Non-Match'] = if_non_match unless if_non_match.nil? headers["Content-MD5"] = content_md5 unless content_md5.nil? headers["Content-Type"] = content_type unless content_type.nil? headers["Digest"] = digest unless digest.nil? BOX_CLIENT.post(uri, body: body, query: query, header: headers) end check_response_status(res, success_codes) processed_response(res) end
preflight_check(io, filename, parent_id)
click to toggle source
# File lib/boxr/files.rb, line 274 def preflight_check(io, filename, parent_id) size = io.size #TODO: need to make sure that figuring out the filename from the path_to_file works for people using Windows attributes = {name: filename, parent: {id: "#{parent_id}"}, size: size} body_json, res = options("#{FILES_URI}/content", attributes) end
preflight_check_new_version_of_file(io, file_id)
click to toggle source
# File lib/boxr/files.rb, line 282 def preflight_check_new_version_of_file(io, file_id) size = io.size attributes = {size: size} body_json, res = options("#{FILES_URI}/#{file_id}/content", attributes) end
processed_response(res)
click to toggle source
# File lib/boxr/client.rb, line 254 def processed_response(res) body_json = JSON.load(res.body) return BoxrMash.new(body_json), res end
put(uri, body, query: nil, success_codes: [200, 201], process_body: true, content_type: nil, content_range: nil, digest: nil, if_match: nil)
click to toggle source
# File lib/boxr/client.rb, line 166 def put(uri, body, query: nil, success_codes: [200, 201], process_body: true, content_type: nil, content_range: nil, digest: nil, if_match: nil) uri = Addressable::URI.encode(uri) body = JSON.dump(body) if process_body res = with_auto_token_refresh do headers = standard_headers headers['If-Match'] = if_match unless if_match.nil? headers["Content-Type"] = content_type unless content_type.nil? headers["Content-Range"] = content_range unless content_range.nil? headers["Digest"] = digest unless digest.nil? BOX_CLIENT.put(uri, body: body, query: query, header: headers) end check_response_status(res, success_codes) processed_response(res) end
restore_trashed_item(uri, name, parent)
click to toggle source
# File lib/boxr/client.rb, line 297 def restore_trashed_item(uri, name, parent) parent_id = ensure_id(parent) attributes = {} attributes[:name] = name unless name.nil? attributes[:parent] = {id: parent_id} unless parent_id.nil? restored_item, response = post(uri, attributes) restored_item end
standard_headers()
click to toggle source
# File lib/boxr/client.rb, line 213 def standard_headers() headers = {"Authorization" => "Bearer #{@access_token}"} if @jwt_private_key.nil? headers['As-User'] = "#{@as_user_id}" unless @as_user_id.nil? end headers end
to_comma_separated_string(values)
click to toggle source
# File lib/boxr/client.rb, line 269 def to_comma_separated_string(values) return values if values.is_a?(String) || values.is_a?(Symbol) if values.is_a?(Array) && values.length > 0 values.join(',') else nil end end
validate_role(role)
click to toggle source
# File lib/boxr/collaborations.rb, line 82 def validate_role(role) case role when :previewer_uploader role = 'previewer uploader' when :viewer_uploader role = 'viewer uploader' when :co_owner role = 'co-owner' end role = role.to_s raise BoxrError.new(boxr_message: "Invalid collaboration role: '#{role}'") unless VALID_COLLABORATION_ROLES.include?(role) role end
verify_url(item)
click to toggle source
# File lib/boxr/web_links.rb, line 81 def verify_url(item) return item if item.class == String and (item.include? 'https://' or item.include? 'http://') raise BoxrError.new(boxr_message: "Invalid url. Must include 'http://' or 'https://'") end
with_auto_token_refresh() { || ... }
click to toggle source
# File lib/boxr/client.rb, line 221 def with_auto_token_refresh return yield unless @refresh_token or @jwt_private_key res = yield if res.status == 401 auth_header = res.header['WWW-Authenticate'][0] if auth_header && auth_header.include?('invalid_token') if @refresh_token new_tokens = Boxr::refresh_tokens(@refresh_token, client_id: client_id, client_secret: client_secret) @access_token = new_tokens.access_token @refresh_token = new_tokens.refresh_token @token_refresh_listener.call(@access_token, @refresh_token, @identifier) if @token_refresh_listener else if @as_user_id new_token = Boxr::get_user_token(@as_user_id, private_key: @jwt_private_key, private_key_password: @jwt_private_key_password, public_key_id: @jwt_public_key_id, client_id: @client_id, client_secret: @client_secret) @access_token = new_token.access_token else new_token = Boxr::get_enterprise_token(private_key: @jwt_private_key, private_key_password: @jwt_private_key_password, public_key_id: @jwt_public_key_id, enterprise_id: @enterprise_id, client_id: @client_id, client_secret: @client_secret) @access_token = new_token.access_token end end res = yield end end res end