Created
August 12, 2011 16:51
-
-
Save psaia/1142449 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Bitly { | |
private $login; | |
private $appkey; | |
function __construct($login, $appkey) | |
{ | |
$this->login = $login; | |
$this->appkey = $appkey; | |
} | |
function shorten($url) | |
{ | |
return $this->curl_get_result("http://api.bit.ly/v3/shorten?login={$this->login}&apiKey={$this->appkey}&uri=".urlencode($url)."&format=txt"); | |
} | |
function expand($url) | |
{ | |
return $this->curl_get_result("http://api.bit.ly/v3/expand?login={$this->login}&apiKey={$this->appkey}&shortUrl=".urlencode($url)."&format=txt"); | |
} | |
private function curl_get_result($url) | |
{ | |
$ch = curl_init(); | |
$timeout = 5; | |
curl_setopt($ch,CURLOPT_URL,$url); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); | |
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
} | |
} | |
$bitly_api = new Bitly("login", "api_key"); | |
$bitly_api->shorten('url'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment