1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.service.short-url">
<title>Zend_Service_ShortUrl</title>
<sect2 id="zend.service.short-url.intro">
<title>Overview</title>
<para>
URL shorteners have exploded in popularity in the last several years, in large part due
to the social nature of the web and the desire to share links.
<classname>Zend_Service_ShortUrl</classname> provides an API for accessing a number of
different URL shortener services, with the ability to both create short URLs as well as
retrieve the original URL.
</para>
<para>
Adapters provided include:
</para>
<itemizedlist>
<listitem>
<para>
<classname>Zend_Service_ShortUrl_JdemCz</classname>, which accesses the <ulink
url="http://jdem.cz/">jdem.cz</ulink> service.
</para>
</listitem>
<listitem>
<para>
<classname>Zend_Service_ShortUrl_TinyUrlCom</classname>, which accesses the <ulink
url="http://tinyurl.com">tinyurl.com</ulink> service.
</para>
</listitem>
<listitem>
<para>
<classname>Zend_Service_ShortUrl_MetamarkNet</classname>, which accesses the <ulink
url="http://metamark.net/">metamark.net</ulink> service.
</para>
</listitem>
<listitem>
<para>
<classname>Zend_Service_ShortUrl_IsGd</classname>, which accesses the <ulink
url="http://is.gd">is.gd</ulink> service.
</para>
</listitem>
<listitem>
<para>
<classname>Zend_Service_ShortUrl_BitLy</classname>, which accesses the <ulink
url="http://bitly.com">bit.ly</ulink> service.
</para>
</listitem>
</itemizedlist>
</sect2>
<sect2 id="zend.service.short-url.quick-start">
<title>Quick Start</title>
<para>
Using one of the URL shortener services is straightforward. Each URL shortener follows a
simple interface that defines two methods: <methodname>shorten()</methodname> and
<methodname>unshorten()</methodname>. Instantiate the class, and call the appropriate
method.
</para>
<programlisting language="php"><![CDATA[
$tinyurl = new Zend_Service_ShortUrl_TinyUrlCom();
// Shorten a URL:
$short = $tinyurl->shorten('http://framework.zend.com/'); // http://tinyurl.com/rxtuq
// Inflate or unshorten a short URL:
$long = $tinyurl->unshorten('http://tinyurl.com/rxtuq'); // http://framework.zend.com/
]]></programlisting>
</sect2>
<sect2 id="zend.service.short-url.methods">
<title>Available Methods</title>
<variablelist>
<varlistentry id="zend.service.short-url.methods.shorten">
<term>
<methodsynopsis>
<methodname>shorten</methodname>
<methodparam>
<funcparams>$url</funcparams>
</methodparam>
</methodsynopsis>
</term>
<listitem>
<para>
Takes the given <varname>$url</varname> and passes it to the service in
order to obtain a shortened URL.
</para>
<para>
If the provided <varname>$url</varname> is invalid, an exception will be
raised.
</para>
</listitem>
</varlistentry>
<varlistentry id="zend.service.short-url.methods.unshorten">
<term>
<methodsynopsis>
<methodname>unshorten</methodname>
<methodparam>
<funcparams>$shortenedUrl</funcparams>
</methodparam>
</methodsynopsis>
</term>
<listitem>
<para>
Takes the provided <varname>$shortenedUrl</varname> and passes it to the
service in order to obtain the original URL.
</para>
<para>
If the provided <varname>$shortenedUrl</varname> is invalid, an exception
will be raised.
</para>
</listitem>
</varlistentry>
<varlistentry id="zend.service.short-url.methods.set-http-client">
<term>
<methodsynopsis>
<methodname>setHttpClient</methodname>
<methodparam>
<funcparams>Zend_Http_Client $httpClient</funcparams>
</methodparam>
</methodsynopsis>
</term>
<listitem>
<para>
Use this method to set the HTTP client used for communicating with the
service.
</para>
</listitem>
</varlistentry>
<varlistentry id="zend.service.short-url.methods.get-http-client">
<term>
<methodsynopsis>
<methodname>getHttpClient</methodname>
<methodparam>
<funcparams></funcparams>
</methodparam>
</methodsynopsis>
</term>
<listitem>
<para>
Use this method to access the HTTP client attached to the service. By
default, this will lazy-load an instance of
<classname>Zend_Http_Client</classname> if no client is yet attached.
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
<sect2 id="zend.service.short-url.bitly">
<title>Additional Bit.ly Methods</title>
<para>
The bitly API require that authentication credentials be supplied as query arguments.
To get started, you'll need a free bitly user account and apiKey. Signup at:
<ulink url="http://http://bitly.com/a/sign_up">http://bitly.com/a/sign_up</ulink>
</para>
<para>
bitly currently also supports the OAuth 2 draft specification. You could provide a
generated OAuth access token to <classname>Zend_Service_ShortUrl_BitLy</classname>
using <methodname>setOAuthAccessToken</methodname> or as constructor argument.
</para>
<programlisting language="php"><![CDATA[
$bitly = new Zend_Service_ShortUrl_BitLy('username','apiKey');
// Shorten a URL:
$short = $bitly->shorten('http://framework.zend.com/'); // http://bit.ly/15Oe0
// Inflate or unshorten a short URL:
$long = $bitly->unshorten('http://bit.ly/15Oe0'); // http://framework.zend.com/
]]></programlisting>
<variablelist>
<varlistentry id="zend.service.short-url.bitly.setApiLogin">
<term>
<methodsynopsis>
<methodname>setApiLogin</methodname>
<methodparam>
<funcparams>$login, $apiKey</funcparams>
</methodparam>
</methodsynopsis>
</term>
<listitem>
<para>
Takes the required <varname>$login</varname> username and <varname>$apiKey</varname>
and passes it to the service.
</para>
</listitem>
</varlistentry>
<varlistentry id="zend.service.short-url.bitly.setOAuthAccessToken">
<term>
<methodsynopsis>
<methodname>setOAuthAccessToken</methodname>
<methodparam>
<funcparams>$accessToken</funcparams>
</methodparam>
</methodsynopsis>
</term>
<listitem>
<para>
Use the OAuth <varname>$accessToken</varname> for authentication
</para>
</listitem>
</varlistentry>
</variablelist>
</sect2>
</sect1>
|