Class: Boxr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/boxr/client.rb,
lib/boxr/files.rb,
lib/boxr/tasks.rb,
lib/boxr/users.rb,
lib/boxr/events.rb,
lib/boxr/groups.rb,
lib/boxr/search.rb,
lib/boxr/avatars.rb,
lib/boxr/folders.rb,
lib/boxr/comments.rb,
lib/boxr/metadata.rb,
lib/boxr/webhooks.rb,
lib/boxr/web_links.rb,
lib/boxr/collections.rb,
lib/boxr/shared_items.rb,
lib/boxr/watermarking.rb,
lib/boxr/zip_downloads.rb,
lib/boxr/collaborations.rb,
lib/boxr/chunked_uploads.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

API_URI =
'https://api.box.com/2.0'
AUTH_URI =
'https://api.box.com/oauth2/token'
REVOKE_AUTH_URI =
'https://api.box.com/oauth2/revoke'
UPLOAD_URI =
'https://upload.box.com/api/2.0'
ARCHIVES_URI =
"#{API_URI}/archives"
COLLABORATIONS_URI =
"#{API_URI}/collaborations"
COLLECTIONS_URI =
"#{API_URI}/collections"
COMMENTS_URI =
"#{API_URI}/comments"
EVENTS_URI =
"#{API_URI}/events"
FILE_METADATA_URI =
"#{API_URI}/files"
FILES_UPLOAD_URI =
"#{UPLOAD_URI}/files/content"
FILES_URI =
"#{API_URI}/files"
FOLDER_METADATA_URI =
"#{API_URI}/folders"
FOLDERS_URI =
"#{API_URI}/folders"
GROUP_MEMBERSHIPS_URI =
"#{API_URI}/group_memberships"
GROUPS_URI =
"#{API_URI}/groups"
METADATA_TEMPLATES_URI =
"#{API_URI}/metadata_templates"
SEARCH_URI =
"#{API_URI}/search"
SHARED_ITEMS_URI =
"#{API_URI}/shared_items"
TASK_ASSIGNMENTS_URI =
"#{API_URI}/task_assignments"
TASKS_URI =
"#{API_URI}/tasks"
USERS_URI =
"#{API_URI}/users"
"#{API_URI}/web_links"
WEBHOOKS_URI =
"#{API_URI}/webhooks"
ZIP_DOWNLOADS_URI =
"#{API_URI}/zip_downloads"
BOX_VERSION_HEADER_2025 =
{ 'box-version' => '2025.0' }.freeze
DEFAULT_LIMIT =
100
FOLDER_ITEMS_LIMIT =
1000
FOLDER_AND_FILE_FIELDS =
%i[type id sequence_id etag name created_at modified_at description
size path_collection created_by modified_by trashed_at purged_at
content_created_at content_modified_at owned_by shared_link folder_upload_email
parent item_status item_collection sync_state has_collaborations permissions tags
sha1 shared_link version_number comment_count lock extension is_package can_non_owners_invite].freeze
FOLDER_AND_FILE_FIELDS_QUERY =
FOLDER_AND_FILE_FIELDS.join(',')
COMMENT_FIELDS =
%i[type id is_reply_comment message tagged_message created_by created_at
item modified_at].freeze
COMMENT_FIELDS_QUERY =
COMMENT_FIELDS.join(',')
TASK_FIELDS =
%i[type id item due_at action message task_assignment_collection
is_completed created_by created_at].freeze
TASK_FIELDS_QUERY =
TASK_FIELDS.join(',')
COLLABORATION_FIELDS =
%i[type id created_by created_at modified_at expires_at status
accessible_by role acknowledged_at item].freeze
COLLABORATION_FIELDS_QUERY =
COLLABORATION_FIELDS.join(',')
USER_FIELDS =
%i[type id name login created_at modified_at role language timezone space_amount space_used
max_upload_size tracking_codes can_see_managed_users is_sync_enabled is_external_collab_restricted
status job_title phone address avatar_uri is_exempt_from_device_limits is_exempt_from_login_verification
enterprise my_tags].freeze
USER_FIELDS_QUERY =
USER_FIELDS.join(',')
GROUP_FIELDS =
%i[type id name created_at modified_at].freeze
GROUP_FIELDS_QUERY =
GROUP_FIELDS.join(',')
%i[type id created_at created_by description etag item_status modified_at modified_by
name owned_by parent path_collection purged_at sequence_id shared_link trashed_at url].freeze
WEB_LINK_FIELDS.join(',')
VALID_COLLABORATION_ROLES =
['editor', 'viewer', 'previewer', 'uploader', 'previewer uploader',
'viewer uploader', 'co-owner', 'owner'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token = , refresh_token: nil, client_id: , client_secret: , enterprise_id: , jwt_private_key: , jwt_private_key_password: , jwt_public_key_id: , identifier: nil, as_user: nil, proxy: nil, &token_refresh_listener) ⇒ Client

Returns a new instance of Client.

Raises:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/boxr/client.rb', line 74

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,
               proxy: 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
  BOX_CLIENT.proxy = proxy unless proxy.nil?
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



5
6
7
# File 'lib/boxr/client.rb', line 5

def access_token
  @access_token
end

#as_user_idObject (readonly)

Returns the value of attribute as_user_id.



5
6
7
# File 'lib/boxr/client.rb', line 5

def as_user_id
  @as_user_id
end

#client_idObject (readonly)

Returns the value of attribute client_id.



5
6
7
# File 'lib/boxr/client.rb', line 5

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



5
6
7
# File 'lib/boxr/client.rb', line 5

def client_secret
  @client_secret
end

#identifierObject (readonly)

Returns the value of attribute identifier.



5
6
7
# File 'lib/boxr/client.rb', line 5

def identifier
  @identifier
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



