Skip to content

Instantly share code, notes, and snippets.

@CodeBrauer
Created February 3, 2015 16:15
Show Gist options
  • Save CodeBrauer/34f5a9adc0adeb132132 to your computer and use it in GitHub Desktop.
Save CodeBrauer/34f5a9adc0adeb132132 to your computer and use it in GitHub Desktop.
Super simple gitlab library
<?php
/**
* super simple gitlab api
*/
class Gitlab
{
const API_URL = 'http://gitlab.local/';
const PRIVATE_TOKEN = 'XXXXXXXXXXXXXXXXXXX';
public static function get($method, $param = '', $json_encode = true, $show_error = false) {
if (!function_exists('curl_init')) { return file_get_contents($url); } // fallback
$ch = curl_init();
$options = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => self::API_URL . $method . '?private_token=' . self::PRIVATE_TOKEN . $param,
CURLOPT_HEADER => false,
);
curl_setopt_array($ch, $options);
$html = curl_exec($ch);
if ($html === false && $show_error) {
echo 'ERROR: ' . curl_error($ch)."\n";
}
curl_close($ch);
if ($json_encode)
return json_decode($html);
return $html;
}
}
@CodeBrauer
Copy link
Author

Usage:

// simple
$issues = Gitlab::get('issues');

// multiple pages
for ($i=0; $i < 10; $i++) { 
    $issues[] = Gitlab::get('issues', '&page='.$i.'&per_page=100');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment