Skip to content
This repository was archived by the owner on Feb 10, 2023. It is now read-only.

Commit 539f115

Browse files
README updated
1 parent 5e8d68b commit 539f115

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

README.md

+76-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,78 @@
1-
link-shrink
1+
Link Shrink
22
===========
33

4-
URL shortener library
4+
**Link Shrink** is a library for abstracting interaction with url shortening services like [Bit.ly](https://bitly.com/) and [Goo.gl](https://goo.gl/).
5+
6+
### Adapters ###
7+
**Adapters** are used to make the requests to the APIs. [Ivory Http Adapter](https://github.com/egeloen/ivory-http-adapter) is used to provide a consistent interface. Any of the libraries listed there may be used depending on your needs and existing infrastructure.
8+
9+
### Providers ###
10+
11+
**Providers** are where the magic happens. Each provider contains the logic for interacting with the various APIs.
12+
Currently Bit.ly and Goo.gl are supported and a GenericResolver is provided to retrieving the final location of the link (i.e., reversing the url shortening process)
13+
14+
15+
Installation
16+
------------
17+
18+
The recommended way to install Geocoder is through [Composer](http://getcomposer.org).
19+
Create a `composer.json` file into your project:
20+
21+
``` json
22+
{
23+
"require": {
24+
"devmatt/link-shrink": "dev-master"
25+
}
26+
}
27+
```
28+
29+
30+
How-to get started
31+
------------------
32+
33+
``` php
34+
<?php
35+
require_once('./vendor/autoload.php');
36+
37+
$adapter = new \Ivory\HttpAdapter\Guzzle4HttpAdapter();
38+
$provider = new Bitly($adapter, 'YOUR-BITLY-API-KEY');
39+
$shrink = new LinkShrink($provider);
40+
41+
$shrink->shorten('https://github.com/devmatt/link-shrink'); // http://bit.ly/1vuXvCt
42+
$shrink->expand('http://bit.ly/1vuXvCt'); // https://github.com/devmatt/link-shrink
43+
```
44+
45+
If you want to load and use multiple providers
46+
47+
``` php
48+
<?php
49+
require_once('./vendor/autoload.php');
50+
51+
$adapter = new \Ivory\HttpAdapter\Guzzle4HttpAdapter();
52+
$providers = array(
53+
new \LinkShrink\Provider\Bitly($adapter, 'YOUR-BITLY-API-KEY'),
54+
new \LinkShrink\Provider\Google($adapter, 'YOUR-GOOGLE-API-KEY'), // API key not required but highly recommended
55+
new \LinkShrink\Provider\GenericResolver($adapter),
56+
);
57+
$shrink = new \LinkShrink\LinkShrink();
58+
$shrink->registerProviders($providers);
59+
60+
$shrink->switchProvider('bitly');
61+
$shrink->shorten('https://github.com/devmatt/link-shrink'); // http://bit.ly/1vuXvCt
62+
$shrink->expand('http://bit.ly/1vuXvCt'); // https://github.com/devmatt/link-shrink
63+
64+
$shrink->switchProvider('google');
65+
$shrink->shorten('https://github.com/devmatt/link-shrink'); // http://goo.gl/L3DzDn
66+
$shrink->expand('http://goo.gl/L3DzDn'); // https://github.com/devmatt/link-shrink
67+
```
68+
69+
Credits
70+
-------
71+
72+
Project structure inspired by the amazing [Geocoder](https://github.com/geocoder-php/Geocoder) library.
73+
74+
75+
License
76+
-------
77+
Link Shrink is released under MIT licence. More info can be found in the LICENCE file.
78+

0 commit comments

Comments
 (0)