linkstreet / box-sdk
v2 Box sdk for php
Installs: 1 081
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 5
Forks: 6
Open Issues: 1
Type:sdk
Requires
- firebase/php-jwt: ^6.0
- guzzlehttp/guzzle: ^7.0.1
- webmozart/assert: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.3
- symfony/var-dumper: ^5.1
- symfony/yaml: ^3.2
- dev-master
- v0.4.0
- v0.3.0
- v0.2.5
- v0.2.4
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.1
- v0.1.0
- dev-dependabot/composer/phpunit/phpunit-9.3.7
- dev-dependabot/composer/symfony/yaml-3.4.43
- dev-dependabot/composer/symfony/var-dumper-5.1.3
- dev-dependabot/composer/webmozart/assert-1.9.1
- dev-dependabot/composer/guzzlehttp/guzzle-7.0.1
- dev-dependabot/composer/firebase/php-jwt-5.2.0
- dev-enhancement/tls1.2
This package is auto-updated.
Last update: 2024-11-18 17:42:46 UTC
README
So far this SDK has only machine to machine authentication mechanism and the following functionality
Folders
- Get folder info
- Get folder items
- Create folder
- Delete folder
- Get trashed items
- Destroy trashed folder
- Restore the trashed folder
Files
- Upload file
- Upload Pre flight - This API is used to check if the metadata supplied is valid or not.
- Get embed URL
- Delete a file (soft delete - Moves to trash)
- Destroy trashed file
- Restore the trashed file
Usage
use Linkstreet\Box\Box; use Linkstreet\Box\Enums\SubscriptionType; $box_sdk = new Box(['client_id' => "", "client_secret" => ""]); $app_auth_info = [ "key_id" => "key id from box app", "private_key" => "path to private key", "pass_phrase" => "passphrase", // Can be empty "subscription_type" => SubscriptionType::ENTERPRISE or SubscriptionType::USER, "id" => "enterprise id or user id" ]; // Authenticates with box server and returns app_auth instance. // Throws `GuzzleHttp\Exception\ClientException` on failure $app_auth_instance = $box_sdk->getAppAuthClient($app_auth_info);
Folder Service
-
To get the service
$folder_service = $app_auth_instance->getFolderService();
-
Methods available in
$folder_service
1. getFolderInfo($folder_id); // Defaults to root folder (id = 0) 2. getFolderItems($folder_id = 0, $fields = [], $limit = 100, $offset = 0); // Defaults to root folder (id = 0) 3. create($folder_name, $parent_folder_id = 0) 4. delete($folder_id, $recursive = false, $e_tag = null) 5. getTrashedItems() 6. destroyTrashedFolder($folder_id) 7. restore($trashed_folder_id, $new_name = null, $parent_folder_id = null)
File Service
-
To get the service
$file_service = $app_auth_instance->getFileService();
-
Methods available in
$file_service
1. uploadPreFlight($file_path = "", $folder_id = 0, $filename = null); // If filename is null, file name will be derived from actual file name. 2. upload($file_path = "", $folder_id = 0, $filename = null); // If filename is null, file name will be derived from actual file name. 3. getEmbedUrl($file_id) 4. delete($file_id) 5. destroyTrashedFile($file_id) 6. restore($trashed_file_id, $new_name = null, $parent_folder_id = null)
NOTE:
- All APIs return
\GuzzleHttp\Psr7\Response
(to get the body use$response->getBody()->getContents()
. Refer Guzzle HTTP Messages) exceptgetEmbedUrl($file_id)
which returns string. - Guzzle related exceptions and its documentation can be found in Guzzle Docs