5
6
7
# File 'lib/boxr/client.rb', line 5

def refresh_token
  @refresh_token
end

Instance Method Details

#add_collaboration(item, accessible_by, role, fields: [], notify: nil, type: :folder) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/boxr/collaborations.rb', line 34

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, = post(COLLABORATIONS_URI, attributes, query: query)
  collaboration
end

#add_comment_to_file(file, message: nil, tagged_message: nil) ⇒ Object



13
14
15
16
# File 'lib/boxr/comments.rb', line 13

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) ⇒ Object



157
158
159
160
161
162
163
164
# File 'lib/boxr/users.rb', line 157

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, = post(uri, attributes)
  updated_user
end

#add_user_to_group(user, group, role: nil) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/boxr/groups.rb', line 68

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, = post(GROUP_MEMBERSHIPS_URI, attributes)
  membership
end

#all_folder_metadata(folder) ⇒ Object



33
34
35
36
37
38
# File 'lib/boxr/metadata.rb', line 33

def (folder)
  folder_id = ensure_id(folder)
  uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata"
  , = get(uri)
  
end

#all_metadata(file) ⇒ Object



40
41
42
43
44
45
# File 'lib/boxr/metadata.rb', line 40

def (file)
  file_id = ensure_id(file)
  uri = "#{FILE_METADATA_URI}/#{file_id}/metadata"
  , = get(uri)
  
end

#all_users(filter_term: nil, fields: [], offset: nil, limit: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/boxr/users.rb', line 24

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?
    get_all_with_pagination(uri, query: query, offset: 0, limit: DEFAULT_LIMIT)
  else
    query[:offset] = offset
    query[:limit] = limit

    users, = get(uri, query: query)
    users['entries']
  end
end

#apply_watermark_on_file(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# 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, = put(uri, attributes, content_type: 'application/json')
  file
end

#apply_watermark_on_folder(folder) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/boxr/watermarking.rb', line 40

def apply_watermark_on_folder(folder)
  folder_id = ensure_id(folder)
  uri = "#{FOLDERS_URI}/#{folder_id}/watermark"

  attributes = {}
  attributes[:watermark] = { imprint: 'default' }

  folder, = put(uri, attributes, content_type: 'application/json')
  folder
end

#change_comment(comment, message) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/boxr/comments.rb', line 23

def change_comment(comment, message)
  comment_id = ensure_id(comment)
  uri = "#{COMMENTS_URI}/#{comment_id}"
  attributes = { message: message }
  updated_comment, = put(uri, attributes)
  updated_comment
end

#chunked_upload_abort_session(session_id) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/boxr/chunked_uploads.rb', line 115

def chunked_upload_abort_session(session_id)
  uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}"
  abort_info, = delete(uri)
  abort_info
rescue BoxrError # Ignore errors from aborting session
  nil
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) ⇒ Object

rubocop:disable Metrics



78
79
80
81
82
83
84
85
86
87
# File 'lib/boxr/chunked_uploads.rb', line 78

def chunked_upload_commit(path_to_file, session_id, parts, content_created_at: nil, # rubocop:disable Metrics
                          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) ⇒ Object

rubocop:disable Metrics



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/boxr/chunked_uploads.rb', line 89

def chunked_upload_commit_from_io(io, session_id, parts, content_created_at: nil, # rubocop:disable Metrics
                                  content_modified_at: nil, if_match: nil, if_non_match: nil)
  io.pos = 0
  cca = content_created_at
  cma = content_modified_at
  digest = "sha=#{calculate_chunked_upload_digest(io).base64digest}"

  attributes = {}
  attributes[:content_created_at] = cca.to_datetime.rfc3339 if cca
  attributes[:content_modified_at] = cma.to_datetime.rfc3339 if cma

  uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}/commit"
  body = { parts: parts, attributes: attributes }

  loop do
    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]
    )
    return commit_info if response.status != 202

    sleep response.header['Retry-After'][0].to_i
  end
end

#chunked_upload_create_session_new_file(path_to_file, parent, name: nil) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/boxr/chunked_uploads.rb', line 5

def chunked_upload_create_session_new_file(path_to_file, parent, name: nil)
  filename = 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) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/boxr/chunked_uploads.rb', line 13

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, = 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) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/boxr/chunked_uploads.rb', line 23

def chunked_upload_create_session_new_version(path_to_file, file, name: nil)
  filename = 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) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/boxr/chunked_uploads.rb', line 31

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, = 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) ⇒ Object

rubocop:disable Metrics



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/boxr/chunked_uploads.rb', line 123

def chunked_upload_file(path_to_file, parent, name: nil, n_threads: 1, # rubocop:disable Metrics
                        content_created_at: nil, content_modified_at: nil)
  filename = 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) ⇒ Object

rubocop:disable Metrics



136
137
138
139
140
141
142
143
144
# File 'lib/boxr/chunked_uploads.rb', line 136

def chunked_upload_file_from_io(io, parent, name, n_threads: 1, # rubocop:disable Metrics
                                content_created_at: nil, content_modified_at: nil)
  session = chunked_upload_create_session_new_file_from_io(io, parent, name)
  chunked_upload_to_session_from_io(
    io, session,
    n_threads: n_threads, content_created_at: content_created_at,
    content_modified_at: content_modified_at
  )
end

#chunked_upload_get_session(session_id) ⇒ Object



40
41
42
43
44
# File 'lib/boxr/chunked_uploads.rb', line 40

def chunked_upload_get_session(session_id)
  uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}"
  session_info, = get(uri)
  session_info
end

#chunked_upload_list_parts(session_id, limit: nil, offset: nil) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/boxr/chunked_uploads.rb', line 69

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, = 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) ⇒ Object

rubocop:disable Metrics



146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/boxr/chunked_uploads.rb', line 146

