sw/pardot 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

sw/pardot

Composer 安装命令:

composer require sw/pardot

包简介

A Pardot-API-Wrapper for PHP.

README 文档

README

This is a fork of Henning Glatter-Götz' Pardot-API-Wrapper containing minor changes, for instance to allow the bulk-output-format.

Pardot

Pardot is an API connector for the Pardot API implemented in PHP. It facilitates access to all the API endpoints that Pardot exposes. This can be used to build a custom CRM connector.

Goals

  • Provide a single method for executing any operation on any of the Pardot endpoints
  • Parse the response and return only the data (PHP array from decoded JSON or a SimpleXmlElement)
  • Take care of error handling

NOTE The XML format is not fully supported by this library. I do not use XML and do not have time to keep the XML parser up to date.

Dependencies

Conventions

The Pardot API should be accessed via POST for all operations (recommended by Pardot). For the most part the API does not use the standard HTTP response codes to convey the outcome of the request, rather it always returns 2** response codes and sends back its own set of status codes that need to be handled. This connector captures the status codes and messages and throws exceptions that contain this information. If it should be necessary to handle the individual cases this is possible by catching the exception and extracting the error code from it.

All exceptions emitted by the library implement the ExceptionInterface. Any exceptions raised in the HTTP layer are wrapped into a RequestException.

See Error Handling for more details.

Usage

Instantiating the Connector

The first argument to the constructor is an associative array containing the initialization parameters for the connector.

Required

  • email - The email address of the user account
  • user-key - The user key of the user account
  • password - The account password

Optional

  • format - The content format. Pardot supports json and xml. Default json
  • output - The level of detail that is returned. Possible values are full, simple, mobile. Default full
  • api-key - If the API key is being cached it can be injected into the constructor. Default null

The second parameter is optional and is an instance of the Guzzle\Http\Client. By default the Guzzle\Http\Client is instantiated with the exponential backoff plugin. It is configured for 5 retries (after 2, 4, 8, 16 and 32 seconds). If these settings are not desirable an instance of the client can be injected into the constructor with whatever settings/plugins are needed.

The third parameter is optional and is an array of options for the Guzzle Client post method. Default is array('timeout' => 10), which sets the timeout for the client to 10 seconds.

<?php

use HGG\Pardot\Connector;
use HGG\Pardot\Exception\PardotException;

$connectorParameters = array(
    'email'    => 'The email address of the user account',
    'user-key' => 'The user key of the user account (in My Settings)',
    'password' => 'The account password',
    'format'   => 'json',
    'output'   => 'full'
);

$connector = new Connector($connectorParameters);

Create a prospect

The minimally required set of parameters/fields for creating a prospect is the email address of the prospect. This will create a prospect and return the full prospect record as a PHP array because the connector was instantiated with format = json and output = full. If the format is set to xml the method will return a SimpleXmlElement instance.

<?php

$response = $connector->post('prospect', 'create', array('email' => 'some@example.com'));

prospect is the object that will be accessed and create is the operation performed on that object. The third parameter is an associative array of fields to be set.

The $response will be an array representing the record (keys being the field names and the values being the values of those fields)

Read a prospect

Using the email address as the identifier

<?php

$response = $connector->post('prospect', 'read', array('email' => 'some@example.com'));

Using the Pardot ID as the identifier

<?php

$response = $connector->post('prospect', 'read', array('id' => '12345'));

The $response will be an array representing the record (keys being the field names and the values being the values of those fields)

Query prospects

<?php

$queryParameters = array(
    'created_after' => 'yesterday',
    'limit'         => 200,
    'offset'        => 0
);

$response = $connector->post('prospect', 'query', $queryParameters);

// Obtain the total record count of the query from the connector
// If this is larger than the limit make requests (increasing the offset each
// time) until all records have been fetched
$count = $connector->getResultCount();

If the query result spans more than 200 records and the limit for a request is set to 200 then multiple requests will have to be made to fetch the entire result set. The limit defaults to 200 and cannot be larger. Each request that is part of a single query will return a collection/array of records, even if the collection only contains a single record. Note that the Pardot API does not natively do this.

Error Handling

All library exceptions implement the common ExceptionInterface interface.

Exception Hierarchy

All library exceptions extend the common SPL exceptions.

\Exception
  |
  |- ExceptionCollection
  |
  |- \LogicException
  |    |- \InvalidArgumentExcpetion
  |         |- InvalidArgumentExcpetion
  |
  |- \RuntimeException
       |- RuntimeException
           |- AuthenticationErrorException
           |- RequestException

The following exceptions are thrown:

AuthenticationErrorException

When authentication against the Pardot API fails.

ExceptionCollection

When the Pardot API returns error code 10000 that can contain multiple errors.

InvalidArgumentException

Type errors such as passing an invalid Connector construction parameters.

RequestException

Exceptions emitted by the HTTP layer (GuzzlePHP' HTTPException) are wraped in a RequestExcpetion.

RuntimeException

All non HTTPExceptions from Guzzle and non authentication errors returned by the Pardot API.

Examples

Catch any HGG\Pardot library exception

If no specific error handling is required or needed just use this as a catch-all.

<?php

use HGG\Pardot\Exception\ExceptionInterface;

try {
    // Pardot library code
} catch (ExceptionInterface $e) {
    // Handle it here
}

Get useful logging information

All library exceptions allow you to get at the URL that was called as well as the parameters that were sent. This can be helpful for identifying issues.

<?php

use HGG\Pardot\Exception\RuntimeException;

try {
    $connector->post('prospect', 'update', $parameters);
} catch (RuntimeException $e) {
    printf('Error Message: %s', $e->getMessage());
    printf('Error code:    %d', $e->getCode()); // Pardot Error code
    printf('url:           %s', $e->getUrl());
    printf("Parameters:\n%s", print_r($e->getParameters(), true));
}

sw/pardot 适用场景与选型建议

sw/pardot 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 38 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 sw/pardot 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 15
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-27