eolica / laravel-hubspot
Laravel 对 Hubspot PHP 客户端包的封装
Requires
- php: >=8.0
- graham-campbell/manager: ^5.1
- hubspot/hubspot-php: ^5.2
- illuminate/contracts: ^10.0 || ^11.0
- illuminate/support: ^10.0 || ^11.0
Requires (Dev)
- orchestra/testbench: ^8.0 || ^9.0
- phpunit/phpunit: ^10.0 || ^11.0
README
这里应该放置您的描述。尽量限制为一到两段话,并提及您支持哪些 PSRs,以避免用户和贡献者产生混淆。
安装
您可以通过 Composer 安装此包
composer require eolica/laravel-hubspot
安装后,如果您没有使用自动 包发现,那么您需要在您的 config/app.php
中注册 Eolica\LaravelHubspot\HubspotServiceProvider
服务提供者。
'providers' => [ ... /* * Package Service Providers... */ Eolica\LaravelHubspot\HubspotServiceProvider::class, ... ],
您还可以选择性地为我们的外观设置别名
'aliases' => [ ... 'Hubspot' => Eolica\LaravelHubspot\Facades\Hubspot::class, ],
配置
此包使用了由 Graham Campbell 提供的 Laravel Manager Package,这使得我们能够在同一应用程序中配置和使用多个 HubSpot API 连接。
要开始使用,您需要发布 hubspot 配置文件
php artisan vendor:publish --provider="Eolica\LaravelHubspot\HubspotServiceProvider" --tag="config"
这将在您的应用程序中创建一个 config/hubspot.php
文件,您可以根据需要修改该文件以设置配置。
这是配置文件的示例
return [ 'default' => 'main', 'connections' => [ 'main' => [ 'config' => [ 'key' => '', ], 'retry_middleware' => [ 'rate_limit' => 'constant:5', 'internal_errors' => 'exponential:2' ], 'client_options' => [ 'http_errors' => true, ], 'wrap_response' => true, ], 'alternative' => [ 'config' => [ 'key' => '', 'oauth' => true, ], 'retry_middleware' => [ 'rate_limit' => 'linear', ], 'client_options' => [ 'http_errors' => true, ], 'wrap_response' => true, ], ], ];
默认连接名称
此选项('default'
)是指定您希望将以下哪个连接用作所有工作的默认连接的位置。当然,您可以使用管理类同时使用多个连接。此设置的默认值为 'main'
。
HubSpot 连接
此选项('connections'
)是为您的应用程序设置的每个连接的位置。您可以添加任意数量的连接。
使用方法
HubspotManager
这是最有兴趣的类。它绑定到 ioc 容器中的 'hubspot'
,并可以使用 Facades\Hubspot
外观访问。此类通过扩展 AbstractManager 实现 ManagerInterface。接口和抽象类都是 Laravel Manager 包的一部分,因此您可能想查看该存储库中的文档,了解如何使用管理类。
Facades\Hubspot
此外观将静态方法调用动态地传递到 ioc 容器中的 'hubspot'
对象,默认情况下是 HubspotManager 类。
HubspotServiceProvider
此类应添加到 config/app.php
中的 providers 数组。此类将设置 ioc 绑定。
示例
use Eolica\LaravelHubspot\Facades\Hubspot; Hubspot::contacts()->getByEmail("test@hubspot.com"); Hubspot::contacts()->all([ 'count' => 10, 'property' => ['firstname', 'lastname'], 'vidOffset' => 123456, ]);
Hubspot 管理器将表现得像 \SevenShores\Hubspot\Factory
类。如果您想调用特定的连接,可以使用 connection
方法完成
use Eolica\LaravelHubspot\Facades\Hubspot; Hubspot::connection('alternative')->contacts()->getByEmail("test@hubspot.com"); Hubspot::connection('alternative')->contacts()->all([ 'count' => 10, 'property' => ['firstname', 'lastname'], 'vidOffset' => 123456, ]);
use Eolica\LaravelHubspot\Facades\Hubspot; // Writing this: Hubspot::connection('main')->contacts()->getByEmail("test@hubspot.com"); // Is identical to writing this: Hubspot::contacts()->getByEmail("test@hubspot.com"); // And is also identical to writing this: Hubspot::connection()->contacts()->getByEmail("test@hubspot.com"); // This is because the 'main' connection is configured to be the default Hubspot::getDefaultConnection(); // This will return 'main' // We can change the default connection Hubspot::setDefaultConnection('alternative'); // The default is now 'alternative'
如果您更喜欢使用依赖注入而不是外观,则可以轻松地以这种方式注入管理器
use Illuminate\Support\Facades\App; use Eolica\LaravelHubspot\HubspotManager; final class Example { private $hubspot; public function __construct(HubspotManager $hubspot) { $this->hubspot = $hubspot; } public function method() { $this->hubspot->contacts()->getByEmail("test@hubspot.com"); $this->hubspot->connection('alternative')->contacts()->getByEmail("test@hubspot.com"); } } App::make(Example::class)->method();
有关如何使用我们在此处后台调用的 \SevenShores\Hubspot\Factory
类的更多信息,请参阅 https://github.com/HubSpot/hubspot-php 上的文档,以及 https://github.com/GrahamCampbell/Laravel-Manager#usage 上的管理器类。
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
安全性
如果您在此软件包中发现安全漏洞,请发送电子邮件至 dllobellmoya@gmail.com,而不是使用问题跟踪器。
许可证
MIT许可证(MIT)。有关更多信息,请参阅 许可证文件。
Laravel软件包模板
此软件包是使用 Laravel软件包模板 生成的。