Git Product home page Git Product logo

eventbrite's Introduction

Eventbrite PHP

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.

eventbrite's People

Contributors

adamquaile avatar jakebathman avatar jamiehollern avatar yuters avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

eventbrite's Issues

POST - Can't update event. What am I missing?

Sorry to ask what I'm sure should be relatively obvious...not able to post to an event.

GET works famously, and I appreciate the simplicity of the solution.

The experiment is updating the capacity of an Event.

Steps to recreate

  1. Create a private, unpublished event in Eventbrite.
  2. Get the id.
  3. Add some tickets to establish initial capacity (50).
  4. Run:
// Instantiates the Eventbrite library
$eb = EventbriteClient::setAuthToken(env('OAUTH'), true);

// Gets the Event from Eventbrite
// $eb->get('events/:id')
$event = EventbriteEvent::find('XXXXXXX', $eb);

Try to change the capacity and post.

$eb->post('event/:id/', ['event.capacity' => 40]);

Result should have capacity of 50.

I've spent the last couple of hours trying to figure it out, but can't. Having said that, Postman works like a charm; however, I cannot do it as raw JSON. Instead, I have to do it as a form post.

screen shot 2017-04-16 at 1 55 22 pm

screen shot 2017-04-16 at 1 55 49 pm

Again, I'm pretty sure I'm missing something obvious, but I cannot figure out what. Thanks again.

No composer installed

I do not have a composer installed and can not install it on my provider. Can I install the libraries anyway?

SSL certificate problem

Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message 'cURL error 60: SSL certificate problem: self signed certificate in certificate chain (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)' in C:\xampp\htdocs\eventbrite\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php:187 Stack trace: #0 C:\xampp\htdocs\eventbrite\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(150): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array) #1 C:\xampp\htdocs\eventbrite\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php(103): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #2 C:\xampp\htdocs\eventbrite\vendor\guzzlehttp\guzzle\src\Handler\CurlHandler.php(43): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory)) #3 C:\xampp\htdocs\eventbrit in C:\xampp\htdocs\eventbrite\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 187

POST - Can't update event.

Hate to be a bother...sorry the other ticket had some of my extensions in there...still think I'm missing something.

$eb = new Eventbrite('OAUTH');
$event = $eb->get('events/:id');

Return (note capacity):

{  
   "code":200,
   "headers":{  
      "Server":[  
         "nginx"
      ],
      "Date":[  
         "Sun, 16 Apr 2017 20:28:46 GMT"
      ],
      "Content-Type":[  
         "application\/json"
      ],
      "Transfer-Encoding":[  
         "chunked"
      ],
      "Connection":[  
         "keep-alive"
      ],
      "x-xss-protection":[  
         "1; mode=block"
      ],
      "x-content-type-options":[  
         "nosniff"
      ],
      "Vary":[  
         "Accept, Accept-Encoding"
      ],
      "X-Rate-Limit":[  
      ],
      "Allow":[  
         "GET, POST, DELETE, HEAD, OPTIONS"
      ],
      "X-Frame-Options":[  
         "SAMEORIGIN"
      ],
      "Access-Control-Allow-Origin":[  
         "*"
      ],
      "Access-Control-Allow-Headers":[  
         "Authorization, Content-Type"
      ],
      "P3P":[  
         "CP=\"NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM\""
      ],
      "X-UA-Compatible":[  
         "IE=edge"
      ],
      "Set-Cookie":[  
      ]
   },
   "body":{  
      "name":{  
         "text":"TESTINGAPIINTEGRATIONWITHOURSITE",
         "html":"TESTINGAPIINTEGRATIONWITHOURSITE"
      },
      "description":{  
         "text":"This is the description. Looks like it can take images. Links...And horizontal rules.",
         "html":"<P>This is the description. Looks like it can take images. Links...<\/P><HR><P><BR><\/P><P>And horizontal rules.<\/P>"
      },
      "id":":id",
      "url":"https:\/\/www.eventbrite.com\/e\/testingapiintegrationwithoursite-tickets-:id",
      "start":{  
         "timezone":"America\/New_York",
         "local":"2017-09-01T19:00:00",
         "utc":"2017-09-01T23:00:00Z"
      },
      "end":{  
         "timezone":"America\/New_York",
         "local":"2017-09-30T22:00:00",
         "utc":"2017-10-01T02:00:00Z"
      },
      "created":"2017-04-15T19:36:08Z",
      "changed":"2017-04-16T17:55:41Z",
      "capacity":40,
      "capacity_is_custom":true,
      "status":"draft",
      "currency":"USD",
      "listed":false,
      "shareable":true,
      "invite_only":false,
      "password":"Testing the API and Integration with our site.",
      "online_event":false,
      "show_remaining":true,
      "tx_time_limit":480,
      "hide_start_date":false,
      "hide_end_date":false,
      "locale":"en_US",
      "is_locked":false,
      "privacy_setting":"unlocked",
      "is_series":false,
      "is_series_parent":false,
      "is_reserved_seating":false,
      "source":"create_2.0",
      "is_free":false,
      "version":"3.0.0",
      "logo_id":null,
      "organizer_id":":id",
      "venue_id":":id",
      "category_id":null,
      "subcategory_id":null,
      "format_id":null,
      "resource_uri":"https:\/\/www.eventbriteapi.com\/v3\/events\/:id\/",
      "logo":null
   }
}
// Would expect capacity to update     
$update = $eb->post('events/:id', ['event.capacity' => 30]);

Return is the same as above. Verify by recalling.

$event2 = $eb->get('events/:id');

Return is the same as above.

Again, Postman works just fine - as long as I have it set to form-data.

Thoughts? What am I missing?

Also tried

$update = $eb->post('events/:id', [
    'event' => [
        'capacity' => 30
    ]
]);

$update = $eb->post('events/:id', [
    'body' => [
        'event' => [
            'capacity' => 30
        ]
    ]
]);

$update = $eb->patch(
    'events/:id',
    ['event.capacity' => 30]
);

$update = $eb->put(
    'events/:id',
    ['event.capacity' => 30]
);

// Error because body is array
$update = $eb->call('POST', 'events/:id', [
    'body' => [
        'event' => [
            'capacity' => 30
        ]
    ]
]);

$update = $eb->call('POST', 'events/:id', [
    'event' => [
        'capacity' => 30
    ]
]);

$update = $eb->call('POST', 'events/:id', ['event.capacity' => 30]);

$update = $eb->makeRequest('POST', 'events/:id', ['event.capacity' => 30]);

// Error because body is array
$update = $eb->makeRequest(
    'POST',
    'events/:id',
    null,
    ['event.capacity' => 30]
);

$update = $eb->makeRequest(
    'POST',
    'events/:id',
    null,
    null,
    ['event.capacity' => 30]
);

$update = $eb->makeRequest(
    'POST',
    'events/:id',
    null,
    null,
    null,
    ['event.capacity' => 30]
);

See also #7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.