def chunked_upload_new_version_of_file(path_to_file, file, name: nil, n_threads: 1, # rubocop:disable Metrics
                                       content_created_at: nil, content_modified_at: nil)
  filename = 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) ⇒ Object

rubocop:disable Metrics



159
160
161
162
163
164
165
166
167
168
# File 'lib/boxr/chunked_uploads.rb', line 159

def chunked_upload_new_version_of_file_from_io( # rubocop:disable Metrics
  io, file, name, n_threads: 1, content_created_at: nil, content_modified_at: nil
)
  session = chunked_upload_create_session_new_version_from_io(io, file, name)
  chunked_upload_to_session_from_io(
    io, session,
    n_threads: n_threads, content_created_at: content_created_at,
    content_modified_at: content_modified_at
  )
end

#chunked_upload_part(path_to_file, session_id, content_range) ⇒ Object



46
47
48
49
50
# 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) ⇒ Object

rubocop:disable Metrics



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/boxr/chunked_uploads.rb', line 52

def chunked_upload_part_from_io(io, session_id, content_range) # rubocop:disable Metrics
  io.pos = content_range.min
  part_size = content_range.max - content_range.min + 1
  body = io.read(part_size)
  io.rewind

  digest = "sha=#{Digest::SHA1.base64digest(body)}"
  range = "bytes #{content_range.min}-#{content_range.max}/#{io.size}"

  uri = "#{UPLOAD_URI}/files/upload_sessions/#{session_id}"
  part_info, = 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) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/boxr/collaborations.rb', line 65

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, = get(uri, query: query)
  collaboration
end

#collection_from_id(collection_id) ⇒ Object Also known as: collection



5
6
7
8
9
10
11
# File 'lib/boxr/collections.rb', line 5

def collection_from_id(collection_id)
  collection_id = ensure_id(collection_id)
  uri = "#{COLLECTIONS_URI}/#{collection_id}"

  collection, = get(uri)
  collection
end

#collection_items(collection, fields: []) ⇒ Object



18
19
20
21
22
23
# File 'lib/boxr/collections.rb', line 18

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)
  get_all_with_pagination(uri, query: query, offset: 0, limit: DEFAULT_LIMIT)
end

#collectionsObject



14
15
16
# File 'lib/boxr/collections.rb', line 14

def collections
  get_all_with_pagination(COLLECTIONS_URI, offset: 0, limit: DEFAULT_LIMIT)
end

#comment_from_id(comment_id, fields: []) ⇒ Object Also known as: comment



31
32
33
34
35
36
37
# File 'lib/boxr/comments.rb', line 31

def comment_from_id(comment_id, fields: [])
  comment_id = ensure_id(comment_id)
  uri = "#{COMMENTS_URI}/#{comment_id}"
  query = build_fields_query(fields, COMMENT_FIELDS_QUERY)
  comment, _response = get(uri, query: query)
  comment
end

#copy_file(file, parent, name: nil, version: nil) ⇒ Object



226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/boxr/files.rb', line 226

def copy_file(file, parent, name: nil, version: nil)
  file_id = ensure_id(file)
  parent_id = ensure_id(parent)
  version_id = ensure_id(version) unless version.nil?

  uri = "#{FILES_URI}/#{file_id}/copy"
  attributes = { parent: { id: parent_id } }
  attributes[:name] = name unless name.nil?
  attributes[:version] = version_id unless version_id.nil?
  new_file, = post(uri, attributes)
  new_file
end

#copy_folder(folder, dest_folder, name: nil) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/boxr/folders.rb', line 97

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, = post(uri, attributes)
  new_folder
end

#create_folder(name, parent) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/boxr/folders.rb', line 48

def create_folder(name, parent)
  parent_id = ensure_id(parent)

  uri = FOLDERS_URI.to_s
  attributes = { name: name, parent: { id: parent_id } }

  created_folder, = post(uri, attributes)
  created_folder
end

#create_folder_metadata(folder, metadata, scope, template) ⇒ Object



12
13
14
15
16
17
# File 'lib/boxr/metadata.rb', line 12

def (folder, , scope, template)
  folder_id = ensure_id(folder)
  uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}"
  , = post(uri, , content_type: 'application/json')
  
end

#create_group(name) ⇒ Object



20
21
22
23
24
# File 'lib/boxr/groups.rb', line 20

def create_group(name)
  attributes = { name: name }
  new_group, = post(GROUPS_URI, attributes)
  new_group
end

#create_metadata(file, metadata, scope: :global, template: :properties) ⇒ Object



5
6
7
8
9
10
# File 'lib/boxr/metadata.rb', line 5

def (file, , scope: :global, template: :properties)
  file_id = ensure_id(file)
  uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}"
  , = post(uri, , content_type: 'application/json')
  
end

#create_metadata_template(display_name, template_key: nil, fields: [], hidden: nil) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/boxr/metadata.rb', line 104

def (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?

  , = post(uri, schema, content_type: 'application/json')
  
end

rubocop:disable Metrics



260
261
262
263
264
265
# File 'lib/boxr/files.rb', line 260

def create_shared_link_for_file(file, access: nil, unshared_at: nil, # rubocop:disable Metrics
                                can_download: nil, can_preview: nil, password: nil)
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}"
  create_shared_link(uri, file_id, access, unshared_at, can_download, can_preview, password)
end


109
110
111
112
113
114
# File 'lib/boxr/folders.rb', line 109

def create_shared_link_for_folder(folder, access: nil, unshared_at: nil, can_download: nil,
                                  can_preview: nil, password: nil)
  folder_id = ensure_id(folder)
  uri = "#{FOLDERS_URI}/#{folder_id}"
  create_shared_link(uri, folder_id, access, unshared_at, can_download, can_preview, password)
end

#create_task(file, action: :review, message: nil, due_at: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/boxr/tasks.rb', line 14

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, = post(TASKS_URI, attributes)
  new_task
end

#create_task_assignment(task, assign_to: nil, assign_to_login: nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/boxr/tasks.rb', line 59

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.to_s } }

  attributes[:assign_to] = {}
  attributes[:assign_to][:login] =  unless .nil?
  attributes[:assign_to][:id] = assign_to_id unless assign_to_id.nil?

  new_task_assignment, = 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) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/boxr/users.rb', line 40

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 }
  # login is not required for platform users, so needed to make this optional
  attributes[:login] =  unless .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?
  unless is_external_collab_restricted.nil?
    attributes[:is_external_collab_restricted] =
      is_external_collab_restricted
  end
  attributes[:status] = status unless status.nil?
  attributes[:timezone] = timezone unless timezone.nil?
  unless is_exempt_from_device_limits.nil?
    attributes[:is_exempt_from_device_limits] =
      is_exempt_from_device_limits
  end
  unless .nil?
    attributes[:is_exempt_from_login_verification] =
      
  end
  unless is_platform_access_only.nil?
    attributes[:is_platform_access_only] =
      is_platform_access_only
  end

  new_user, = post(uri, attributes)
  new_user
end

#create_user_avatar(user_id, pic, pic_file_name: nil, pic_content_type: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/boxr/avatars.rb', line 13

def create_user_avatar(user_id, pic, pic_file_name: nil, pic_content_type: nil)
  user_id = ensure_id(user_id)
  uri = "#{USERS_URI}/#{user_id}/avatar"

  body = { pic: pic }
  body[:pic_file_name] = pic_file_name unless pic_file_name.nil?
  body[:pic_content_type] = pic_content_type unless pic_content_type.nil?

  avatar, = post(uri, body, process_body: false, content_type: 'multipart/form-data')
  avatar
end


5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/boxr/web_links.rb', line 5

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.to_s

  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, = post(uri, attributes)
  created_link
end

#create_webhook(target_id, target_type, triggers, address) ⇒ Object



5
6
7
8
9
10
# 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, = post(WEBHOOKS_URI, attributes)
  new_webhook
end

#create_zip_download(targets, download_file_name: nil) ⇒ Object



5
6
7
8
9
10
11
12
# 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: []) ⇒ Object Also known as: me



5
6
7
8
9
10
11
# File 'lib/boxr/users.rb', line 5

def current_user(fields: [])
  uri = "#{USERS_URI}/me"
  query = build_fields_query(fields, USER_FIELDS_QUERY)

  user, = get(uri, query: query)
  user
end

#delete_comment(comment) ⇒ Object



40
41
42
43
44
45
# File 'lib/boxr/comments.rb', line 40

def delete_comment(comment)
  comment_id = ensure_id(comment)
  uri = "#{COMMENTS_URI}/#{comment_id}"
  result, = delete(uri)
  result
end

#delete_file(file, if_match: nil) ⇒ Object



210
211
212
213
214
215
# File 'lib/boxr/files.rb', line 210

def delete_file(file, if_match: nil)
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}"
  result, = delete(uri, if_match: if_match)
  result
end

#delete_folder(folder, recursive: false, if_match: nil) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/boxr/folders.rb', line 88

def delete_folder(folder, recursive: false, if_match: nil)
  folder_id = ensure_id(folder)
  uri = "#{FOLDERS_URI}/#{folder_id}"
  query = { recursive: recursive }

  result, = delete(uri, query: query, if_match: if_match)
  result
end

#delete_folder_metadata(folder, scope, template) ⇒ Object



76
77
78
79
80
81
# File 'lib/boxr/metadata.rb', line 76

def (folder, scope, template)
  folder_id = ensure_id(folder)
  uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}"
  result, = delete(uri)
  result
end

#delete_group(group) ⇒ Object



36
37
38
39
40
41
# File 'lib/boxr/groups.rb', line 36

def delete_group(group)
  group_id = ensure_id(group)
  uri = "#{GROUPS_URI}/#{group_id}"
  result, = delete(uri)
  result
end

#delete_group_membership(membership) ⇒ Object



86
87
88
89
90
91
# File 'lib/boxr/groups.rb', line 86

def delete_group_membership(membership)
  membership_id = ensure_id(membership)
  uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
  result, = delete(uri)
  result
end

#delete_metadata(file, scope: :global, template: :properties) ⇒ Object



69
70
71
72
73
74
# File 'lib/boxr/metadata.rb', line 69

def (file, scope: :global, template: :properties)
  file_id = ensure_id(file)
  uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}"
  result, = delete(uri)
  result
end

#delete_metadata_template(scope, template_key) ⇒ Object



118
119
120
121
122
# File 'lib/boxr/metadata.rb', line 118

def (scope, template_key)
  uri = "#{METADATA_TEMPLATES_URI}/#{scope}/#{template_key}/schema"
  result, = delete(uri)
  result
end

#delete_old_version_of_file(file, file_version, if_match: nil) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/boxr/files.rb', line 217

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, = delete(uri, if_match: if_match)
  result
end

#delete_task(task) ⇒ Object



45
46
47
48
49
50
# File 'lib/boxr/tasks.rb', line 45

def delete_task(task)
  task_id = ensure_id(task)
  uri = "#{TASKS_URI}/#{task_id}"
  result, = delete(uri)
  result
end

#delete_task_assignment(task) ⇒ Object



79
80
81
82
83
84
# File 'lib/boxr/tasks.rb', line 79

def delete_task_assignment(task)
  task_id = ensure_id(task)
  uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
  result, = delete(uri)
  result
end

#delete_trashed_file(file) ⇒ Object



282
283
284
285
286
287
288
# File 'lib/boxr/files.rb', line 282

def delete_trashed_file(file)
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}/trash"

  result, = delete(uri)
  result
end

#delete_trashed_folder(folder) ⇒ Object



145
146
147
148
149
150
# File 'lib/boxr/folders.rb', line 145

def delete_trashed_folder(folder)
  folder_id = ensure_id(folder)
  uri = "#{FOLDERS_URI}/#{folder_id}/trash"
  result, = delete(uri)
  result
end


61
62
63
64
65
66
# File 'lib/boxr/web_links.rb', line 61

def delete_trashed_web_link(web_link)
  web_link_id = ensure_id(web_link)
  uri = "#{WEB_LINKS_URI}/#{web_link_id}/trash"
  result, = delete(uri)
  result
end

#delete_user(user, notify: nil, force: nil) ⇒ Object



126
127
128
129
130
131
132
133
134
135
# File 'lib/boxr/users.rb', line 126

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, = delete(uri, query: query)
  result
end

#delete_user_avatar(user_id) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/boxr/avatars.rb', line 25

def delete_user_avatar(user_id)
  user_id = ensure_id(user_id)
  uri = "#{USERS_URI}/#{user_id}/avatar"

  result, = delete(uri)
  result
end


43
44
45
46
47
48
49
# File 'lib/boxr/web_links.rb', line 43

def delete_web_link(web_link)
  web_link_id = ensure_id(web_link)
  uri = "#{WEB_LINKS_URI}/#{web_link_id}"

  result, = delete(uri)
  result
end

#delete_webhook(webhook) ⇒ Object



32
33
34
35
36
37
# File 'lib/boxr/webhooks.rb', line 32

def delete_webhook(webhook)
  webhook_id = ensure_id(webhook)
  uri = "#{WEBHOOKS_URI}/#{webhook_id}"
  result, = delete(uri)
  result
end


267
268
269
270
271
# File 'lib/boxr/files.rb', line 267

def disable_shared_link_for_file(file)
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}"
  disable_shared_link(uri)
end


116
117
118
119
120
# File 'lib/boxr/folders.rb', line 116

def disable_shared_link_for_folder(folder)
  folder_id = ensure_id(folder)
  uri = "#{FOLDERS_URI}/#{folder_id}"
  disable_shared_link(uri)
end

#download_file(file, version: nil, follow_redirect: true) ⇒ Object

rubocop:disable Metrics



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/boxr/files.rb', line 76

def download_file(file, version: nil, follow_redirect: true) # rubocop:disable Metrics
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}/content"
  query = {}
  query[:version] = version unless version.nil?

  loop do
    # Don't automatically follow the redirect
    _, response = get(uri, query: query, success_codes: [302, 202],
                           process_response: false, follow_redirect: false)

    # By default, Box always returns a 302
    if response.status == 302
      location = response.header['Location'][0]
      return location unless follow_redirect

      file_content, = get(location, process_response: false)
      return file_content

    elsif response.status == 202
      sleep response.header['Retry-After'][0].to_i
    end
  end
end

#download_url(file, version: nil) ⇒ Object



101
102
103
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/boxr/collaborations.rb', line 47

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, = put(uri, attributes)
  updated_collaboration
end

#email_aliases_for_user(user) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/boxr/users.rb', line 149

def email_aliases_for_user(user)
  user_id = ensure_id(user)
  uri = "#{USERS_URI}/#{user_id}/email_aliases"

  aliases, = get(uri)
  aliases['entries']
end

#embed_url(file, show_download: false, show_annotations: false) ⇒ Object Also known as: embed_link, preview_url, preview_link



29
30
31
32
# 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])
  file_info.expiring_embed_link.url + "?showDownload=#{show_download}&showAnnotations=#{show_annotations}"
end

#enterprise_events(created_after: nil, created_before: nil, stream_position: 0, event_type: nil, limit: 500) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# 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) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# 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_metadataObject Also known as: get_enterprise_templates



83
84
85
86
87
# File 'lib/boxr/metadata.rb', line 83

def 
  uri = "#{METADATA_TEMPLATES_URI}/enterprise"
  , = get(uri)
  
end

#file_collaborations(file, fields: [], limit: DEFAULT_LIMIT, marker: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/boxr/collaborations.rb', line 15

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"

  file_collaborations, = get(uri, query: query)
  file_collaborations['entries']
end

#file_comments(file, fields: []) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/boxr/comments.rb', line 5

def file_comments(file, fields: [])
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}/comments"
  query = build_fields_query(fields, COMMENT_FIELDS_QUERY)

  get_all_with_pagination(uri, query: query, offset: 0, limit: DEFAULT_LIMIT)
end

#file_from_id(file_id, fields: []) ⇒ Object Also known as: file



20
21
22
23
24
25
26
# 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, = get(uri, query: query)
  file
end

#file_from_path(path) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/boxr/files.rb', line 5

def file_from_path(path)
  path = path.slice(1..-1) if path.start_with?('/')

  path_items = path.split('/')
  file_name = path_items.slice!(-1)

  folder = folder_from_path(path_items.join('/'))

  files = folder_items(folder, fields: %i[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: []) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/boxr/tasks.rb', line 5

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, = get(uri, query: query)
  tasks.entries
end

#folder_collaborations(folder, fields: [], limit: DEFAULT_LIMIT, marker: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/boxr/collaborations.rb', line 3

def folder_collaborations(folder, fields: [], limit: DEFAULT_LIMIT, marker: nil)
  folder_id = ensure_id(folder)
  query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
  query[:limit] = limit
  query[:marker] = marker unless marker.nil?

  uri = "#{FOLDERS_URI}/#{folder_id}/collaborations"

  folder_collaborations, = get(uri, query: query)
  folder_collaborations['entries']
end

#folder_from_id(folder_id, fields: []) ⇒ Object Also known as: folder



19
20
21
22
23
24
25
26
# 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, = get(uri, query: query)
  folder
end

#folder_from_path(path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/boxr/folders.rb', line 5

def folder_from_path(path)
  path = path.slice(1..-1) if path.start_with?('/')

  path_folders = path.split('/')

  folder = path_folders.inject(Boxr::ROOT) do |parent_folder, folder_name|
    folders = folder_items(parent_folder, fields: %i[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) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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?
    get_all_with_pagination(uri, query: query, offset: 0, limit: FOLDER_ITEMS_LIMIT)
  else
    query[:offset] = offset
    query[:limit] = limit
    items, = get(uri, query: query)
    items['entries']
  end
end

#folder_metadata(folder, scope, template) ⇒ Object



26
27
28
29
30
31
# File 'lib/boxr/metadata.rb', line 26

def (folder, scope, template)
  folder_id = ensure_id(folder)
  uri = "#{FOLDER_METADATA_URI}/#{folder_id}/metadata/#{scope}/#{template}"
  , = get(uri)
  
end

#get_metadata_template_by_id(template_id) ⇒ Object



97
98
99
100
101
102
# File 'lib/boxr/metadata.rb', line 97

def (template_id)
  template_id = ensure_id(template_id)
  uri = "#{METADATA_TEMPLATES_URI}/#{template_id}"
  schema, = get(uri)
  schema
end

#get_user_avatar(user_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/boxr/avatars.rb', line 5

def get_user_avatar(user_id)
  user_id = ensure_id(user_id)
  uri = "#{USERS_URI}/#{user_id}/avatar"

  avatar_data, = get(uri, process_response: false)
  avatar_data
end

#get_watermark_on_file(file) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/boxr/watermarking.rb', line 5

def get_watermark_on_file(file)
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}/watermark"

  file, = get(uri)
  file
end

#get_watermark_on_folder(folder) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/boxr/watermarking.rb', line 32

def get_watermark_on_folder(folder)
  folder_id = ensure_id(folder)
  uri = "#{FOLDERS_URI}/#{folder_id}/watermark"

  folder, = get(uri)
  folder
end


20
21
22
23
24
25
26
# 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, = get(uri)
  web_link
end

#get_webhook(webhook) ⇒ Object



18
19
20
21
22
23
# File 'lib/boxr/webhooks.rb', line 18

def get_webhook(webhook)
  webhook_id = ensure_id(webhook)
  uri = "#{WEBHOOKS_URI}/#{webhook_id}"
  webhook, = get(uri)
  webhook
end

#get_webhooks(marker: nil, limit: nil) ⇒ Object



12
13
14
15
16
# File 'lib/boxr/webhooks.rb', line 12

def get_webhooks(marker: nil, limit: nil)
  query_params = { marker: marker, limit: limit }.compact
  webhooks, = get(WEBHOOKS_URI, query: query_params)
  webhooks
end

#group_collaborations(group, offset: 0, limit: DEFAULT_LIMIT) ⇒ Object



27
28
29
30
31
32
# File 'lib/boxr/collaborations.rb', line 27

def group_collaborations(group, offset: 0, limit: DEFAULT_LIMIT)
  group_id = ensure_id(group)
  uri = "#{GROUPS_URI}/#{group_id}/collaborations"

  get_all_with_pagination(uri, offset: offset, limit: limit)
end

#group_from_id(group_id, fields: []) ⇒ Object Also known as: group



10
11
12
13
14
15
16
17
# File 'lib/boxr/groups.rb', line 10

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, = get(uri, query: query)
  group
end

#group_membership_from_id(membership_id) ⇒ Object Also known as: group_membership



60
61
62
63
64
65
# File 'lib/boxr/groups.rb', line 60

def group_membership_from_id(membership_id)
  membership_id = ensure_id(membership_id)
  uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
  membership, = get(uri)
  membership
end

#group_memberships(group, offset: 0, limit: DEFAULT_LIMIT) ⇒ Object



43
44
45
46
47
# File 'lib/boxr/groups.rb', line 43

def group_memberships(group, offset: 0, limit: DEFAULT_LIMIT)
  group_id = ensure_id(group)
  uri = "#{GROUPS_URI}/#{group_id}/memberships"
  get_all_with_pagination(uri, offset: offset, limit: limit)
end

#group_memberships_for_me(offset: 0, limit: DEFAULT_LIMIT) ⇒ Object



55
56
57
58
# File 'lib/boxr/groups.rb', line 55

def group_memberships_for_me(offset: 0, limit: DEFAULT_LIMIT)
  uri = "#{USERS_URI}/me/memberships"
  get_all_with_pagination(uri, offset: offset, limit: limit)
end

#group_memberships_for_user(user, offset: 0, limit: DEFAULT_LIMIT) ⇒ Object



49
50
51
52
53
# File 'lib/boxr/groups.rb', line 49

def group_memberships_for_user(user, offset: 0, limit: DEFAULT_LIMIT)
  user_id = ensure_id(user)
  uri = "#{USERS_URI}/#{user_id}/memberships"
  get_all_with_pagination(uri, offset: offset, limit: limit)
end

#groups(fields: [], offset: 0, limit: DEFAULT_LIMIT) ⇒ Object



5
6
7
8
# File 'lib/boxr/groups.rb', line 5

def groups(fields: [], offset: 0, limit: DEFAULT_LIMIT)
  query = build_fields_query(fields, GROUP_FIELDS_QUERY)
  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) ⇒ Object



55
56
57
58
59
60
61
# 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) ⇒ Object



19
20
21
22
23
24
# File 'lib/boxr/metadata.rb', line 19

def (file, scope: :global, template: :properties)
  file_id = ensure_id(file)
  uri = "#{FILE_METADATA_URI}/#{file_id}/metadata/#{scope}/#{template}"
  , = get(uri)
  
end

#metadata_schema(scope, template_key) ⇒ Object Also known as: get_metadata_template_by_name



90
91
92
93
94
# File 'lib/boxr/metadata.rb', line 90

def (scope, template_key)
  uri = "#{METADATA_TEMPLATES_URI}/#{scope}/#{template_key}/schema"
  schema, = get(uri)
  schema
end

#move_file(file, new_parent, name: nil, if_match: nil) ⇒ Object



72
73
74
# 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) ⇒ Object



84
85
86
# File 'lib/boxr/folders.rb', line 84

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) ⇒ Object

As of writing, API only supports a root source folder (0)



138
139
140
141
142
143
144
145
146
147
# File 'lib/boxr/users.rb', line 138

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, = put(uri, attributes)
  folder
end

#pending_collaborations(fields: []) ⇒ Object

These are pending collaborations for the current user Use the As-User Header to request for different users



78
79
80
81
82
83
# File 'lib/boxr/collaborations.rb', line 78

def pending_collaborations(fields: [])
  query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
  query[:status] = :pending
  pending_collaborations, = get(COLLABORATIONS_URI, query: query)
  pending_collaborations['entries']
end

#promote_old_version_of_file(file, file_version) ⇒ Object



200
201
202
203
204
205
206
207
208
# File 'lib/boxr/files.rb', line 200

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, = post(uri, attributes)
  new_version
end

#remove_collaboration(collaboration) ⇒ Object



58
59
60
61
62
63
# File 'lib/boxr/collaborations.rb', line 58

def remove_collaboration(collaboration)
  collaboration_id = ensure_id(collaboration)
  uri = "#{COLLABORATIONS_URI}/#{collaboration_id}"
  result, = delete(uri)
  result
end

#remove_email_alias_for_user(user, email_alias) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/boxr/users.rb', line 166

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, = delete(uri)
  result
end

#remove_watermark_on_file(file) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/boxr/watermarking.rb', line 24

def remove_watermark_on_file(file)
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}/watermark"

  result, = delete(uri)
  result
end

#remove_watermark_on_folder(folder) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/boxr/watermarking.rb', line 51

def remove_watermark_on_folder(folder)
  folder_id = ensure_id(folder)
  uri = "#{FOLDERS_URI}/#{folder_id}/watermark"

  result, = delete(uri)
  result
end

#reply_to_comment(comment, message: nil, tagged_message: nil) ⇒ Object



18
19
20
21
# File 'lib/boxr/comments.rb', line 18

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) ⇒ Object



290
291
292
293
294
295
296
# File 'lib/boxr/files.rb', line 290

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) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/boxr/folders.rb', line 152

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


68
69
70
71
72
73
74
# File 'lib/boxr/web_links.rb', line 68

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) ⇒ Object



44
45
46
# 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: [], fields: [], 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) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/boxr/search.rb', line 5

def search(query = nil, scope: nil, file_extensions: [], fields: [],
           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)
  # if a string is passed in assume it is already formatted correctly
  if !mdfilters.nil? && !mdfilters.is_a?(String)
    unless mdfilters.is_a? Array
      # if just one mdfilter is specified ensure that it is packaged inside an array
      mdfilters = [mdfilters]
    end
    mdfilters = JSON.dump(mdfilters)
  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)
  fields_string = to_comma_separated_string(fields)

  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[:fields] = fields_string unless fields_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?
  unless ancestor_folder_ids_string.nil?
    search_query[:ancestor_folder_ids] =
      ancestor_folder_ids_string
  end
  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, = get(SEARCH_URI, query: search_query)
  results.entries
end

#shared_item(shared_link, shared_link_password: nil) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/boxr/shared_items.rb', line 5

def shared_item(shared_link, shared_link_password: nil)
  box_api_header = "shared_link=#{shared_link}"
  unless shared_link_password.nil?
    box_api_header += "&shared_link_password=#{shared_link_password}"
  end

  file_or_folder, = get(SHARED_ITEMS_URI, box_api_header: box_api_header)
  file_or_folder
end

#task_assignment(task) ⇒ Object



72
73
74
75
76
77
# File 'lib/boxr/tasks.rb', line 72

def task_assignment(task)
  task_id = ensure_id(task)
  uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
  task_assignment, = get(uri)
  task_assignment
end

#task_assignments(task) ⇒ Object



52
53
54
55
56
57
# File 'lib/boxr/tasks.rb', line 52

def task_assignments(task)
  task_id = ensure_id(task)
  uri = "#{TASKS_URI}/#{task_id}/assignments"
  assignments, = get(uri)
  assignments['entries']
end

#task_from_id(task_id) ⇒ Object Also known as: task



25
26
27
28
29
30
# File 'lib/boxr/tasks.rb', line 25

def task_from_id(task_id)
  task_id = ensure_id(task_id)
  uri = "#{TASKS_URI}/#{task_id}"
  task, = get(uri)
  task
end

#thumbnail(file, min_height: nil, min_width: nil, max_height: nil, max_width: nil) ⇒ Object

rubocop:disable Metrics



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/boxr/files.rb', line 239

def thumbnail(file, min_height: nil, min_width: nil, max_height: nil, max_width: nil) # rubocop:disable Metrics
  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 [202, 302].include?(response.status)
    location = response.header['Location'][0]
    thumbnail, = get(location, process_response: false)
  else # 200
    thumbnail = body
  end

  thumbnail
end

#trash(fields: [], offset: nil, limit: nil) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/boxr/folders.rb', line 122

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?
    get_all_with_pagination(uri, query: query, offset: 0, limit: FOLDER_ITEMS_LIMIT)
  else
    query[:offset] = offset
    query[:limit] = limit
    items, = get(uri, query: query)
    items['entries']
  end
end

#trashed_file(file, fields: []) ⇒ Object



273
274
275
276
277
278
279
280
# File 'lib/boxr/files.rb', line 273

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, = get(uri, query: query)
  trashed_file
end

#trashed_folder(folder, fields: []) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/boxr/folders.rb', line 136

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, = get(uri, query: query)
  folder
end


51
52
53
54
55
56
57
58
# File 'lib/boxr/web_links.rb', line 51

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, = get(uri, query: query)
  web_link
end

#unlock_file(file, if_match: nil) ⇒ Object



63
64
65
66
67
68
69
70
# 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, = 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) ⇒ Object

rubocop:disable Metrics



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/boxr/files.rb', line 37

def update_file(file, name: nil, description: nil, parent: nil, # rubocop:disable Metrics
                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, = 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) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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?
  unless folder_upload_email_access.nil?
    attributes[:folder_upload_email] =
      { access: folder_upload_email_access }
  end
  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, = put(uri, attributes, if_match: if_match)
  updated_folder
end

#update_folder_metadata(folder, updates, scope, template) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/boxr/metadata.rb', line 58

def (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

  , = put(uri, updates, content_type: 'application/json-patch+json')
  
end

#update_group(group, name) ⇒ Object Also known as: rename_group



26
27
28
29
30
31
32
33
# File 'lib/boxr/groups.rb', line 26

def update_group(group, name)
  group_id = ensure_id(group)
  uri = "#{GROUPS_URI}/#{group_id}"
  attributes = { name: name }

  updated_group, = put(uri, attributes)
  updated_group
end

#update_group_membership(membership, role) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/boxr/groups.rb', line 78

def update_group_membership(membership, role)
  membership_id = ensure_id(membership)
  uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
  attributes = { role: role }
  updated_membership, = put(uri, attributes)
  updated_membership
end

#update_metadata(file, updates, scope: :global, template: :properties) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/boxr/metadata.rb', line 47

def (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

  , = put(uri, updates, content_type: 'application/json-patch+json')
  
end

#update_task(task, action: :review, message: nil, due_at: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/boxr/tasks.rb', line 33

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, = put(uri, attributes)
  task
end

#update_task_assignment(task, message: nil, resolution_state: nil) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# File 'lib/boxr/tasks.rb', line 86

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, = 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) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/boxr/users.rb', line 81

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 = {}
  query[:notify] = notify unless notify.nil?

  attributes = {}
  # this is a special condition where setting this to nil means to roll this user out of the enterprise
  attributes[:enterprise] = nil if enterprise.nil?
  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?
  unless is_exempt_from_device_limits.nil?
    attributes[:is_exempt_from_device_limits] =
      is_exempt_from_device_limits
  end
  unless .nil?
    attributes[:is_exempt_from_login_verification] =
      
  end
  unless is_exempt_from_reset_required.nil?
    attributes[:is_exempt_from_reset_required] =
      is_exempt_from_reset_required
  end
  unless is_external_collab_restricted.nil?
    attributes[:is_external_collab_restricted] =
      is_external_collab_restricted
  end

  updated_user, = put(uri, attributes, query: query)
  updated_user
end


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/boxr/web_links.rb', line 28

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, = put(uri, attributes)
  updated_web_link
end

#update_webhook(webhook, attributes = {}) ⇒ Object



25
26
27
28
29
30
# File 'lib/boxr/webhooks.rb', line 25

def update_webhook(webhook, attributes = {})
  webhook_id = ensure_id(webhook)
  uri = "#{WEBHOOKS_URI}/#{webhook_id}"
  updated_webhook, = 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) ⇒ Object

rubocop:disable Metrics



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/boxr/files.rb', line 105

def upload_file(path_to_file, parent, name: nil, content_created_at: nil, # rubocop:disable Metrics
                content_modified_at: nil, preflight_check: true, send_content_md5: true)
  filename = 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) ⇒ Object

rubocop:disable Metrics



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/boxr/files.rb', line 118

def upload_file_from_io(io, parent, name:, content_created_at: nil, # rubocop:disable Metrics
                        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 } }
  unless content_created_at.nil?
    attributes[:content_created_at] =
      content_created_at.to_datetime.rfc3339
  end
  unless content_modified_at.nil?
    attributes[:content_modified_at] =
      content_modified_at.to_datetime.rfc3339
  end

  body = { attributes: JSON.dump(attributes), file: io }

  file_info, = 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) ⇒ Object

rubocop:disable Metrics



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/boxr/files.rb', line 147

def upload_new_version_of_file( # rubocop:disable Metrics
  path_to_file, file, content_modified_at: nil,
  send_content_md5: true, preflight_check: true, if_match: nil, name: nil
)
  filename = 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) ⇒ Object

rubocop:disable Metrics



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/boxr/files.rb', line 162

def upload_new_version_of_file_from_io( # rubocop:disable Metrics
  io, file, name: nil, content_modified_at: nil,
  send_content_md5: true, preflight_check: true, if_match: nil
)
  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"

  if send_content_md5
    content_md5 = Digest::SHA1.hexdigest(io.read)
    io.rewind
  end

  attributes = { name: name }
  unless content_modified_at.nil?
    attributes[:content_modified_at] =
      content_modified_at.to_datetime.rfc3339
  end

  body = { attributes: JSON.dump(attributes), file: io }

  file_info, = 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) ⇒ Object



4
5
6
7
8
9
# 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: []) ⇒ Object Also known as: user



14
15
16
17
18
19
20
21
# File 'lib/boxr/users.rb', line 14

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, = get(uri, query: query)
  user
end

#versions_of_file(file) ⇒ Object



193
194
195
196
197
198
# File 'lib/boxr/files.rb', line 193

def versions_of_file(file)
  file_id = ensure_id(file)
  uri = "#{FILES_URI}/#{file_id}/versions"
  versions, = get(uri)
  versions.entries
end