BOX API 集成包装器。

v10.0.2 2024-03-01 17:18 UTC

This package is auto-updated.

Last update: 2024-09-24 18:43:34 UTC


README

用于将 Box Api 集成到 Laravel 应用程序的包装器。

开发者指南:https://developer.box.com.

安装

  • composer require prasadchinwal/box
  • 运行 php artisan vendor:publish 并发布配置文件。
  • 编辑 config/box.php 文件以配置您的设置。有关配置的更多信息,请访问 https://developer.box.com/guides/

用法

文件 API

  • 获取文件信息:文档 获取关于文件的详细信息。

    use PrasadChinwal\Box\Facades\Box;
    Box::file()->whereId('1234')->info();
  • 下载文件:文档 返回文件的二进制内容。

    use PrasadChinwal\Box\Facades\Box;
    Box::file()->whereId('1234')->downloadFile();
  • 为文件创建共享链接:文档 为文件添加共享链接。

    use PrasadChinwal\Box\Facades\BoxFile;
    $attributes = [
        'shared_link' => [
            'access' => 'company',
            'permissions' => [
                'can_download' => true,
                'can_edit' => true,
            ]
        ]
    ];
    Box::file()->whereId('1234')->createSharedLink(attributes: $attributes);
  • 从共享链接查找文件:文档 返回由共享链接表示的文件。共享文件可以由共享链接表示,该链接可以来自当前企业或来自另一个企业。此端点允许应用程序在仅给定共享链接的情况下检索有关共享文件的信息。

    use PrasadChinwal\Box\Facades\BoxFile;
    $sharedLink = 'https://my.box.com/s/xasddyuejhkljawd';
    Box::file()->whereLink($sharedLink)->find();
  • 获取文件的共享链接:文档 获取文件共享链接的信息。

    use PrasadChinwal\Box\Facades\BoxFile;
    Box::file()->whereId('1234')->getSharedLink();
  • 获取文件的缩略图:文档 获取文件的缩略图或较小图像表示。

    use PrasadChinwal\Box\Facades\BoxFile;
     Box::file()->whereId('1234')->thumbnail(extension: '.jpg');
  • 复制文件:文档 将文件从一个位置复制到另一个位置。

    use PrasadChinwal\Box\Facades\BoxFile;
    $attributes = [
        'name' => 'TestFile.pdf', // An optional new name for the copied file.
        'parent' => [
            'id' => '4321' // The ID of folder to copy the file to.
        ],
        'version' => null // An optional ID of the specific file version to copy.
    ];
    Box::file()->whereId('1234')->copy(attributes: $attributes);
  • 更新文件:文档 使用提供的属性更新现有文件。

    use PrasadChinwal\Box\Facades\BoxFile;
    $attributes = [
        'name' => 'Test.pdf',  // An optional different name for the file. This can be used to rename the file.
        'description' => 'Testing update api.', //The description for a file. This can be seen in the right-hand sidebar panel when viewing a file in the Box web app. Additionally, this index is used in the search index of the file, allowing users to find the file by the content in the description.
        'disposition_at' => '2023-12-12T10:53:43-08:00', // The retention expiration timestamp for the given file. This date cannot be shortened once set on a file.
        'lock' => [ // Defines a lock on an item. This prevents the item from being moved, renamed, or otherwise changed by anyone other than the user who created the lock.
            'access' => 'lock',  // The type of this object. Value is always lock
            'expiration_at' => '',  // Defines the time at which the lock expires.
            'is_download_prevented' => false,  // Defines if the file can be downloaded while it is locked.
        ],
        'parent' => [  // An optional new parent folder for the file. This can be used to move the file to a new folder.
            'id' => ''  // The ID of parent item
        ],
        'permissions' => [  // Defines who can download a file.
            'can_download' => 'open'  // Defines who is allowed to download this file. The possible values are either open for everyone or company for the other members of the user's enterprise.
        ],
        'shared_link' => [  // Defines a shared link for a file. Set this to null to remove the shared link.
            'access' => '',  // The level of access for the shared link. This can be restricted to anyone with the link (open), only people within the company (company) and only those who have been invited to the folder (collaborators).
            'password' => '',  // The password required to access the shared link. Set the password to null to remove it. Passwords must now be at least eight characters long and include a number, upper case letter, or a non-numeric or non-alphabetic character. A password can only be set when access is set to open.
            'permissions' => [  //
                'can_download' => '',  // If the shared link allows for downloading of files. This can only be set when access is set to open or company.
                'unshared_at' => '',  // The timestamp at which this shared link will expire. This field can only be set by users with paid accounts.
                'vanity_name' => '',  // Defines a custom vanity name to use in the shared link URL, for example https://app.box.com/v/my-shared-link.
            ]
        ]
    ];
    Box::file()->whereId(fileId: '1234')->update(attributes: $attributes);
  • 删除文件:文档
    删除文件,可以是永久删除或将其移动到垃圾箱。

    use PrasadChinwal\Box\Facades\BoxFile;
    Box::file()->whereId('1234')->delete();
  • 上传文件:文档
    将小型文件上传到 Box。对于超过 50MB 的文件大小,我们建议使用分块上传 API。

    use PrasadChinwal\Box\Facades\BoxFile;
    $attributes = [
        'attributes' => json_encode(['name' => 'New_Test.pdf', 'parent' => ['id' => '4321']]),
    ];  // For full list of available options please see the docs.
    $filePath = storage_path('app/file.pdf');
    Box::file()->create(filepath: $filePath, filename: 'My_New_File.pdf',  attributes: $attributes);
  • 文件版本:文档
    检索文件的过去版本列表。

    use PrasadChinwal\Box\Facades\BoxFile;
    Box::file()->whereId('1234')->versions();
  • 获取文件水印:文档
    检索文件的水印。

    use PrasadChinwal\Box\Facades\BoxFile;
    Box::file()->whereId('1234')->getWatermark();
  • 创建文件水印:文档
    应用或更新文件上的水印。

    use PrasadChinwal\Box\Facades\BoxFile;
    Box::file()->whereId('1234')->createWatermark();
  • 删除文件水印:文档
    从文件中删除水印。

    use PrasadChinwal\Box\Facades\BoxFile;
    Box::file()->whereId('1248628118855')->removeWatermark();

文件夹 API

  • 获取文件夹信息:文档
    检索文件夹的详细信息,包括文件夹中的前 100 个条目。

    use PrasadChinwal\Box\Facades\Box;
    Box::folder()->whereId('4321')->info();
  • 获取文件夹项目
    删除文件夹,可以是永久删除或将其移动到垃圾箱。

        Box::folder()->whereId('4321')->items();
  • 创建文件夹
    在指定的父文件夹中创建一个新的空文件夹。

    use PrasadChinwal\Box\Facades\Box;
    $attributes = [
        'folder_upload_email' => [  // Setting this object enables the upload email address. This email address can be used by users to directly upload files directly to the folder via email.
            'access' => ''  // When this parameter has been set, users can email files to the email address that has been automatically created for this folder. Value is one of open,collaborators
        ],
        'name' => '',  // The name for the new folder. max length 255
        'parent' => [  // The parent folder to create the new folder within
            'id' => ''  // The ID of parent folder
        ],
        'sync_state' => ''  // Specifies whether a folder should be synced to a user's device or not. This is used by Box Sync (discontinued) and is not used by Box DriveSpecifies whether a folder should be synced to a user's device or not. This is used by Box Sync (discontinued) and is not used by Box Drive. Value is one of synced,not_synced,partially_synced
    ];
    Box::folder()->whereId('4321')->create(attributes: $attributes);
  • 更新文件夹
    更新文件夹。这也可以用来移动文件夹、创建共享链接、更新协作等。

    use PrasadChinwal\Box\Facades\Box;
    $attributes = [
        'can_non_owners_invite' => [  // Specifies if users who are not the owner of the folder can invite new collaborators to the folder.
            'can_non_owners_view_collaborators' => '',  // Restricts collaborators who are not the owner of this folder from viewing other collaborations on this folder. It also restricts non-owners from inviting new collaborators. It also restricts non-owners from inviting new collaborators.
        ],
        'collections' => [  // An array of collections to make this folder a member of. Currently we only support the favorites collection.
            'id' => '',  // The unique identifier for this object
            'type' => '', // The type for this object
        ],
        'description' => '',  // The optional description of this folder
        'folder_upload_email' => [  // Setting this object enables the upload email address. This email address can be used by users to directly upload files directly to the folder via email.
            'access' => '',  // When this parameter has been set, users can email files to the email address that has been automatically created for this folder. To create an email address, set this property either when creating or updating the folder.
        ],
        'is_collaboration_restricted_to_enterprise' => '',  // Specifies if new invites to this folder are restricted to users within the enterprise. This does not affect existing collaborations.
        'name' => '',  // The optional new name for this folder.
        'parent' => [  // The parent folder to create the new folder within
            'id' => '212346363047'  // The ID of parent folder
        ],
        'shared_link' => [  // Enables the creation of a shared link for a folder.
            'access' => '',  // The level of access for the shared link. This can be restricted to anyone with the link (open), only people within the company (company) and only those who have been invited to the folder (collaborators). If not set, this field defaults to the access level specified by the enterprise admin. To create a shared link with this default setting pass the shared_link object with no access field, for example { 'shared_link': {} }.
            'password' => '',  // The password required to access the shared link. Set the password to null to remove it. Passwords must now be at least eight characters long and include a number, upper case letter, or a non-numeric or non-alphabetic character. A password can only be set when access is set to open.
            'permissions' => [
                'can_download' => '',  // If the shared link allows for downloading of files. This can only be set when access is set to open or company.
                'unshared_at' => '',  // The timestamp at which this shared link will expire. This field can only be set by users with paid accounts.
                'vanity_name' => '',  // Defines a custom vanity name to use in the shared link URL, for example https://app.box.com/v/my-shared-link.Custom URLs should not be used when sharing sensitive content as vanity URLs are a lot easier to guess than regular shared links.
            ],
        ],
        'sync_state' => '',  // Specifies whether a folder should be synced to a user's device or not. This is used by Box Sync (discontinued) and is not used by Box Drive. Value is one of synced,not_synced,partially_synced
        'tags' => [''],  // The tags for this item. These tags are shown in the Box web app and mobile apps next to an item. To add or remove a tag, retrieve the item's current tags, modify them, and then update this field. There is a limit of 100 tags per item, and 10,000 unique tags per enterprise. 
    ];
    Box::folder()->whereId('4321')->update(attributes: $attributes);
  • 复制文件夹:文档
    在目标文件夹中创建文件夹的副本。原始文件夹不会改变。

    use PrasadChinwal\Box\Facades\Box;
    $attributes = [
        'name' => 'Test',  // The name for the new folder. max length 255
        'parent' => [  // The parent folder to create the new folder within
            'id' => '54321'  // The ID of parent folder
        ],
    ];
    Box::folder()->whereId('4321')->copy(attributes: $attributes);
  • 删除文件夹:文档
    删除文件夹,可以是永久删除或将其移动到垃圾箱。

        Box::folder()->whereId('4321')->delete(recursive: true);
  • 从共享链接中查找文件夹:文档
    返回由共享链接表示的文件夹。

    use PrasadChinwal\Box\Facades\Box;
    Box::folder()->whereLink('https://test.box.com/s/dad4dasdcddasd')->find();
  • 获取共享链接:文档
    获取文件夹上的共享链接信息。

    use PrasadChinwal\Box\Facades\Box;
    Box::folder()->whereId('4321')->getSharedLink();
  • 创建共享链接:文档 将共享链接添加到文件夹。

    use PrasadChinwal\Box\Facades\Box;
    $attributes = [
        'shared_link' => [
            'access' => 'company',
            'permissions' => [
                'can_download' => true,
            ]
        ]
    ];
    Box::folder()->whereId('4321')->createSharedLink(attributes: $attributes);
  • 获取锁:文档 获取指定文件夹的文件夹锁详细信息。您必须作为文件夹的所有者或共同所有者进行身份验证才能使用此端点。

    use PrasadChinwal\Box\Facades\Box;
    Box::folder()->whereId('4321')->getLocks();
  • 创建锁:文档 在文件夹上创建文件夹锁,防止其被移动和/或删除。

    use PrasadChinwal\Box\Facades\Box;
    $attributes = [
        'folder' => [
            'type' => '',
            'id' => '4321'
        ],
        'locked_operations' => [
            'move' => true,
            'delete' => true,
        ]
    ];
    Box::folder()->lock(attributes: $attributes);
  • 移除锁:文档 删除指定文件夹的文件夹锁。

    use PrasadChinwal\Box\Facades\Box;
    Box::folder()->unlock(lockid: '0983');

协作 API

  • 获取协作:文档 删除指定文件夹的文件夹锁。

    use PrasadChinwal\Box\Facades\Box;
    Box::whereId('45678')->get();
  • 创建协作:文档 为单个用户或单个组添加文件或文件夹的协作。

    use PrasadChinwal\Box\Facades\Box;
    $attributes = [
        'item' => [
            'type' => 'folder',
            'id' => '4321',
        ],
        'accessible_by' => [
            'type' => 'user',
            'login' => 'xyz@abc.edu'
        ],
        'role' => 'editor'
    ];
     Box::create(attributes: $attributes);
  • 更新协作:文档 更新协作。可以用来更改项目的所有者,或接受协作邀请。

    use PrasadChinwal\Box\Facades\Box;
    $attributes = [
        'can_view_path' => true,
        'status' => 'accepted',  // pending / accepted / rejected
        'role' => 'editor'  // editor / viewer / previewer / uploader / previewer / uploader / viewer / uploader / co-owner / owner
    ];
    Box::whereId('1111')->update(attributes: $attributes);
  • 删除协作:文档 删除单个协作。

    use PrasadChinwal\Box\Facades\Box;
    Box::collaboration()->whereId('1111')->delete();

用户 API

  • 获取用户:文档 获取用户

    use PrasadChinwal\Box\Facades\Box;
    Box::user()->get();
  • 获取用户:文档 获取用户

    use PrasadChinwal\Box\Facades\Box;
    Box::user()->whereId('3477983675')->memberships();