定制 helpscout/api-laravel 二次开发

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

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

helpscout/api-laravel

Composer 安装命令:

composer require helpscout/api-laravel

包简介

Service provider and facade to integrate the Help Scout Mailbox API 2.0 with Laravel and Lumen

README 文档

README

Build Status Maintainability

This package contains a service provider and facade for use with Laravel and Lumen.

Installation

The Help Scout Service Provider can be installed via Composer by requiring the helpscout/api-laravel package in your project's composer.json.

{
    "require": {
        "helpscout/api-laravel": "~2.0"
    }
}

Then run a composer update

php composer.phar update

To use the Help Scout Service Provider, you must register the provider when bootstrapping your application.

Lumen

In Lumen find the Register Service Providers in your bootstrap/app.php and register the Help Scout Service Provider.

    $app->register(HelpScout\Laravel\HelpScoutServiceProvider::class);

Laravel

In Laravel find the providers key in your config/app.php and register the Help Scout Service Provider.

    'providers' => [
        // ...
        HelpScout\Laravel\HelpScoutServiceProvider::class,
    ]

Find the aliases key in your config/app.php and add the Help Scout facade alias.

    'aliases' => [
        // ...
        'HelpScout' => HelpScout\Laravel\HelpScoutFacade::class,
    ]

Configuration

This package offers two ways to configure your client from within the service provider. You can use the client_credentials auth type or you can use the legacy_token auth type.

Client Credentials Flow

The client_credentials auth type uses the OAuth2 grant of the same name described on the Mailbox API 2.O Authentication page.

When using this method, if the API client does not have an access_token when a request is make, it will make a pre-flight request to retrieve that token from the Mailbox 2.0 https://api.helpscout.net/v2/oauth2/token endpoint. Every subsequent request to the API after that will use the access_token retrieved in this first request. See this page for more details about the client_credentials authorization flow.

To use this grant type, set the following environment variables:

HS_AUTH_TYPE=client_credentials
HS_APP_ID=your-app-id
HS_APP_SECRET=your-app-secret

Legacy Credentials Flow

To ease the transition of legacy apps to the new API, the API client uses the transition service to exchange the legacy clientId and apiKey for an access_token.

Just as with the client_credentials flow described above, if the API client does not have an access_token when attempting an API call, it will make a pre-flight request to the transition service to exchange the legacy credentials for a valid access_token.

To use this grant type, set the following environment variables:

HS_AUTH_TYPE=legacy_credentials
HS_CLIENT_ID=your-client-id
HS_API_KEY=your-api-key

Changing credentials between requests

If you do not provide credentials when the client is created, you must provide either an access_token or valid credentials for one of the two auth types described above. You can do this with a concrete instance of the client like so:

$client = app('helpscout');
$client->useClientCredentials($appId, $appSecret);

$webhooks = $client->webhooks()->list();

To customize the configuration file, publish the package configuration using Artisan.

php artisan vendor:publish  --provider="HelpScout\Laravel\HelpScoutServiceProvider"

// or
php artisan vendor:publish  --tag="helpscout"

The settings can be found in the generated config/helpscout.php configuration file.

Usage

This service provider offers several ways to use the API Client from within your app. You can resolve the client instance from the container by using the helpscout alias, by specifying the Helpscout\Api\ApiClient class name, or you may type-hint the client in a class constructor or a method signature. If you configured the client with credentials as described above, there is no further configuration needed.

Use the full class name to get the client from the container.

$client = app(\HelpScout\Api\ApiClient::class);
$webhooks = $client->webhooks()->list();

Use the alias to get the client from the container.

$client = app('helpscout');
$webhooks = $client->webhooks()->list();

Or, type-hint the client in a constructor or method signature.

use HelpScout\Api\ApiClient;
use HelpScout\Api\Entity\PagedCollection;

class Foo
{
    private $api;
    
    public function __construct(ApiClient $api)
    {
        $this->api = $api;
    }
    
    public function getWebhooks(): PagedCollection
    {
        return $this->api->webhooks()->list();
    }
}

Additionally, you can request and resolve specific API Endpoints from the container in a similar fashion. For a list of the endpoints and their aliases, see the ApiClient::AVAILABLE_ENDPOINTS in the API client library. In the same fashion as the ApiClient class, the container will return a fully-configured endpoint that is ready for use as long as you specified the auth type and appropriate credentials in your config/helpscout.php file.

use HelpScout\Api\Webhooks\WebhooksEndpoint;
use HelpScout\Api\Entity\PagedCollection;

class Foo
{
    private $endpoint;
    
    public function __construct(WebhooksEndpoint $endpoint) 
    {
        $this->endpoint = $endpoint;
    }
    
    public function getHsWebhooks(): PagedCollection
    {
        return $this->endpoint->list();
    }
}

// usage
$foo = app(Foo::class);
$webhooks = $foo->getHsWebhooks();

// using the endpoints registered alias...
$webhookEndpoint = app('hs.webhooks');
$webhooks = $webhookEndpoint->list();

If the HelpScout facade is registered within the aliases section of the application configuration, you can also use the following technique.

$webhooks = HelpScout::webhooks()->list();

Links

helpscout/api-laravel 适用场景与选型建议

helpscout/api-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 529.68k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2018 年 12 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「support」 「help desk」 「laravel」 「helpscout」 「lumen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 helpscout/api-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 529.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 27
  • 依赖项目数: 2
  • 推荐数: 2

GitHub 信息

  • Stars: 9
  • Watchers: 27
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-19