Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Untitled #1

Open
wants to merge 1 commit into from

1 participant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2010
  1. @BlaM
This page is out of date. Refresh to see the latest.
View
1  README.textile
@@ -16,6 +16,7 @@ h3. Services
* short.ie
* TinyURL
* tr.im
+* piep.net
h3. Shortening a URL
View
3  Services/ShortURL.php
@@ -60,7 +60,8 @@
'tinyurl.com' => 'TinyURL',
'digg.com' => 'Digg',
'tr.im' => 'Trim',
- 'short.ie' => 'Shortie'
+ 'short.ie' => 'Shortie',
+ 'piep.net' => 'PiepNet'
);
/**
View
87 Services/ShortURL/PiepNet.php
@@ -0,0 +1,87 @@
+<?php
+
+/**
+ * An abstract interface for dealing with short URL services
+ *
+ * PHP version 5.2.0+
+ *
+ * LICENSE: This source file is subject to the New BSD license that is
+ * available through the world-wide-web at the following URI:
+ * http://www.opensource.org/licenses/bsd-license.php. If you did not receive
+ * a copy of the New BSD License and are unable to obtain it through the web,
+ * please send a note to license@php.net so we can mail you a copy immediately.
+ *
+ * @category Services
+ * @package Services_ShortURL
+ * @author Joe Stump <joe@joestump.net>
+ * @copyright 2009 Joe Stump <joe@joestump.net>
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @version CVS: $Id:$
+ * @link http://pear.php.net/package/Services_ShortURL
+ * @link http://github.com/joestump/services_shorturl
+ */
+
+require_once 'Services/ShortURL/Common.php';
+require_once 'Services/ShortURL/Interface.php';
+require_once 'Services/ShortURL/Exception/NotImplemented.php';
+require_once 'Services/ShortURL/Exception/CouldNotShorten.php';
+require_once 'Services/ShortURL/Exception/CouldNotExpand.php';
+
+/**
+ * Interface for creating/expanding piep.net links
+ *
+ * @category Services
+ * @package Services_ShortURL
+ * @author Dominik Deobald <dominik.deobald@interdose.com>
+ * @license http://tinyurl.com/new-bsd New BSD License
+ * @link http://pear.php.net/package/Services_ShortURL
+ * @link http://piep.net/
+ */
+class Services_ShortURL_PiepNet
+extends Services_ShortURL_Common
+implements Services_ShortURL_Interface
+{
+ /**
+ * piep.net's API URL
+ *
+ * @var string $api The location of piep.net's API
+ */
+ protected $api = 'http://api.interdose.com/api/shorturl/v1/shorten';
+ protected $defaultOptions = array(
+ 'service' => 'piep.net'
+ );
+
+ /**
+ * Shorten a link using piep.net
+ *
+ * @param string $url The URL to shorten
+ *
+ * @throws {@link Services_ShortURL_Exception_CouldNotShorten}
+ * @return string
+ */
+ public function shorten($url)
+ {
+ $myOptions = array_merge($this->defaultOptions, $this->options);
+ $url = $this->api . '?url=' . urlencode($url);
+
+ foreach (array('service', 'user', 'pass', 'apikey') as $v) {
+ if (strlen($myOptions[$v]) > 0) {
+ $url .= '&' . $v . '=' . urlencode($myOptions[$v]);
+ }
+ }
+
+ $this->req->setUrl($url);
+ $this->req->setMethod('GET');
+
+ $result = $this->req->send();
+ if ($result->getStatus() != 200) {
+ throw new Services_ShortURL_Exception_CouldNotShorten(
+ 'Non-200 code returned', $result->getStatus()
+ );
+ }
+
+ return trim($result->getBody());
+ }
+}
+
+?>
View
6 tests/Services/ShortURLTest.php
@@ -158,7 +158,8 @@ public function allServices()
array('Trim'),
array('Shortie'),
array('Bitly'),
- array('Digg')
+ array('Digg'),
+ array('PiepNet'),
);
}
@@ -175,7 +176,8 @@ public function detectServices()
array('http://is.gd/uaPi', 'Isgd'),
array('http://tr.im/jCBG', 'Trim'),
array('http://bit.ly/10qgu', 'Bitly'),
- array('http://digg.com/d1kAa1', 'Digg')
+ array('http://digg.com/d1kAa1', 'Digg'),
+ array('http://piep.net/6z68', 'PiepNet')
);
}
}
Something went wrong with that request. Please try again.