engaging-io / hubspot-manager
一个用于管理 HubSpot API 交互并具有回滚功能的 Laravel 扩展包。
v0.0.1
2024-06-06 05:43 UTC
Requires
- php: ^7.3|^8.0|^8.1|^8.2
- hubspot/api-client: ^11.1
- illuminate/support: ^8.0|^9.0|^10.0|^11.9
This package is auto-updated.
Last update: 2024-09-10 05:20:56 UTC
README
关于 HubSpot Manager
一个用于管理 HubSpot API 交互并具有回滚功能的 Laravel 扩展包。
设置
安装
composer require engaging-io/hubspot-manager
将此内容添加到您的 `.env` 文件中
HUBSPOT_API_KEY=<HubSpot Private App Access Token>
用法
<?php use EngagingIo\HubSpotManager\HubSpotManager; use HubSpot\Client\Crm\Deals\Model\SimplePublicObjectInput; $hubSpotManager = new HubSpotManager; $properties1 = [ 'property_date' => '1572480000000', 'property_radio' => 'option_1', 'property_number' => '17', 'property_string' => 'value', 'property_checkbox' => 'false', 'property_dropdown' => 'choice_b', 'property_multiple_checkboxes' => 'chocolate;strawberry' ]; $simplePublicObjectInput = new SimplePublicObjectInput([ 'properties' => $properties1, ]); try { // Call the updateDeal method on the HubSpotManager instance. // This method sends a request to the HubSpot API to update a deal with the given ID. // The second parameter, $simplePublicObjectInput, contains the new data for the deal. // The method returns an API response which contains the updated deal data or an error message. $apiResponse = $hubSpotManager->updateDeal('dealId', $simplePublicObjectInput); var_dump($apiResponse); } catch (\Exception $e) { // Rollback any changes made during the process. // This method is called when an exception occurs during the process. // It ensures that the state of the system is consistent by undoing any changes that were made. $hubSpotManager->rollback(); throw $e; }
此示例创建一个 HubSpot 公司和一个联系对象。如果在过程中发生异常,它将调用 HubSpotManager 实例上的回滚方法,并回滚对 HubSpot 对象所做的任何更改。
<?php namespace App\Http\Controllers; use EngagingIo\HubSpotManager\HubSpotManager; use HubSpot\Client\Crm\Companies\Model\AssociationSpec as CompanyAssociationSpec; use HubSpot\Client\Crm\Companies\Model\PublicAssociationsForObject as CompanyPublicAssociationsForObject; use HubSpot\Client\Crm\Companies\Model\PublicObjectId as CompanyPublicObjectId; use HubSpot\Client\Crm\Companies\Model\SimplePublicObjectInputForCreate as CompanySimplePublicObjectInputForCreate; use HubSpot\Client\Crm\Contacts\Model\AssociationSpec as ContactAssociationSpec; use HubSpot\Client\Crm\Contacts\Model\PublicAssociationsForObject as ContactPublicAssociationsForObject; use HubSpot\Client\Crm\Contacts\Model\PublicObjectId as ContactPublicObjectId; use HubSpot\Client\Crm\Contacts\Model\SimplePublicObjectInputForCreate as ContactSimplePublicObjectInputForCreate; class SampleController extends Controller { private $hubSpotManager; /** * Construct a new instance of IndexController. * * This constructor method injects a HubSpotManager instance into the controller. * The HubSpotManager instance is used to interact with the HubSpot API. * * @param HubSpotManager $hubSpotManager An instance of HubSpotManager. */ public function __construct(HubSpotManager $hubSpotManager) { $this->hubSpotManager = $hubSpotManager; } /** * Handle the incoming request. * * This method creates a HubSpot company and a contact object. * It first creates an association specification and a public object ID for the company, * then it creates a simple public object input for the company with the association and properties. * It then calls the createCompany method on the HubSpotManager instance with the simple public object input. * It repeats the same process for the contact object. * If an exception occurs during the process, it calls the rollback method on the HubSpotManager instance. * If the process is successful, it returns a JSON response with a message. * * @throws \Exception If an error occurs during the process. * @return \Illuminate\Http\JsonResponse A JSON response with a message. */ public function __invoke() { try { $associationSpec1 = new CompanyAssociationSpec([ 'association_category' => 'HUBSPOT_DEFINED', 'association_type_id' => 0 ]); $to1 = new CompanyPublicObjectId([ 'id' => 'string' ]); $publicAssociationsForObject1 = new CompanyPublicAssociationsForObject([ 'types' => [$associationSpec1], 'to' => $to1 ]); $properties1 = [ 'additionalProp1' => 'string', 'additionalProp2' => 'string', 'additionalProp3' => 'string' ]; $simplePublicObjectInputForCreate = new CompanySimplePublicObjectInputForCreate([ 'associations' => [$publicAssociationsForObject1], 'properties' => $properties1, ]); // Create a HubSpot company object $this->hubSpotManager->createCompany($simplePublicObjectInputForCreate); $associationSpec1 = new ContactAssociationSpec([ 'association_category' => 'HUBSPOT_DEFINED', 'association_type_id' => 0 ]); $to1 = new ContactPublicObjectId([ 'id' => 'string' ]); $publicAssociationsForObject1 = new ContactPublicAssociationsForObject([ 'types' => [$associationSpec1], 'to' => $to1 ]); $properties1 = [ 'additionalProp1' => 'string', 'additionalProp2' => 'string', 'additionalProp3' => 'string' ]; $simplePublicObjectInputForCreate = new ContactSimplePublicObjectInputForCreate([ 'associations' => [$publicAssociationsForObject1], 'properties' => $properties1, ]); // Create a HubSpot contact object $this->hubSpotManager->createContact($simplePublicObjectInputForCreate); return response()->json('Hello World!', 200); } catch (\Exception $e) { // Rollback any changes made to HubSpot objects $this->hubSpotManager->rollback(); throw $e; } } }
安全漏洞
如果您在 Laravel 中发现安全漏洞,请通过 danniel@engaging.io 发送电子邮件给 Danniel Libor。所有安全漏洞都将得到及时处理。
许可证
HubSpot Manager 是开源软件,受 MIT 许可证 许可。
待办事项
- 自定义对象
- 批量公司
- 批量联系
- 批量交易
- 批量自定义对象
- 任务
- 批量任务
- 笔记
- 批量笔记
- 关联
- 批量关联
- 更好的文档
- 等等。