Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hpatoio/bitly-api
PHP Library based on Guzzle to consume Bit.ly API
https://github.com/hpatoio/bitly-api
behat bitly guzzle php php-library
Last synced: about 14 hours ago
JSON representation
PHP Library based on Guzzle to consume Bit.ly API
- Host: GitHub
- URL: https://github.com/hpatoio/bitly-api
- Owner: hpatoio
- Created: 2013-11-08T13:57:50.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2019-12-17T10:47:07.000Z (almost 5 years ago)
- Last Synced: 2024-10-31T18:08:23.933Z (8 days ago)
- Topics: behat, bitly, guzzle, php, php-library
- Language: Gherkin
- Size: 63.5 KB
- Stars: 33
- Watchers: 3
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# BitlyApi
## This package is not maintained
Check [phplicengine/bitly](https://packagist.org/packages/phplicengine/bitly) as a possible replacement.[![Build Status](https://travis-ci.org/hpatoio/bitly-api.svg?branch=master)](https://travis-ci.org/hpatoio/bitly-api)
[![Total Downloads](https://poser.pugx.org/hpatoio/bitly-api/downloads.png)](https://packagist.org/packages/hpatoio/bitly-api)
[![Latest Stable Version](https://poser.pugx.org/hpatoio/bitly-api/v/stable.png)](https://packagist.org/packages/hpatoio/bitly-api)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/8d861d8b-3529-493d-b801-1a11a098492e/mini.png)](https://insight.sensiolabs.com/projects/8d861d8b-3529-493d-b801-1a11a098492e)PHP Library based on Guzzle to consume Bit.ly API.
The biggest advantage in using Guzzle is that you can easely attach [Guzzle plugins](http://guzzle.readthedocs.org/en/latest/plugins/plugins-overview.html) to your client. [Here](#attach-guzzle-plugin), for example,you can see how to attach the log plugin and write all your requests to a file.
An [integration](#integrations) with Symfony2 is available as well.
## Versions
* 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 bugfixThis project follow [semantic versioning](http://semver.org/).
## Installation
The recommended way to install this library is through Composer.
For information about Composer and how to install in [look here](http://getcomposer.org/doc/00-intro.md).#### New project
From the command line run
```shell
./composer create-project hpatoio/bitly-api your_prj_dir '~2.0'
```#### Existing project
Move into your project directory and run
```shell
./composer require hpatoio/bitly-api '~2.0'
```
or add to your `composer.json`
```json
{
...
"require": {
...
"hpatoio/bitly-api": "~2.0"
}
}
```
and run
```shell
./composer update
```## Usage
```php
Highvalue(array("limit" => 3));print_r($response);
```
## cURL optionsIt might be that bit.ly is unreachable and you want to set a specific timeout.
Just set the cURL timeout options in the client:```php
$my_bitly = new \Hpatoio\Bitly\Client("insert_here_your_bitly_api_access_token");
// set cURL timeout, you can specify any cURL options
$my_bitly->setConfig(array(
'curl.options' =>
array(
CURLOPT_TIMEOUT => 2,
CURLOPT_CONNECTTIMEOUT => 2
)
));$response = $my_bitly->Highvalue(array("limit" => 3));
print_r($response);
```
## Methods names
To get the method name remove "v3" from the API url and camelize the other words removing the slashes.
Examples:
* /v3/highvalue -> Highvalue
* /v3/realtime/hot_phrases -> RealtimeHot_phrases
* /v3/link/content -> LinkContent## Available methods
At the moment the library supports these APIs:- [bitly Data APIs](http://dev.bitly.com/data_apis.html)
- [Links](http://dev.bitly.com/links.html)
- [Link Metrics](dev.bitly.com/link_metrics.html)
- [User Metrics](http://dev.bitly.com/user_metrics.html)## [Behat](http://behat.org)
You need to copy Behat default configuration file and enter your ``access_token`` option there.
```bash
$ 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
```bash
$ bin/behat
```## Integrations
A Symfony2 bundle that integrate this library is available [here](https://github.com/hpatoio/BitlyBundle)## 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`
```php
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 https://bitly.com/a/oauth_apps
$my_bitly = new \Hpatoio\Bitly\Client("your_bitly_access_token");
$my_bitly->addSubscriber($logPlugin);$response = $my_bitly->Highvalue(array("limit" => 3));
print_r($response);
```Now in `/tmp/bitly_guzzle.log` you can see all your requests.