-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add file requests api support (#355)
- Loading branch information
Showing
13 changed files
with
14,449 additions
and
165 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.