tschope/laravel-hubspot

为 Hubspot 客户端包添加 Laravel 特定的包装器

v3.0.1 2020-09-16 12:01 UTC

README

Latest Stable Version Total Downloads Build Status

这是一个对 hubspot/hubspot-php 包的包装器,并为用户提供了一个 Service Container 绑定和 facade,用于 SevenShores\Hubspot\Factory::create('api-key') 函数。

安装

  1. composer require rossjcooper/laravel-hubspot
  2. 从您的 HubSpot 账户的“集成”页面获取 HubSpot API 密钥。
  3. Laravel 5.4 或更早版本,在您的 config/app.php 文件中
    • Rossjcooper\LaravelHubSpot\HubSpotServiceProvider::class 添加到您的 providers 数组中。
    • 'HubSpot' => Rossjcooper\LaravelHubSpot\Facades\HubSpot::class 添加到您的 aliases 数组中。
  4. 运行 php artisan vendor:publish --provider="Rossjcooper\LaravelHubSpot\HubSpotServiceProvider" --tag="config" 将创建一个 config/hubspot.php 文件。
  5. 将您的 HubSpot API 密钥添加到您的 .env 文件中: HUBSPOT_API_KEY=yourApiKey

用法

您可以使用 facade 或将 HubSpot 类注入为依赖项

Facade

// Echo all contacts first and last names
$response = HubSpot::contacts()->all();
    foreach ($response->contacts as $contact) {
        echo sprintf(
            "Contact name is %s %s." . PHP_EOL,
            $contact->properties->firstname->value,
            $contact->properties->lastname->value
        );
    }

依赖注入

Route::get('/', function (Rossjcooper\LaravelHubSpot\HubSpot $hubspot) {
    $response = $hubspot->contacts()->all();
    foreach ($response->contacts as $contact) {
        echo sprintf(
            "Contact name is %s %s." . PHP_EOL,
            $contact->properties->firstname->value,
            $contact->properties->lastname->value
        );
    }
});

有关使用实际 API 的更多信息,请参阅主仓库 hubspot/hubspot-php

测试

我们使用出色的 Orchestra Testbench v4 在 Laravel 环境中运行单元测试。如果您想运行测试,请确保在您的 .env 文件中有一个 HubSpot API 密钥,并运行 ./vendor/bin/phpunit

当前的单元测试访问 HubSpot API,并期望看到 HubSpot 为其开发者账户提供的演示联系人/潜在客户。

问题

请在此处仅报告与 Laravel 方面相关的问题,主要 API 问题应在此处报告 here