ixoplan / ixoplan-sdk
Client library for Ixoplan APIs
Requires
- ixoplan/ixoplan-sdk-http: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- apigen/apigen: ^4.1
- fzaninotto/faker: ^1.9@dev
- ixoplan/ixoplan-sdk-http-guzzle: ^1.0
- mockery/mockery: 1.3.x-dev
- phing/phing: ^2.14
- phpmd/phpmd: ^2.4
- phpunit/phpunit: ^4.8
Suggests
- ixoplan/ixoplan-sdk-http-guzzle: Guzzle connector for the Ixoplan SDK
- dev-master
- 1.0.52
- 1.0.51
- 1.0.50
- 1.0.49
- 1.0.48
- 1.0.47
- 1.0.46
- v1.0.45
- v1.0.44
- v1.0.43
- v1.0.42
- v1.0.41
- v1.0.40
- v1.0.39
- v1.0.38
- v1.0.37
- v1.0.36
- v1.0.35
- v1.0.34
- v1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-beta
This package is auto-updated.
Last update: 2024-12-08 20:25:31 UTC
README
PHP SDK for the Ixoplan API
Installation
Simply add ixolit/ixoplan-sdk
and a provider of ixolit/ixoplan-sdk-http
(e.g. ixolit/ixoplan-sdk-http-guzzle) to your composer.json, e.g:
{ "name": "myvendor/myproject", "description": "Using ixoplan-sdk", "require": { "ixolit/ixoplan-sdk": "*", "ixolit/ixoplan-sdk-http-guzzle": "*" } }
Usage
Instantiate the Client
The client is designed for different transport layers. It needs a RequestClient interface (e.g. HTTPRequestClient) to actually communicate with Ixoplan.
use Ixolit\Dislo\Client; use Ixolit\Dislo\HTTP\Guzzle\GuzzleHTTPClientAdapter; use Ixolit\Dislo\Request\HTTPRequestClient; $httpAdapter = new GuzzleHTTPClientAdapter(); $httpClient = new HTTPRequestClient( $httpAdapter, $host, $apiKey, $apiSecret ); $apiClient = new Client($httpClient);
Most methods related to user data can be used with either a user ID, a \Ixolit\Dislo\WorkingObjects\User
object or an authentication token. However, the less secure options have to be requested explicitely by passing $forceTokenMode = false
to the constructor. Don't use this option unless you really need it, e.g. for implementing administrative functionality.
Login
Authenticate user, retrieve token and user data:
$apiClient = new \Ixolit\Dislo\Client($httpClient); try { $authResponse = $apiClient->userAuthenticate( $userEmail, $password, $ipAddress ); $authToken = $authResponse->getAuthToken(); setcookie('authToken', $authToken); $user = $response->getUser(); echo $user->getLastLoginDate(); } catch (\Ixolit\Dislo\Exceptions\AuthenticationInvalidCredentialsException $e) { // invalid credentials echo $e->getMessage(); }
Get user from token:
$token = getcookie('authToken'); $apiClient = new \Ixolit\Dislo\Client($httpClient); try { $user = $apiClient->userGet($token); } catch (\Ixolit\Dislo\Exceptions\InvalidTokenException $e) { // token invalid, e.g. expired setcookie('authToken', null, -1); } catch (\Ixolit\Dislo\Exceptions\DisloException $e) { // other, e.g. missing arguments }
A token's expiry time is extended automatically on usage.
Verify a token, explicitly extend its expiry time and optionally change its lifetime:
$token = getcookie('authToken'); $apiClient = new \Ixolit\Dislo\Client($httpClient); try { $response = $apiClient->userExtendToken($token, $ipAdress, 3600); $authToken = $response->getAuthToken(); echo $authToken->getValidUntil()->format('c'); } catch (\Ixolit\Dislo\Exceptions\InvalidTokenException $e) { // token invalid, e.g. expired setcookie('authToken', null, -1); } catch (\Ixolit\Dislo\Exceptions\DisloException $e) { // other, e.g. missing arguments }
Deauthenticate:
$apiClient->userDeauthenticate($token); setcookie('authToken', null, -1);
Packages
Retrieve a list of packages, optionally filtered by service ID:
$apiClient = new \Ixolit\Dislo\Client($httpClient); $response = $apiClient->packagesList("1"); foreach ($response->getPackages() as $package) { echo $package->getDisplayNameForLanguage('en')->getName(), "\n"; }
Subscriptions
Retrieve a list of subscriptions for a user:
$apiClient = new \Ixolit\Dislo\Client($httpClient); $response = $apiClient->subscriptionGetAll($token); foreach ($response->getSubscriptions() as $subscription) { print_r([ 'status' => $subscription->getStatus(), 'active' => $subscription->isActive(), 'startedAt' => $subscription->getStartedAt()->format('c'), 'package' => $subscription->getCurrentPackage()->getDisplayNameForLanguage('en')->getName(), 'price (EU)' => $subscription->getCurrentPeriod()->getBasePriceForCurrency('EUR')->getAmount(), 'metaData' => $subscription->getProvisioningMetaData(), ]); }
Search API
Run a parametrized query against the search database in Ixoplan, pass a file resource to stream the returned data to.
$apiClient = new \Ixolit\Dislo\Client($httpClient); $date = date('Y-m-d'); $file = fopen('/path/to/file', 'w'); $apiClient->exportStreamQuery( 'select * from users where last_indexed_at > :_last(date)', ['last' => $date], $file );