1<?php
2/**
3 * This file contains the Horde_Service_UrlShortener class for shortening URLs
4 * using the TinyUrl service.
5 *
6 * Copyright 2011-2017 Horde LLC (http://www.horde.org/)
7 *
8 * See the enclosed file COPYING for license information (LGPL). If you
9 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10 *
11 * @author   Michael J Rubinsky <mrubinsk@horde.org>
12 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
13 * @category Horde
14 * @package  Service_UrlShortener
15 */
16
17/**
18 * UrlShortener class for TinyUrl.
19 *
20 * @author   Michael J Rubinsky <mrubinsk@horde.org>
21 * @category Horde
22 * @package  Service_UrlShortener
23 */
24class Horde_Service_UrlShortener_TinyUrl extends Horde_Service_UrlShortener_Base
25{
26    const API_URL = 'http://tinyurl.com/api-create.php';
27
28    /**
29     *
30     * @param  string $url The URL to shorten
31     *
32     * @return string  The shortened URL
33     * @throws Horde_UrlShorten_Exception
34     */
35    public function shorten($url)
36    {
37        $u = new Horde_Url(self::API_URL);
38        $u = $u->setRaw(true)->add('url', $url);
39        try {
40            $response = $this->_http->get($u);
41        } catch (Horde_Http_Exception $e) {
42            throw new Horde_Service_UrlShortener_Exception($e);
43        }
44
45        return $response->getBody();
46    }
47
48}