Skip to content

Instantly share code, notes, and snippets.

@ronaldbaltus
Created November 10, 2016 07:35
Show Gist options
  • Save ronaldbaltus/35acfc723c27dec8a1d6137de02fed7f to your computer and use it in GitHub Desktop.
Save ronaldbaltus/35acfc723c27dec8a1d6137de02fed7f to your computer and use it in GitHub Desktop.
Basic ClubIslive API authentication implementation and customer registration example
<?php
class ClubisliveApi
{
private $url = 'https://api.clubislive.nl/';
private $key = '';
private $testMode = false;
const METHOD_POST = 'post';
const METHOD_GET = 'get';
public function __construct($key = null, $testMode = false) {
$this->testMode = is_null($key) || $testMode;
$this->key = $key;
}
public function post($path, array $params = null) {
return $this->request(self::METHOD_POST, $path, $params);
}
public function get($path, array $params = null) {
return $this->request(self::METHOD_GET, $path, $params);
}
protected function request($method, $path, array $params = null) {
$ch = curl_init();
$url = $this->url . $path;
if ($this->testMode) {
$params['test'] = 1;
}
// CURLOPT_HTTPHEADER
switch ($method) {
case self::METHOD_POST:
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
break;
case self::METHOD_GET:
if (!empty($params)) {
$url .= '?' . http_build_query($params);
}
break;
}
// setup the defaults
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1); // return headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'x-apikey' => $this->key,
]);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);
return json_decode($body);
}
}
$apiKeyNotWorking = 'JullieApiKey';
$api = new ClubisliveApi($apiKeyNotWorking, false);
$vars = [
//'partnerCode' => ,
'partnerInfo' => 'test-pikant',
'user' => [
'username' => 'test-pikant',
'email' => 'ronald+test-pikant@ratus.nl',
'password' => 'asdgasdg',
'location' => [
'placeId' => 'ChIJNy3TOUNvxkcR6UqvGUz8yNY'
]
],
'personal' => [
'dateOfBirth' => '1985-01-01',
'gender' => 'male',
'sexualPreference' => 'straight',
]
];
$res = $api->post('customer', $vars);
var_dump($res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment