Skip to content

Commit

Permalink
feat: add file requests api support (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwwoda authored Jul 15, 2022
1 parent 4649d8a commit 73f0490
Show file tree
Hide file tree
Showing 13 changed files with 14,449 additions and 165 deletions.
13,978 changes: 13,814 additions & 164 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@oclif/plugin-help": "^2.2.1",
"@oclif/plugin-not-found": "^1.2.0",
"archiver": "^3.0.0",
"box-node-sdk": "^2.3.0",
"box-node-sdk": "^2.4.0",
"chalk": "^2.4.1",
"cli-progress": "^2.1.0",
"csv": "^3.1.0",
Expand Down
90 changes: 90 additions & 0 deletions src/commands/file-requests/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
'use strict';

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');

class FileRequestsCopyCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(FileRequestsCopyCommand);
let options = { folder: { type: 'folder' }};

if (args.folderID) {
options.folder.id = args.folderID;
}

if (flags.title) {
options.title = flags.title;
}

if (flags.description) {
options.description = flags.description;
}

if (flags['expires-at']) {
options.expires_at = flags['expires-at'];
}

if (flags['description-required']) {
options.is_description_required = flags['description-required'];
}

if (flags['email-required']) {
options.is_email_required = flags['email-required'];
}

if (flags.status) {
options.status = flags.status;
}

let fileRequest = await this.client.fileRequests.copy(args.id, options);
await this.output(fileRequest);
}
}

FileRequestsCopyCommand.description =
'Copies existing file request to new folder';
FileRequestsCopyCommand.examples = ['box file-requests:copy 22222 44444'];
FileRequestsCopyCommand._endpoint = 'post_file_requests_id_copy';

FileRequestsCopyCommand.flags = {
...BoxCommand.flags,
description: flags.string({
description: 'New description of file request',
}),
'expires-at': flags.string({
description: 'New date when file request expires',
parse: (input) => BoxCommand.normalizeDateString(input),
}),
'description-required': flags.boolean({
description:
'is file request submitter required to provide a description of the files they are submitting',
allowNo: true,
}),
'email-required': flags.boolean({
description: 'New date when file request expires',
allowNo: true,
}),
status: flags.string({
description: 'New status of file request',
options: ['active', 'inactive'],
}),
title: flags.string({
description: 'New title of file request',
}),
};
FileRequestsCopyCommand.args = [
{
name: 'id',
required: true,
hidden: false,
description: 'ID of the file request to copy',
},
{
name: 'folderID',
required: true,
hidden: false,
description: 'ID of folder to which file request will be copied',
},
];

module.exports = FileRequestsCopyCommand;
31 changes: 31 additions & 0 deletions src/commands/file-requests/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const BoxCommand = require('../../box-command');

class FileRequestsDeleteCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(FileRequestsDeleteCommand);

await this.client.fileRequests.delete(args.id);
this.info(`Deleted file request ${args.id}`);
}
}

FileRequestsDeleteCommand.description = 'Delete individual file request';
FileRequestsDeleteCommand.examples = ['box file-requests:delete 12345'];
FileRequestsDeleteCommand._endpoint = 'delete_file_requests_id';

FileRequestsDeleteCommand.flags = {
...BoxCommand.flags,
};

FileRequestsDeleteCommand.args = [
{
name: 'id',
required: true,
hidden: false,
description: 'ID of the file request to delete',
},
];

module.exports = FileRequestsDeleteCommand;
31 changes: 31 additions & 0 deletions src/commands/file-requests/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const BoxCommand = require('../../box-command');

class FileRequestsGetCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(FileRequestsGetCommand);

let fileRequest = await this.client.fileRequests.getById(args.id);
await this.output(fileRequest);
}
}

FileRequestsGetCommand.description = 'Get information about an file request';
FileRequestsGetCommand.examples = ['box file-requests:get 12345'];
FileRequestsGetCommand._endpoint = 'get_file_requests_id';

FileRequestsGetCommand.flags = {
...BoxCommand.flags,
};

FileRequestsGetCommand.args = [
{
name: 'id',
required: true,
hidden: false,
description: 'ID of the file request to get',
},
];

module.exports = FileRequestsGetCommand;
94 changes: 94 additions & 0 deletions src/commands/file-requests/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use strict';

const BoxCommand = require('../../box-command');
const { flags } = require('@oclif/command');

class FileRequestsUpdateCommand extends BoxCommand {
async run() {
const { flags, args } = this.parse(FileRequestsUpdateCommand);
let updates = {};
let etag = '';

if (flags.description) {
updates.description = flags.description;
}

if (flags['expires-at']) {
updates.expires_at = flags['expires-at'];
}

if (flags['description-required']) {
updates.is_description_required = flags['description-required'];
}

if (flags['email-required']) {
updates.is_email_required = flags['email-required'];
}

if (flags.status) {
updates.status = flags.status;
}

if (flags.title) {
updates.title = flags.title;
}

if (flags.etag) {
etag = flags.etag;
}

let fileRequest = await this.client.fileRequests.update(
args.id,
updates,
etag
);
await this.output(fileRequest);
}
}

FileRequestsUpdateCommand.description = 'Update a file request';
FileRequestsUpdateCommand.examples = [
'box file-requests:update 12345 --description "New file request description!"',
];
FileRequestsUpdateCommand._endpoint = 'put_file_requests_id';

FileRequestsUpdateCommand.flags = {
...BoxCommand.flags,
description: flags.string({
description: 'New description of file request',
}),
'expires-at': flags.string({
description: 'New date when file request expires',
parse: (input) => BoxCommand.normalizeDateString(input),
}),
'description-required': flags.boolean({
description:
'is file request submitter required to provide a description of the files they are submitting',
allowNo: true,
}),
'email-required': flags.boolean({
description: 'New date when file request expires',
allowNo: true,
}),
status: flags.string({
description: 'New status of file request',
options: ['active', 'inactive'],
}),
title: flags.string({
description: 'New title of file request',
}),
etag: flags.string({
description: `Pass in the item's last observed etag value into this header and the endpoint will fail with a 412 Precondition Failed if it has changed since.`,
}),
};

FileRequestsUpdateCommand.args = [
{
name: 'id',
required: true,
hidden: false,
description: 'ID of the file request to update',
},
];

module.exports = FileRequestsUpdateCommand;
Loading

0 comments on commit 73f0490

Please sign in to comment.