Skip to content

Instantly share code, notes, and snippets.

@pvalencia
Created August 12, 2009 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvalencia/166334 to your computer and use it in GitHub Desktop.
Save pvalencia/166334 to your computer and use it in GitHub Desktop.
como hacer trim de una url en cakephp con tr.im
<?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