定制 bluebillywig/bb-sapi-php-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bluebillywig/bb-sapi-php-sdk

Composer 安装命令:

composer require bluebillywig/bb-sapi-php-sdk

包简介

README 文档

README

This PHP SDK provides abstractions to interact with the Blue Billywig Server API.

Requirements

  • PHP >= 8.1

Installation

composer require bluebillywig/bb-sapi-php-sdk

Quick Start

use BlueBillywig\Sdk;

$sdk = Sdk::withRPCTokenAuthentication(
    'my-publication',
    1,                // token ID
    'shared-secret'   // shared secret
);

// List media clips
$response = $sdk->mediaclip->list();
$data = $response->getDecodedBody();
print_r($data);

Authentication

The SDK uses HOTP-based RPC token authentication. You need a token ID and shared secret from your Blue Billywig publication settings.

use BlueBillywig\Sdk;
use BlueBillywig\Authentication\RPCTokenAuthenticator;

// Recommended: use the convenience factory
$sdk = Sdk::withRPCTokenAuthentication('my-publication', $tokenId, $sharedSecret);

// Or provide a custom authenticator
$authenticator = new RPCTokenAuthenticator($tokenId, $sharedSecret);
$sdk = new Sdk('my-publication', $authenticator);

Clock synchronization: The RPC token is time-based (HOTP). Both client and server clocks must be reasonably synchronized (within the token expiration window, default 120 seconds). Significant clock drift will cause authentication failures.

Entities

All entities support standard CRUD operations where applicable:

Entity List Get Create Update Delete
$sdk->mediaclip Yes Yes Yes Yes Yes
$sdk->playlist Yes Yes Yes Yes Yes
$sdk->channel Yes Yes Yes Yes Yes
$sdk->playout Yes Yes Yes Yes Yes
$sdk->subtitle Yes Yes Yes Yes Yes
$sdk->thumbnail - - - - -

Sync and Async

Every entity method is available in both synchronous and asynchronous variants. Async methods return a GuzzleHttp\Promise\PromiseInterface.

// Synchronous
$response = $sdk->mediaclip->list();

// Asynchronous
$promise = $sdk->mediaclip->listAsync();
$response = $promise->wait();

Media Clips

// List
$response = $sdk->mediaclip->list(15, 0, 'createddate desc');

// Get (with optional language and job inclusion)
$response = $sdk->mediaclip->get(123);
$response = $sdk->mediaclip->get(123, 'en', false);

// Create
$response = $sdk->mediaclip->create(['title' => 'My Video']);

// Update
$response = $sdk->mediaclip->update(123, ['title' => 'Updated Title']);

// Delete (with optional purge)
$response = $sdk->mediaclip->delete(123);
$response = $sdk->mediaclip->delete(123, true); // purge

Playlists, Channels, Playouts, Subtitles

// All follow the same pattern
$response = $sdk->playlist->list();
$response = $sdk->playlist->get(1);
$response = $sdk->playlist->create(['title' => 'My Playlist']);
$response = $sdk->playlist->update(1, ['title' => 'Updated']);
$response = $sdk->playlist->delete(1);

File Uploads

The SDK supports single-chunk and multi-part uploads to S3 via presigned URLs.

// 1. Initialize the upload
$initResponse = $sdk->mediaclip->initializeUpload('/path/to/video.mp4');
$initResponse->assertIsOk();
$uploadData = $initResponse->getDecodedBody();

// 2. Execute the upload
$success = $sdk->mediaclip->helper->executeUpload('/path/to/video.mp4', $uploadData);

// 3. (Optional) Track upload progress
foreach ($sdk->mediaclip->helper->uploadProgressGenerator(
    $uploadData['listPartsUrl'],
    $uploadData['headObjectUrl'],
    $uploadData['chunks'],
) as $progress) {
    echo "Upload progress: {$progress}%\n";
}

Async upload using coroutines:

use GuzzleHttp\Promise\Coroutine;

$promise = Coroutine::of(function () use ($sdk, $mediaClipPath) {
    $response = (yield $sdk->mediaclip->initializeUploadAsync($mediaClipPath));
    $response->assertIsOk();

    yield $sdk->mediaclip->helper->executeUploadAsync($mediaClipPath, $response->getDecodedBody());
});
$promise->wait();

Thumbnails

// Generate an absolute thumbnail URL with dimensions
$url = $sdk->thumbnail->helper->getAbsoluteImagePath('/path/to/image.jpg', 640, 360);
// => https://my-publication.bbvms.com/image/640/360/path/to/image.jpg

Response Handling

All entity methods return a SapiResponse object:

$response = $sdk->mediaclip->get(123);

// Check status
if ($response->isOk()) {
    $data = $response->getDecodedBody();
}

// Or assert (throws on non-2xx)
$response->assertIsOk();
$data = $response->getDecodedBody();

// Access response details
$response->getStatusCode();            // e.g. 200
$response->getBody()->getContents();   // raw body string
$response->getJsonBody();              // parse as JSON
$response->getXmlBody();               // parse as XML
$response->getDecodedBody();           // try JSON first, then XML
$response->getStatusCodeCategory();    // HTTPStatusCodeCategory enum
$response->getRequest();               // the original Request object

// Batch response utilities
Response::allOk($responses);           // true if all 2xx
Response::assertAllOk($responses);     // throws on first non-2xx
Response::getFailedResponses($responses); // generator yielding non-2xx responses

Error Handling

The SDK throws typed exceptions for HTTP errors:

use BlueBillywig\Exception\HTTPRequestException;
use BlueBillywig\Exception\HTTPClientErrorRequestException;
use BlueBillywig\Exception\HTTPServerErrorRequestException;

try {
    $response = $sdk->mediaclip->get(999);
    $response->assertIsOk();
} catch (HTTPClientErrorRequestException $e) {
    // 4xx error
    echo "Client error {$e->getCode()}: {$e->getMessage()}\n";
    echo "Response body: {$e->getResponseBody()}\n";
} catch (HTTPServerErrorRequestException $e) {
    // 5xx error
    echo "Server error {$e->getCode()}: {$e->getMessage()}\n";
}

Configuration

$sdk = Sdk::withRPCTokenAuthentication('my-publication', $tokenId, $sharedSecret, [
    // Pass any Guzzle client options
    // See: https://docs.guzzlephp.org/en/stable/request-options.html
]);

Development

# Install dependencies
composer install

# Lint
composer run lint

# Run tests
composer run test:unit

# Run tests with coverage
composer run test:unit:coverage

bluebillywig/bb-sapi-php-sdk 适用场景与选型建议

bluebillywig/bb-sapi-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.14k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bluebillywig/bb-sapi-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bluebillywig/bb-sapi-php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 bluebillywig/bb-sapi-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 7
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-05