PHP Library based on Guzzle to consume API
Cucumber PHP
Latest commit a868e81 Jan 18, 2017 @hpatoio committed on GitHub Merge pull request #17 from eroncanc/master
Fixed errors in service description and removed deprecated operation


Build Status Total Downloads Latest Stable Version SensioLabsInsight

PHP Library based on Guzzle to consume API.

The biggest advantage in using Guzzle is that you can easely attach Guzzle plugins to your client. Here, for example,you can see how to attach the log plugin and write all your requests to a file.

An integration with Symfony2 is available as well.


  • branch master follows psr4 standards and get 2.x tags
  • branch psr0 follows, of course, psr0 standards and get 1.x tags - No new features only bugfix

This project follow semantic versioning.


The recommended way to install this library is through Composer. For information about Composer and how to install in look here.

New project

From the command line run

./composer create-project hpatoio/bitly-api your_prj_dir '~2.0'

Existing project

Move into your project directory and run

./composer require hpatoio/bitly-api '~2.0'

or add to your composer.json

    "require": {
        "hpatoio/bitly-api": "~2.0"

and run

./composer update



// This file is generated by Composer
require_once 'vendor/autoload.php';

# To find your bitly access token see here
$my_bitly = new \Hpatoio\Bitly\Client("insert_here_your_bitly_api_access_token");

$response = $my_bitly->Highvalue(array("limit" => 3));


cURL options

It might be that is unreachable and you want to set a specific timeout. Just set the cURL timeout options in the client:

$my_bitly = new \Hpatoio\Bitly\Client("insert_here_your_bitly_api_access_token");
// set cURL timeout, you can specify any cURL options
    'curl.options' => 
            CURLOPT_TIMEOUT => 2, 

$response = $my_bitly->Highvalue(array("limit" => 3));


Methods names

To get the method name remove "v3" from the API url and camelize the other words removing the slashes.


  • /v3/highvalue -> Highvalue
  • /v3/realtime/hot_phrases -> RealtimeHot_phrases
  • /v3/link/content -> LinkContent

Available methods

At the moment the library supports these APIs:


You need to copy Behat default configuration file and enter your access_token option there.

$ cp behat.yml.dist behat.yml

Now open behat.yml and change the string your_bitly_access_token_here with your access token. Run the suite typing

$ bin/behat


A Symfony2 bundle that integrate this library is available here

Attach Guzzle plugin

Here you can see how to attach Guzzle Log plug to your client and save all your requests to a file.

NB: To run this script you need monolog/monolog

// This file is generated by Composer
require_once 'vendor/autoload.php';

use Guzzle\Log\MessageFormatter;
use Guzzle\Log\MonologLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$logger = new Logger('client');
$logger->pushHandler(new StreamHandler('/tmp/bitly_guzzle.log'));
$adapter = new MonologLogAdapter($logger);
$logPlugin = new LogPlugin($adapter, MessageFormatter::DEBUG_FORMAT);

# To find your bitly access token see here
$my_bitly = new \Hpatoio\Bitly\Client("your_bitly_access_token");

$response = $my_bitly->Highvalue(array("limit" => 3));


Now in /tmp/bitly_guzzle.log you can see all your requests.