PHP code example of iceithq / oneid-php-client
1. Go to this page and download the library: Download iceithq/oneid-php-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iceithq / oneid-php-client example snippets
neID\Client;
use OneID\Config;
// Create configuration
$config = new Config([
'base_url' => 'https://oneid.systems/api/v1',
'api_key' => 'your-api-key-here', // Optional, can be set later
'timeout' => 30,
'debug' => false
]);
// Initialize client
$client = new Client($config);
// Make API calls
try {
$response = $client->get('/users');
print_r($response);
} catch (OneID\Exceptions\OneIDException $e) {
echo 'Error: ' . $e->getMessage();
}
// Login
try {
$result = $client->authenticate('username', 'password');
$token = $result['token'];
// Set token for future requests
$client->setApiKey($token);
} catch (OneID\Exceptions\AuthenticationException $e) {
echo 'Authentication failed: ' . $e->getMessage();
}
try {
$result = $client->verifyToken($token);
if ($result['valid']) {
echo 'Token is valid';
}
} catch (OneID\Exceptions\OneIDException $e) {
echo 'Token verification failed: ' . $e->getMessage();
}
// Get current authenticated user
$profile = $client->getProfile();
// Get specific user by ID
$profile = $client->getProfile('user-id-123');
try {
$result = $client->refreshToken($refreshToken);
$newToken = $result['token'];
$client->setApiKey($newToken);
} catch (OneID\Exceptions\OneIDException $e) {
echo 'Token refresh failed: ' . $e->getMessage();
}
$client->logout();
// GET request
$response = $client->get('/endpoint', ['param1' => 'value1']);
// POST request
$response = $client->post('/endpoint', ['field1' => 'value1']);
// PUT request
$response = $client->put('/endpoint', ['field1' => 'value1']);
// DELETE request
$response = $client->delete('/endpoint', ['param1' => 'value1']);
$config = new Config([
'base_url' => 'https://oneid.systems/api/v1', // API base URL
'api_key' => 'your-api-key', // API key/token
'timeout' => 30, // Request timeout in seconds
'debug' => false, // Enable debug mode
'options' => [ // Custom options
'custom_option' => 'value'
]
]);
// Getters
$config->getBaseUrl();
$config->getApiKey();
$config->getTimeout();
$config->isDebugMode();
$config->getOption('key', 'default');
// Setters (chainable)
$config->setBaseUrl('https://api.example.com')
->setApiKey('new-key')
->setTimeout(60)
->setDebugMode(true)
->setOption('key', 'value');
use OneID\Exceptions\OneIDException;
use OneID\Exceptions\AuthenticationException;
use OneID\Exceptions\ValidationException;
try {
$client->post('/users', $userData);
} catch (ValidationException $e) {
// Handle validation errors (422)
echo 'Validation failed: ' . $e->getMessage();
print_r($e->getErrors());
} catch (AuthenticationException $e) {
// Handle authentication errors (401, 403)
echo 'Authentication failed: ' . $e->getMessage();
} catch (OneIDException $e) {
// Handle other API errors
echo 'API Error: ' . $e->getMessage();
echo 'HTTP Code: ' . $e->getCode();
}
// public/index.php or bootstrap file
// Initialize OneID client
$oneIdConfig = new Config([
'base_url' => 'https://oneid.systems/api/v1',
'timeout' => 30
]);
$oneIdClient = new Client($oneIdConfig);
// Store in container or global scope
$GLOBALS['oneid'] = $oneIdClient;
// Use in your application
function authenticateRider($username, $password) {
global $oneIdClient;
try {
$result = $oneIdClient->authenticate($username, $password);
$_SESSION['rider_token'] = $result['token'];
$_SESSION['rider_id'] = $result['user']['id'];
return true;
} catch (OneID\Exceptions\AuthenticationException $e) {
return false;
}
}
// config/oneid.php
return [
'base_url' => getenv('ONEID_BASE_URL') ?: 'https://oneid.systems/api/v1',
'api_key' => getenv('ONEID_API_KEY'),
'timeout' => 30,
'debug' => getenv('APP_ENV') === 'development'
];
// services/OneIDService.php
class OneIDService {
private $client;
public function __construct() {
$config = json
{
"repositories": [
{
"type": "path",
"url": "../oneid-php-client"
}
],
"
oneid-php-client/
├── src/
│ ├── Client.php # Main API client
│ ├── Config.php # Configuration class
│ └── Exceptions/ # Exception classes
│ ├── OneIDException.php
│ ├── AuthenticationException.php
│ └── ValidationException.php
├── examples/ # Usage examples
├── tests/ # Unit tests
├── composer.json # Composer configuration
└── README.md # This file