Created
February 3, 2015 16:15
-
-
Save CodeBrauer/34f5a9adc0adeb132132 to your computer and use it in GitHub Desktop.
Super simple gitlab library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: