tychovbh / laravel-bluebillywig
为 Laravel 5 定制的 BlueBillyWig 桥接器
Requires
- php: ^7.1.3
- ext-json: *
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- illuminate/contracts: ~5.6.0|~5.7.0|~5.8.0|~5.9.0
- illuminate/support: ~5.6.0|~5.7.0|~5.8.0|~5.9.0
- orchestra/testbench: ^3.7
- phpunit/phpunit: ^7
- squizlabs/php_codesniffer: ^2.3
- vlucas/phpdotenv: ^2.5
README
Laravel Blue Billywig 由 Tycho 创建并维护,是一个连接 Blue Billywig API 的 Laravel/Lumen 包。您可以自由查看变更日志、发行版、许可协议和贡献指南。
安装
Laravel Blue Billywig 需要 PHP 7.1 或 7.2。这个版本仅支持 Laravel 5.5 - 5.7 和 Lumen。
要获取最新版本,只需使用 Composer 需求项目。
$ composer require tychovbh/laravel-bluebillywig
安装完成后,如果您没有使用自动包发现,那么您需要在您的 config/app.php
中注册 Tychovbh\Bluebillywig\BluebillywigServiceProvider
服务提供者。
在 Lumen 中,您需要在 bootstrap/app.php
中添加 Service Provider。
$app->register(\Tychovbh\Bluebillywig\BluebillywigServiceProvider::class);
配置
Laravel Blue Billywig 需要 publication 配置。
要开始,您需要发布所有供应商资产
$ php artisan vendor:publish --tag=laravel-bluebillywig
这将创建一个 config/bluebillywig.php
文件在您的应用程序中,您可以根据需要进行修改以设置配置。同时,请确保检查此包中原始配置文件在发布之间的更改。
在 Lumen 中,由于 vendor:publish
不可用,您必须手动创建配置文件。创建 config/bluebillywig.php
文件,并复制粘贴示例文件。
有两个配置选项
默认发布名称
此选项('default'
)用于指定以下哪个发布您希望用作所有工作的默认发布。当然,您可以使用 $bluebillywig->publication('my_publication')
方法同时使用多个连接。此设置的默认值为 'public'
。
Bluebillywig 发布
此选项('publications'
)用于为应用程序设置每个发布。已包含示例配置,但您可以根据需要添加尽可能多的发布。
使用方法
Bluebillywig
这是最感兴趣的类。这将向 Blue Billywig API 发送经过身份验证的请求。请参阅他们的文档以获取所有可用的端点。
真实示例
实例化 Bluebillywig 类
use Tychovbh\Bluebillywig\Bluebillywig; // Use class injection Route::get('/bluebillywig', function(Bluebillywig $bluebillywig) { $response = $bluebillywig->retrieve('/sapi/publication') return response()->json($response) }); // Or use Laravel helper app() Route::get('/bluebillywig', function() { $bluebillywig = app('bluebillywig'); $response = $bluebillywig->retrieve('/sapi/publication') return response()->json($response) });
可用的 Bluebillywig 方法
// The examples below use the default publication. $response = $bluebillywig->retrieve('/sapi/mediaclip') $response = $bluebillywig->retrieve('/sapi/mediaclip/' . $id) $response = $bluebillywig->create('/sapi/mediaclip', $formData) $response = $bluebillywig->update('/sapi/mediaclip/{id}', $id, $formData) $response = $bluebillywig->delete('/sapi/mediaclip', $id) // in this example we request data from my_publication. // my_publication key should be added to publications in the confiugration file. $response = $bluebillywig->publication('my_publication')->retrieve('/sapi/playlist') // You can use other API endpoints like /json/mediaclip: $response = $bluebillywig>retrieve('/json/mediaclip')
您可以在某些请求中发送参数
// Request with GET parameter 'limit=10' $response = $bluebillywig->retrieve('/sapi/mediaclip', [ 'limit' => 10 ]) // Create resource $response = $bluebillywig->create('/sapi/mediaclip', [ 'title' => 'my fantastic new title', ]) // Update resource $response = $bluebillywig->update('/sapi/mediaclip/{id}', $id, [ 'title' => 'my fantastic new title', ])
您需要自行处理 Bluebillywig 的异常
use Tychovbh\Bluebillywig\Exceptions\ConfigurationException; try { $bluebillywig = app('bluebillywig'); $bluebillywig->retrieve('/sapi/mediaclip') } catch(\ConfigurationException $exception) { echo $exception->getMessage(); } catch(\GuzzleException $exception) { echo $exception->getMessage(); } catch(\Exception $exception) { echo $exception->getMessage(); }
变更日志
请参阅CHANGELOG 了解最近更改的详细信息。
测试
为了测试 tests/feature/*
,将 tests/.env.example
复制到 tests/.env
,并填写您的 Blue Billywig 测试账户凭据。
$ composer test
贡献
请参阅CONTRIBUTING 了解详细信息。
安全性
如果您发现任何安全问题,请通过电子邮件info@bespokeweb.nl报告,而不是使用问题跟踪器。
致谢
许可协议
MIT许可证(MIT)。请参阅许可文件获取更多信息。