Skip to content

Instantly share code, notes, and snippets.

@olivierlesnicki
Created May 11, 2012 12:48
Show Gist options
  • Save olivierlesnicki/2659413 to your computer and use it in GitHub Desktop.
Save olivierlesnicki/2659413 to your computer and use it in GitHub Desktop.
CakePHP Component to easily access YQL Console
<?php
/**
*
* YQL Component for CakePHP
* CakePHP Component to easily access "YQL Console" (http://developer.yahoo.com/yql/console/)
*
* Author : Olivier Lesnicki
* Website : https://github.com/olivierlesnicki
*
* Licensed under the MIT licenses:
* http://www.opensource.org/licenses/mit-license.php
*
* Using YQL Component for CakePHP:
* 1. Save the component in app/controller/component
* 2. Push it in your controller's $components array: public $components = array('Yql');
* 3. Use the run function like so $this->Yql->run($query);
*
* Example:
* pr($this->Yql->run('select * from yahoo.finance.stock where symbol="yhoo"'));
*
**/
App::uses('HttpSocket', 'Network/Http');
class YqlComponent extends Component
{
public function run($query = null, $params = array(
'env' => 'http://datatables.org/alltables.env',
'callback' => null,
))
{
$HttpSocket = new HttpSocket();
$result = $HttpSocket->get('http://query.yahooapis.com/v1/public/yql', array(
'q' => $query,
'diagnostics' => false,
'format' => 'json',
'env' => $params['env'],
'callback' => null
));
return json_decode($result, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment