omniindex 1.0.18 omniindex: ^1.0.18 copied to clipboard
OmniIndex dart package is a library which handles commnication between OmniIndex clients and their relating data within a flutter/dart application environment
/// 3-Clause BSD License
/// Copyright 2023 OmniIndex Inc.
///
/// Redistribution and use in source and binary forms, with or without
/// modification, are permitted provided that the following conditions are met:
///
/// 1. Redistributions of source code must retain the above copyright notice,
/// this list of conditions and the following disclaimer.
/// 2. Redistributions in binary form must reproduce the above copyright notice,
/// this list of conditions and the following disclaimer in the documentation
/// and/or other materials provided with the distribution.
/// 3. Neither the name of the copyright holder nor the names of its
/// contributors may be used to endorse or promote products derived from this
/// software without specific prior written permission.
///
/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
/// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
/// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
/// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
/// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
/// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
/// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
/// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
/// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
/// POSSIBILITY OF SUCH DAMAGE.
///
/// @author: Ken Hawkins
/// @email: ken@omniindex.io
/// @date: 01/24/2023
/// @project: omniindex
///
/// Naming Conventions Inline with the Google Dart programming specification.
library omniindex.example;
import 'dart:convert';
import 'dart:io';
import 'package:logger/logger.dart';
import 'package:omniindex/omniindex.dart';
final _logger = Logger(
printer: PrettyPrinter(
methodCount: 0,
errorMethodCount: 5,
lineLength: 50,
colors: true,
printEmojis: true,
printTime: true,
));
OmniIndex _getOmniIndexInstance() {
PGBCCredentials pgbcCredentials = PGBCCredentials(
username: '[Username]',
password: '[Password]',
dataSource: '',
seed: '0.0.0.0',
port: 5434);
return OmniIndex.withPGBCCredentials(pgbcCredentials: pgbcCredentials);
}
Future<void> main() async {
// omniindex (oidx) object to work with
OmniIndex oidx = _getOmniIndexInstance();
if (!await oidx.authorize()) {
_logger.e("could not log in");
exit;
}
// user to act with
BasicCredentials testUser = BasicCredentials(
username: 'test@omniindex.io', password: 'test@omniindex.io');
// add the user
String result = await oidx.addUser(testUser.username, testUser.password);
// parse the response
Map<String, dynamic> json = jsonDecode(result) as Map<String, dynamic>;
if (json.containsKey('error')) {
_logger.e(json);
_logger.e('exiting...');
exit;
}
// simple delete of user
result = await oidx.deleteUser(testUser.username);
json = jsonDecode(result) as Map<String, dynamic>;
_logger.d(json);
// exiting
_logger.d('exiting...');
exit;
}