glpi_dart library

GLPI DART

A library to access the GLPI API / This library is a wrapper around the GLPI API, it provides a simple way to access he API. It is based on the Dart http library so it can be used ont dartvm and dartweb. It was implemented following the GLPI API documentation

First step

Before using the library, you need to make sure your GLPI instance is correctly setup to enable the api usage. First you need to add the library to your pubspec.yaml file. Either run

dart pub add glpi_dart

or manually add

glpi_dart: ^0.2.0

to your pubspec.yaml file.

Then you can use the library by importing the client.

import 'package:glpi_dart/glpi_dart.dart';

Usage

Import the library and create a client using GlpiClient You can either also create a client with a stored session token to avoid calling initSessionUsernamePassword or initSessionToken every time.

import 'package:glpi_dart/glpi_dart.dart';
void main() async {
// We recommend to use a secret management library like dotenv
// to store your credentials in a file
String userToken = 'abcedfghijklmnopqrstuvwxyz123467890';
String appToken = '0987654321zyxwvutsrqponmlkjihgfedcba';
String baseUrl = 'http://example.com/apirest.php';
// Create the client BUT doesn't get the session token
GlpiClient client = GlpiClient(baseUrl, appToken: appToken);
String? sessionToken;///
// Get the session token
try {
final response = await client.initSessionUserToken(userToken);
sessionToken = response['session_token'];
client.sessionToken = sessionToken;
} on GlpiException catch (e) {
// In case of will get the http status code (e.code) and the message (e.reason['error'])
print('${e.code} - ${e.error} - ${e.message}');
}///
print(sessionToken);
}

Check the example directory for more examples.

Errors

By design the library will throw an GlpiException if an error occurs during the request. The exception will contain the http response code and a Map with the error code and the error localized message. Methods will also throw an exception if the session token is not set using .

Testing

Right now all the tests aren't written and/or cleaned

License

See LICENSE.md

Additional information

This package is still in development

Classes

GlpiClient
An abstract client which hold the common clients methods and parameters.
GlpiClientBase
Represent the base client for all GLPI API calls.
GlpiSearchCriteria
Represent a search criteria to be used in a search request with GlpiClient.search

Enums

GlpiItemType
The enum reference all the GLPI itemtype inherited from the GLPI class CommonDBTM. This mean we will keep the GLPI / PHP naming convention for the itemtype.
Represent both values that can be used inside a search criteria
GlpiSearchType
Contains all the search types usable inside a search criteria

Exceptions / Errors

GlpiException
A special Exception class is used to handle the errors. It contains the error code and the error code error and message message from GLPI's API response. The code will be a HTTP status code. The error will be the error code and message the error message.