jamiehollern/eventbrite 问题修复 & 功能扩展

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

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

jamiehollern/eventbrite

最新稳定版本:1.0.1

Composer 安装命令:

composer require jamiehollern/eventbrite

包简介

A PHP library to provide interactions with the Eventbrite API.

README 文档

README

Deprecated! This project contains bugs and is no longer actively maintained. Use at your own risk.

A lightweight PHP wrapper for the Eventbrite API v3 using Guzzle 6.

Build Status Coverage Status Scrutinizer Code Quality Total Downloads Latest Stable Version License

Requirements

  • PHP >= 5.5
  • cURL if you don't want any extra config (see the Guzzle docs)

Installation

Install via Composer command:
composer require jamiehollern/eventbrite

Install via composer.json:

{
  "require": {
    "jamiehollern/eventbrite": "1.0.1"
  }
}

Once you've done this:

  • Run composer install
  • Add the autoloader to your script require_once('vendor/autoload.php')

Authentication

This API does not deal with the OAuth authentication flow. It assumes that your app has already been authenticated and that you have an OAuth token for any accounts you're going to use. It is this OAuth token that should be passed to the class on instantiation.

You can find out more about the Eventbrite authentication process on the Eventbrite API docs. If you only have a single app to authenticate you can simply get a premade OAuth token by adding an app on your Eventbrite apps page.

Examples

Instantiating the class

Basic usage

To get started, you only need an OAuth token to pass into the Eventbrite class:

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN');

?>

You can check that everything's working okay by running:

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN');
// Returns true if you can connect.
$can_connect = $eventbrite->canConnect();

?>

Advanced options

You can take advantage of the fact that this library is a fairly light wrapper around Guzzle if you need more advanced options while connecting.

To increase the timeout limit from the default 30 seconds to 60 seconds:

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN', ['timeout' => 60]);

?>

If you don't have cURL installed, you can add a different HTTP request handler when instantiating the class. See the Guzzle docs for more information.

<?php

use jamiehollern\eventbrite\Eventbrite;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\StreamHandler;

$handler = new StreamHandler();
$stack = HandlerStack::create($handler);
$eventbrite = new Eventbrite('MY_OAUTH_TOKEN', ['handler' => $stack]);

?>

Making requests

There are three ways of making requests with the library and all of them roughly amount to the same thing, but with various levels of abstraction:

  • makeRequest
  • call
  • get/post/put/patch/delete

Each of the following examples make the same call, using Eventbrite expansions.

The makeRequest method

This method is a wrapper around the call method and differs only in the parameters it takes. It is designed to be slightly more obvious than call in that the parameters explicitly outline what to do with the method.

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN');

// Get all of the current users' ticket orders and ensure that the event 
// data and the event venue data are present in full.
$eventbrite->makeRequest('GET', 'users/me/orders/', ['expand' => 'event.venue']);

?>

The shortcut methods

The shortcut methods are simply methods named for the HTTP verbs and are identical to the makeRequest method but for the fact that the first parameter of makeRequest is the actual name of the shortcut method. The methods available are get, post, put, patch and delete.

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN');

// Get all of the current users' ticket orders and ensure that the event 
// data and the event venue data are present in full.
$events = $eventbrite->get('users/me/orders/', ['expand' => 'event.venue']);

?>

The call method

The call method is the most lightweight wrapper around the Guzzle client and takes three parameters; the HTTP verb (i.e. GET, POST etc), the endpoint and an optional array config for the request that maps directly to the Guzzle request options.

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN');

// Get all of the current users' ticket orders and ensure that the event 
// data and the event venue data are present in full.
$eventbrite->call('GET', 'users/me/orders/', ['query' => ['expand' => 'event.venue']]);

?>

Responses

Successfull requests made to the API will return an array with the following information:

  • Response code
  • Response headers
  • Response body

If the body content sent back is JSON (which is almost always will be with the Eventbrite API) then this will be decoded to a multidimensional array.

The library does this by taking a Guzzle response object and extracting the most pertinent data from it. This is useful enough for most requests but since the library is just a wrapper around Guzzle, if you wish you can request the full Guzzle response object instead by passing a false value for the parse_response parameter.

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN');

// Make a request but instruct the call to not parse the response
// and instead return the Guzzle response object.
$eventbrite->call('GET', 'users/me/orders/', ['parse_response' => false]);

?>

If you'd like the response object but also want the usual array or don't want to modify your requests, the library stores the last request for you.

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN');

// Make a request as normal.
$eventbrite->call('GET', 'users/me/orders/');
// Get the response object.
$last_response = $eventbrite->getLastResponse();

?>

If you need the parsed data again you can parse the last response. Be advised that the parseResponse method expects an object that implements the Guzzle ResponseInterface, which will always be a Guzzle response object in this case.

<?php

use jamiehollern\eventbrite\Eventbrite;

$eventbrite = new Eventbrite('MY_OAUTH_TOKEN');

// Make a request as normal.
$eventbrite->call('GET', 'users/me/orders/');
// Get the response object.
$last_response = $eventbrite->getLastResponse();
// Parse the response.
$parsed_response = $eventbrite->parseResponse($last_response);

?>

FAQ

  • My calls aren't working and don't seem to be calling the correct endpoint. What's wrong? Make sure you don't put a slash / in front of your endpoint or you'll confuse Guzzle.
  • Is there more in depth documentation available? Not yet but as I develop the library I plan to write extensive documentation.
  • What is the roadmap for this library? Initially it will serve to be a lightweight abstraction around Guzzle focused on RESTful requests to the Eventbrite API but eventually the plan is to include data objects and heavier abstraction on a per endpoint basis for users who don't want to put too much effort into using the API manually. This will allow for both beginners and advanced users to find something valuable in the library.

jamiehollern/eventbrite 适用场景与选型建议

jamiehollern/eventbrite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.02k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2016 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 27.02k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 32
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 6
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: GPL2
  • 更新时间: 2016-04-24