Skip to content

squio/yii2-boxapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Box API 2.0 for Yii 2

Interface with the Box.com API

Features:

  • connect through OAuth 2
  • basic file management (list, upload, download, delete)

This module is roughly based on maengkom/boxapi for Laravel

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist squio/yii2-boxapi "*"

or add

"squio/yii2-boxapi": "*"

to the require section of your composer.json file.

Configuration

Run migrations to create the box_user table:

php yii migrate --migrationPath=@vendor/squio/boxapi/src/migrations

Add the configuration to modules in your config.php

'modules' => [
    'boxapi' => [
        'class' => 'squio\boxapi\BoxApi',
        'config' => [
            'client_id'         => 'YOUR_BOX_CLIENT_ID',
            'client_secret'     => 'YOUR_BOX_CLIEN_SECRET',
            // optional encryption key, to encrypt user tokens in database
            'data_crypt_key'    => 'RANDOM_STRING',
        ]
    ],
],

API List

Below are the API methods you can used. All methods are following Box documentation.

Object Method Verb Official Manual
Folder getFolderInfo($id) Get Get Folder’s Info
Folder getFolderItems($id) Get Get Folder's Items
Folder createFolder($name, $parent_id) Post Create Folder
Folder updateFolder($id, $name) Put Update Folder
Folder deleteFolder($id) Delete Delete Folder
Folder copyFolder($id, $dest) Post Copy Folder
Folder createSharedLink($id) Put Create Shared Link
Folder folderCollaborations($id) Get Folder Collaborations
Folder getTrashedItems($limit, $offeset) Get Get Trashed Items
Folder getTrashedFolder($id) Get Get Trashed Folder
Folder permanentDelete($id) Delete Permanently Delete
Folder restoreFolder($id, $newName) Get Restore Folder
File getFileInfo($id) Get Get File's Info
File getFileVersionInfo($id) Get Get File's Version Info
File updateFileInfo($id, $name) Put Update File's Info
File toggleLock($id, $type, $expire, $down) Put Lock and Unlock
File downloadFile($id) Get Download File
File uploadFile($file, $parent, $name) Post Upload File
File deleteFile($id) Delete Delete File
File updateFile($name, $id) Post Update File
File copyFile($id, $dest) Post Copy File
File getThumbnail($id) Get Get Thumbnail
File getEmbedLink($id) Get Get Embed Link
File createSharedLink($id, $access) Put Create Shared Link
File getTrashedFile($id) Get Get Trashed File
File deleteFilePermanent($id) Delete Permanently Delete
File restoreItem($id, $newName) Post Restore File Item
File viewComments($id) Get View Comments
File getFileTasks($id) Get Get File's Tasks

Usage

Once the module is installed, simply use it anywhere in your code:

// Initialize module and authenticate current logged-in user with Box
// Throws InvalidCallException if no user is logged in
$boxapi = \Yii::$app->getModule('boxapi');

// Authenticate with Box; takes care of all of OAuth protocol and redirects
// user as needed to ask for permissions
$boxapi->authenticate();

// Get root folder listing as nested array structure
$boxapi->getFolderInfo('0')

// List a folder's index: open URL http://<app-name>/boxapi/folder?id=0

// Download file, a specific version can be specified for Enterprise accounts
$this->redirect($boxapi->downloadFile('12364521', $versionId = '675463234'))

About

Yii2 implementation of Box API 2.0 for Standard User accounts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages