public
Last active

Sparks Example

  • Download Gist
welcome.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
class Welcome extends CI_Controller {
 
protected $user = 'github';
 
public function __construct()
{
parent::__construct();
 
$this->load->helper('url');
$this->load->spark('restclient/2.0.0');
$this->rest->initialize(array('server' => 'https://api.github.com/'));
 
$this->output->cache(60*24); // cache for a day
}
 
/**
* Shows a list of all public repositories.
*/
public function index()
{
$this->rest->option(CURLOPT_SSL_VERIFYPEER, FALSE);
$repos = $this->rest->get('users/'.$this->user.'/repos');
 
$this->load->view('home', array('repos' => $repos));
}
 
/**
* Shows the README.md for a given repository
*/
public function docs($which)
{
$this->rest->option(CURLOPT_SSL_VERIFYPEER, FALSE);
$trees = $this->rest->get('repos/'.$this->user.'/'.$which.'/git/trees/HEAD');
 
$doc_url = '';
 
foreach ($trees->tree as $info)
{
if ($info->path == 'README.md')
{
$doc_url = str_replace('https://api.github.com/', '', $info->url);
break;
}
}
 
if ( ! $doc_url)
{
show_error("No Documentation Available");
}
 
$this->rest->option(CURLOPT_SSL_VERIFYPEER, FALSE);
$readme = $this->rest->get($doc_url);
$content = base64_decode($readme->content);
 
$this->load->spark('markdown/1.2.0');
$this->load->view('docs', array('content' => $content));
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.