sonrisa / shorturl-service
Standalone library that allows URL shortening using online services such as Google or Bit.ly. Expanding shortened URLs is also possible.
Installs: 17 489
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2018-01-08 08:12:10 UTC
README
This library allows you to shorten a URL using online services such as Google or Bit.ly. Expanding shortened URLs is also possible.
1.Installation
Add the following to your composer.json
file :
{ "require": { "sonrisa/shorturl-service":"dev-master" } }
2. Description
Currently supports the 2 major services:
- Google URL Shortener (goo.gl/XXXXX)
- Bitly.com: (bit.ly/XXXXX, j.mp/XXXXX)
3. Supported Services
3.1. Google API
Get an API key at https://developers.google.com/url-shortener/v1/getting_started#APIKey.
<?php //Create the short url. Optionally pass the $apiKey credentials $googl = new \Sonrisa\Service\ShortLink\Google($apiKey); echo $url = $googl->shorten($longUrl); //Expand a short URL into the original URL. Optionally pass the $apiKey credentials $googl = new \Sonrisa\Service\ShortLink\Google($apiKey); echo $url = $googl->expand($shortUrl); //Get all data, including statistics for a shortened URL $googl = new \Sonrisa\Service\ShortLink\Google($apiKey); $array = $googl->stats($shortUrl);
3.2. Bit.ly API
Get an API Key at https://bitly.com/a/oauth_apps.
<?php //Create the short url. $bitly = new \Sonrisa\Service\ShortLink\Bitly($user,$pass); echo $url = $bitly->shorten($longUrl); //Expand a short URL into the original URL. $bitly = new \Sonrisa\Service\ShortLink\Bitly($user,$pass); echo $url = $bitly->expand($shortUrl);
Bit.ly implements many analytic features not taken into account in this library. All extra features can be found in the API documentation.
4. Fully tested.
Testing has been done using PHPUnit and Travis-CI. All code has been tested to be compatible from PHP 5.3 up to PHP 5.5 and Facebook's PHP Virtual Machine: HipHop.
5. Author
Nil Portugués Calderó