|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Service_ShortUrl |
|
17 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
19 * @version $Id: $ |
|
20 */ |
|
21 |
|
22 /** |
|
23 * @see Zend_Service_ShortUrl_AbstractShortener |
|
24 */ |
|
25 require_once 'Zend/Service/ShortUrl/AbstractShortener.php'; |
|
26 |
|
27 /** |
|
28 * Metamark.net API implementation |
|
29 * |
|
30 * @category Zend |
|
31 * @package Zend_Service_ShortUrl |
|
32 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
33 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
34 */ |
|
35 class Zend_Service_ShortUrl_MetamarkNet extends Zend_Service_ShortUrl_AbstractShortener |
|
36 { |
|
37 /** |
|
38 * Base URI of the service |
|
39 * |
|
40 * @var string |
|
41 */ |
|
42 protected $_baseUri = 'http://xrl.us/'; |
|
43 |
|
44 protected $_apiUri = 'http://metamark.net/api/rest/simple'; |
|
45 |
|
46 /** |
|
47 * This function shortens long url |
|
48 * |
|
49 * @param string $url URL to Shorten |
|
50 * @throws Zend_Service_ShortUrl_Exception When URL is not valid |
|
51 * @return string New URL |
|
52 */ |
|
53 public function shorten($url) |
|
54 { |
|
55 $this->_validateUri($url); |
|
56 |
|
57 $this->getHttpClient()->setUri($this->_apiUri); |
|
58 $this->getHttpClient()->setParameterGet('long_url', $url); |
|
59 |
|
60 $response = $this->getHttpClient()->request(); |
|
61 |
|
62 return $response->getBody(); |
|
63 } |
|
64 |
|
65 /** |
|
66 * Reveals target for short URL |
|
67 * |
|
68 * @param string $shortenedUrl URL to reveal target of |
|
69 * @throws Zend_Service_ShortUrl_Exception When URL is not valid or is not shortened by this service |
|
70 * @return string |
|
71 */ |
|
72 public function unshorten($shortenedUrl) |
|
73 { |
|
74 $this->_validateUri($shortenedUrl); |
|
75 |
|
76 $this->_verifyBaseUri($shortenedUrl); |
|
77 |
|
78 $this->getHttpClient()->setUri($this->_apiUri); |
|
79 $this->getHttpClient()->setParameterGet('short_url', $shortenedUrl); |
|
80 |
|
81 $response = $this->getHttpClient()->request(); |
|
82 |
|
83 return $response->getBody(); |
|
84 } |
|
85 } |