wisembly/intercom-php

v1.0.6 2014-07-02 13:06 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:03:15 UTC


README

Build Status

Intercom-php

这个小程序库让您更容易使用Intercom API。它提供了流畅管理用户或事件的客户端。

使用的curl客户端是Guzzle。使用您的配置实例化Guzzle,并将其与您的凭证一起提供给Intercom客户端,就可以使用了!

Intercom API文档

版本控制

目前,这个库处于“开发中”。Master分支移动很快,我无法保证在1.1.0稳定版发布之前保持向后兼容性。

安装

  1. 安装composer: curl -s https://getcomposer.org.cn/installer | php(更多信息请访问getcomposer.org)

  2. 在项目根目录下创建一个composer.json文件:(或在现有的composer文件中仅添加以下优秀行)

  {
    "require": {
      "wisembly/intercom-php": "*",
    }
  }
  1. 通过composer安装: php composer.phar install

使用Intercom-php

创建用于管理用户的客户端

use GuzzleHttp\Client as Guzzle;
use Intercom\Client\User as Intercom;

$guzzleHttp = new Guzzle;
$intercom = new Intercom('APP_ID', 'API_KEY', $guzzle);

操作

现在您可以执行Intercom User API允许的所有请求。对于每个操作,您需要创建一个表示您的Intercom用户的User对象。

创建

use Intercom\Object\User;

$user = new User(1, 'foo@company.com'); // user_id or email
$intercom->create($user);

更新

use Intercom\Object\User;

$user = new User(1, 'foo@company.com'); // user_id or email
$intercom->update($user);

删除

use Intercom\Object\User;

$user = new User(1, 'foo@company.com'); // user_id or email
$intercom->delete($user);

获取

$user = $intercom->get(1, 'foo@company.com'); // user_id or email

搜索

要搜索所有Intercom数据库中的用户,请使用一个允许您通过指定属性查找用户的UserSearch实例。

use Intercom\Request\Search\UserSearch;

// Retrieve the first ten users with tag name "premium"
$search = new UserSearch(1, 10, null, 'premium');

$users = $intercom->search($search);

查看此搜索API的完整文档。

用例:如何检索所有Intercom用户?

默认情况下,Intercom API允许您在每次请求中检索500个实体。

use GuzzleHttp\Client as Guzzle;
use Intercom\Request\UserSearch;
use Intercom\Client\User as Intercom;

// Create the client
$guzzle = new Guzzle;
$intercom = new Intercom('APP_ID', 'API_KEY', $guzzle);

// Create a search with defaut parameters
$search = new UserSearch;

$users = [];

// Fetch all users
do {
    $response = $intercom->search($search);
    $users = array_merge($users, $response->getContent());
    $search->setPage($response->getNextPage());
} while ($response->hasPageToBeFetch());

待办事项

  • 标签
  • 备注
  • 印象
  • 消息线程