2017 © Pedro PelĂĄez
 

library url-shortener

A PHP5 library using API to shorten/expand URL

image

pixxet/url-shortener

A PHP5 library using API to shorten/expand URL

  • Tuesday, February 27, 2018
  • by pixxet
  • Repository
  • 1 Watchers
  • 0 Stars
  • 49 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 19 Forks
  • 0 Open issues
  • 8 Versions
  • 250 % Grown

The README.md

URL shortener library

This library allows you to shorten a URL, reverse is also possible., (*1)

SensioLabsInsight, (*2)

Build Status Total Downloads Latest Stable Version, (*3)

Basic Docs, (*4)

, (*5)

Installation

Only 1 step:, (*6)

Download UrlShortener using composer

Add UrlShortener in your composer.json:, (*7)

{
    "require": {
        "pixxet/url-shortener": "dev-master"
    }
}

Now tell composer to download the library by running the command:, (*8)

``` bash $ php composer.phar update pixxet/url-shortener, (*9)


Composer will install the library to your project's `vendor/pixxet` directory. <a name="bitly-api"></a> ## Bit.ly API ### Shorten ```php <?php use Pixxet\UrlShortener\Model\Link; use Pixxet\UrlShortener\Provider\Bitly\BitlyProvider; use Pixxet\UrlShortener\Provider\Bitly\OAuthClient; $link = new Link; $link->setLongUrl('http://www.google.com'); $bitlyProvider = new BitlyProvider( new OAuthClient('username', 'password'), // or new GenericAccessTokenAuthenticator('generic_access_token') array('connect_timeout' => 1, 'timeout' => 1) ); $bitlyProvider->shorten($link);

You can also use the commands provided by this library, look at the help message:, (*10)

$ bin/shortener bitly:shorten --help

Some arguments are mandatory:, (*11)

$ bin/shortener bitly:shorten username password http://www.google.com

Some options are available:, (*12)

$ bin/shortener bitly:shorten username password http://www.google.com --options='{"connect_timeout":1,"timeout":1}'

Expand

<?php

use Pixxet\UrlShortener\Model\Link;
use Pixxet\UrlShortener\Provider\Bitly\BitlyProvider;
use Pixxet\UrlShortener\Provider\Bitly\OAuthClient;

$link = new Link;
$link->setShortUrl('http://goo.gl/fbsS');

$bitlyProvider = new BitlyProvider(
    new OAuthClient('username', 'password'), // or new GenericAccessTokenAuthenticator('generic_access_token')
    array('connect_timeout' => 1, 'timeout' => 1)
);

$bitlyProvider->expand($link);
$ bin/shortener bitly:expand --help

Some arguments are mandatory:, (*13)

$ bin/shortener bitly:expand username password http://bit.ly/ze6poY

Some options are available:, (*14)

$ bin/shortener bitly:expand username password http://bit.ly/ze6poY --options='{"connect_timeout":1,"timeout":1}'

, (*15)

Google API

Shorten

<?php

use Pixxet\UrlShortener\Model\Link;
use Pixxet\UrlShortener\Provider\Google\GoogleProvider;

$link = new Link;
$link->setLongUrl('http://www.google.com');

$googleProvider = new GoogleProvider(
    'api_key',
    array('connect_timeout' => 1, 'timeout' => 1)
);

$googleProvider->shorten($link);

You can also use the commands provided by this library, look at the help message:, (*16)

$ bin/shortener google:shorten --help

Only one argument is mandatory (the long URL) but you can also provide a Google API key:, (*17)

$ bin/shortener google:shorten http://www.google.com
$ bin/shortener google:shorten http://www.google.com api_key

Some options are available:, (*18)

$ bin/shortener google:shorten http://www.google.com --options='{"connect_timeout":1,"timeout":1}'

Expand

<?php

use Pixxet\UrlShortener\Model\Link;
use Pixxet\UrlShortener\Provider\Google\GoogleProvider;

$link = new Link;
$link->setShortUrl('http://goo.gl/fbsS');

$googleProvider = new GoogleProvider(
    'api_key',
    array('connect_timeout' => 1, 'timeout' => 1)
);

$googleProvider->expand($link);
$ bin/shortener google:expand --help

Only one argument is mandatory (the short URL) but you can also provide a Google API key:, (*19)

$ bin/shortener google:expand http://goo.gl/fbsS
$ bin/shortener google:expand http://goo.gl/fbsS api_key

Some options are available:, (*20)

$ bin/shortener google:expand http://goo.gl/fbsS --options='{"connect_timeout":1,"timeout":1}'

, (*21)

Chain providers

<?php

use Pixxet\UrlShortener\Model\Link;
use Pixxet\UrlShortener\Provider\ChainProvider;

$chainProvider = new ChainProvider;
$chainProvider->addProvider($bitlyProvider);
$chainProvider->addProvider($googleProvider);
// add yours...

$link = new Link;
$link->setLongUrl('http://www.google.com');

$chainProvider->getProvider('bitly')->shorten($link);

$chainProvider->getProvider('google')->expand($link);

, (*22)

You can retrieve some links using these finders:, (*23)

<?php

use Pixxet\UrlShortener\Model\LinkManager;

$linkManager = new LinkManager($chainProvider);

$shortened = $linkManager->findOneByProviderAndShortUrl('bitly', 'http://bit.ly/ze6poY');

$expanded = $linkManager->findOneByProviderAndLongUrl('google', 'http://www.google.com');

, (*24)

Contribution

Any question or feedback? Open an issue and I will try to reply quickly., (*25)

A feature is missing here? Feel free to create a pull request to solve it!, (*26)

I hope this has been useful and has helped you. If so, share it and recommend it! :), (*27)

Credentials @mremitsme, (*28)

@pixxetde, (*29)

The Versions

27/02 2018

dev-master

9999999-dev https://github.com/pixxet/UrlShortener

A PHP5 library using API to shorten/expand URL

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rémi Marseille

api url shortener

27/02 2018

v2.1.1

2.1.1.0 https://github.com/pixxet/UrlShortener

A PHP5 library using API to shorten/expand URL

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rémi Marseille

api url shortener

29/03 2017

v2.1.0

2.1.0.0 https://github.com/mremi/UrlShortener

A PHP5 library using API to shorten/expand URL

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rémi Marseille

api url shortener

27/01 2017

v2.0.0

2.0.0.0 https://github.com/mremi/UrlShortener

A PHP5 library using API to shorten/expand URL

  Sources   Download

MIT

The Requires

 

The Development Requires

by Rémi Marseille

api url shortener

18/10 2013

v1.0.3

1.0.3.0 https://github.com/mremi/UrlShortener

A PHP5 library using API to shorten/expand URL

  Sources   Download

MIT

The Requires

 

by Rémi Marseille

api url shortener

14/08 2013

v1.0.2

1.0.2.0 https://github.com/mremi/UrlShortener

A PHP5 library using API to shorten/expand URL

  Sources   Download

MIT

The Requires

 

by Rémi Marseille

api url shortener

29/07 2013

v1.0.1

1.0.1.0 https://github.com/mremi/UrlShortener

A PHP5 library using API to shorten/expand URL

  Sources   Download

MIT

The Requires

 

by Rémi Marseille

api url shortener

21/07 2013

v1.0.0

1.0.0.0 https://github.com/mremi/UrlShortener

A PHP5 library using API to shorten/expand URL

  Sources   Download

MIT

The Requires

 

by Rémi Marseille

api url shortener