Skip to content

Instantly share code, notes, and snippets.

@trcio
Last active January 31, 2017 12:02
Show Gist options
  • Save trcio/aa7127ccf3072989f28a526bfd3a89da to your computer and use it in GitHub Desktop.
Save trcio/aa7127ccf3072989f28a526bfd3a89da to your computer and use it in GitHub Desktop.
Scroll all the way down for an example - A wrapper for Netseal's new v2 API - http://seal.nimoru.com/docs/index.php
<?php
// Created by Positron Software
// Wraps all endpoints described at http://seal.nimoru.com/docs/index.php
// Last updated 11/23/2016
class NetsealProvider
{
const ENDPOINT = 'http://seal.nimoru.com/Remote2/';
public $token;
private function curl($endpoint, $data)
{
$curl = curl_init($endpoint);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 8000);
curl_setopt($curl, CURLOPT_MAXREDIRS, 4);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
private function callRemoteFunction($name, $data)
{
$data['token'] = $this->token;
$response = $this->curl(self::ENDPOINT . $name . '.php', $data);
if ($response === false) {
return false;
}
$json = json_decode($response, true);
if ($json === null) {
return false;
}
return $json;
}
// http://seal.nimoru.com/docs/user.php
public function getUserDetails($username)
{
$data = [
'act' => 'details',
'user' => $username
];
return $this->callRemoteFunction('user', $data);
}
public function banUser($username, $reason)
{
$data = [
'act' => 'ban',
'user' => $username,
'reason' => $reason
];
return $this->callRemoteFunction('user', $data);
}
public function pardonUser($username)
{
$data = [
'act' => 'unban',
'user' => $username
];
return $this->callRemoteFunction('user', $data);
}
public function unlockUser($username)
{
$data = [
'act' => 'unlock',
'user' => $username
];
return $this->callRemoteFunction('user', $data);
}
// http://seal.nimoru.com/docs/code.php
public function createCode($quantity, $time, $points, $type, $tracking)
{
$data = [
'act' => 'create',
'quantity' => $quantity,
'time' => $time,
'points' => $points,
'type' => $type,
'track' => $tracking
];
return $this->callRemoteFunction('code', $data);
}
public function deleteCode($code)
{
$data = [
'act' => 'delete',
'code' => $code
];
return $this->callRemoteFunction('code', $data);
}
public function checkCode($code)
{
$data = [
'act' => 'check',
'code' => $code
];
return $this->callRemoteFunction('code', $data);
}
// http://seal.nimoru.com/docs/global.php
public function createSetting($name, $value)
{
$data = [
'act' => 'create',
'name' => $name,
'value' => $value
];
return $this->callRemoteFunction('global', $data);
}
public function deleteSetting($name)
{
$data = [
'act' => 'delete',
'name' => $name
];
return $this->callRemoteFunction('global', $data);
}
public function getPrivateKey($public)
{
$data = [
'act' => 'key',
'pub' => $public
];
return $this->callRemoteFunction('global', $data);
}
public function unlockAll()
{
$data = [
'act' => 'unlock'
];
return $this->callRemoteFunction('global', $data);
}
}
<?php
require 'NetsealProvider.php';
$netseal = new NetsealProvider();
// Your remote token can be found in the 'REMOTE' tab in the License Panel
$netseal->token = '####################';
// All methods return an associative array
$response = $netseal->checkCode('PPPP-PPPP-PPPP-PPPP');
// $response is now populated with
// [
// 'data' => [
// 'user' => 'testusername',
// 'code' => 'PPPP-PPPP-PPPP-PPPP'
// ],
// 'success' => true,
// 'error' => ''
// ]
// If the request failed to be sent/processed, $response === false
// true on success, false on failure
if ($response['success']) {
// send the username to another method for further handling
doSomethingWithUsername($response['data']['user']);
}
// ALL METHODS (look at the urls' for response structure)
// http://seal.nimoru.com/docs/user.php
$netseal->getUserDetails($username);
$netseal->banUser($username, $reason);
$netseal->pardonUser($username);
$netseal->unlockUser($username);
// http://seal.nimoru.com/docs/code.php
$netseal->createCode($quantity, $time, $points, $type, $tracking);
$netseal->deleteCode($code);
$netseal->checkCode($code);
// http://seal.nimoru.com/docs/global.php
$netseal->createSetting($name, $value);
$netseal->deleteSetting($name);
$netseal->getPrivateKey($publicKey);
$netseal->unlockAll();
@Panthere
Copy link

Thank you very much for this wrapper.

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