File indexing completed on 2025-01-26 05:29:54

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Service_ShortUrl
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id: $
0020  */
0021 
0022 /**
0023  * @see Zend_Service_ShortUrl_AbstractShortener
0024  */
0025 // require_once 'Zend/Service/ShortUrl/AbstractShortener.php';
0026 
0027 /**
0028  * Metamark.net API implementation
0029  *
0030  * @category   Zend
0031  * @package    Zend_Service_ShortUrl
0032  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0033  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0034  */
0035 class Zend_Service_ShortUrl_MetamarkNet extends Zend_Service_ShortUrl_AbstractShortener
0036 {
0037     /**
0038      * Base URI of the service
0039      *
0040      * @var string
0041      */
0042     protected $_baseUri = 'http://xrl.us/';
0043 
0044     protected $_apiUri = 'http://metamark.net/api/rest/simple';
0045 
0046     /**
0047      * This function shortens long url
0048      *
0049      * @param string $url URL to Shorten
0050      * @throws Zend_Service_ShortUrl_Exception When URL is not valid
0051      * @return string New URL
0052      */
0053     public function shorten($url)
0054     {
0055         $this->_validateUri($url);
0056 
0057         $this->getHttpClient()->setUri($this->_apiUri);
0058         $this->getHttpClient()->setParameterGet('long_url', $url);
0059 
0060         $response = $this->getHttpClient()->request();
0061 
0062         return $response->getBody();
0063     }
0064 
0065    /**
0066      * Reveals target for short URL
0067      *
0068      * @param string $shortenedUrl URL to reveal target of
0069      * @throws Zend_Service_ShortUrl_Exception When URL is not valid or is not shortened by this service
0070      * @return string
0071      */
0072     public function unshorten($shortenedUrl)
0073     {
0074         $this->_validateUri($shortenedUrl);
0075 
0076         $this->_verifyBaseUri($shortenedUrl);
0077 
0078         $this->getHttpClient()->setUri($this->_apiUri);
0079         $this->getHttpClient()->setParameterGet('short_url', $shortenedUrl);
0080 
0081         $response = $this->getHttpClient()->request();
0082 
0083         return $response->getBody();
0084     }
0085 }