Created
August 12, 2009 05:04
-
-
Save pvalencia/166334 to your computer and use it in GitHub Desktop.
como hacer trim de una url en cakephp con tr.im
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 | |
/** | |
* Hacer tr.im de una URL en cakephp | |
*/ | |
function trim($url) { | |
// Quizás esto debiese ir en un archivo de configuración | |
$username = 'TR.IM_USERNAME'; | |
$password = 'TR.IM_PASSWORD'; | |
App::import('Core', array('Xml', 'HttpSocket')); //Esto va acá? | |
$sckt = new HttpSocket(); | |
//$query = array('url' => $url, 'sandbox' => true); // Para no usar tantos request (debug) | |
$res = $sckt->request( | |
array( | |
'method' => 'POST', | |
'uri' => array( | |
'scheme' => 'http', | |
'host' => 'api.tr.im/api/trim_url', | |
'query' => $query, | |
), | |
'auth' => array( | |
'method' => 'Basic', | |
'user' => $username, | |
'pass' => $password | |
), | |
'header' => array( | |
'User-Agent' => 'USER_AGENT' // elegir el user_agent | |
) | |
) | |
); | |
if(!$res) | |
return false; | |
$xml = new Xml($res); | |
$xml = Set::reverse($xml); // CakeMagic!!!!!!! | |
return $xml; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment