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)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment