artemis_timatic 0.0.1
artemis_timatic: ^0.0.1 copied to clipboard
A Dart/Flutter client for Timatic-powered APIs — handles authentication, token management, and provides strongly-typed methods to query locations, parameters, accepted values, and submit Timatic docum [...]
example/lib/main.dart
import 'dart:developer';
import 'dart:io';
import 'package:artemis_timatic/artemis_timatic.dart';
Future<void> main() async {
// 1) Init client & API
final client = TimaticClient(TimaticClientOptions(
baseUrl: 'https://timatic.multidcs.com/api/v1', // ← CHANGE ME
));
final api = TimaticApi(client);
try {
// 2) Login (stores bearer token inside client for future calls)
final login = await api.login(
LoginRequest(
username: 'superadmin', // ← CHANGE
password: '11555FaraN#+', // ← CHANGE
app: {"aa":"asd"},
device: {},
network: {},
),
);
log('Logged in as: ${login.profile.username}');
log('Token (short): ${client.authToken?.substring(0, 12)}…');
// 3) Locations — by type (path param)
final airports = await api.listLocationsByType(
LocationType.AIRPORT,
name: 'Istanbul', // optional
);
log('Airports (sample): ${airports.take(3).map((a) => a.code3).toList()}');
// 4) Locations — multi-type search (repeated query params)
final mixed = await api.listLocationsByType(
LocationType.CITY,
code: '',
name: ""// optional
);
log('Search locations count: ${mixed.length}');
// 5) Parameters (e.g., "pets")
final paramsEnv = await api.getParameters(codes: ['pets']);
for (final p in paramsEnv.parameters) {
log('Parameter: ${p.name} (${p.code}) → '
'${p.parameterValues.map((v) => v.code).take(3).join(", ")}…');
}
// 6) Accepted values for a country/parameter with rule set filters
final accepted = await api.getAcceptedValues(
countryCode: 'TR', // Turkiye
parameter: 'docIssueCountry', // from your API
ruleSetTypes: ['REQTIX','INFTST','REQDOC'],
);
log('Accepted for ${accepted.locationName}: '
'${accepted.ruleSets.first.parameter.parameterValues.length} values');
// 7) Submit main Timatic document request
final docResp = await api.submitDocumentRequest(
DocumentRequest(
documentDetails: [
DocumentDetail(
documentCode: 'OFFICIALPASSPORT',
documentExpiryDate: '2024-01-31',
documentIssueCountry: 'AFG',
),
],
itineraryDetails: ItineraryDetails(
segments: [
ItinerarySegment(
arrival: ItinPoint(
date: '2023-12-28',
time: '08:54',
dateTime: '2023-12-28T08:54:05',
point: 'AAH',
type: LocationType.AIRPORT,
),
departure: ItinPoint(
date: '2023-12-28',
time: '08:54',
dateTime: '2023-12-28T08:54:05',
point: 'IST',
type: LocationType.AIRPORT,
),
processingEntity: 'ABOMIS DOC CHECK',
),
],
),
passengerDetails: PassengerDetails(
birthDate: '2023-12-13',
nationality: 'ALB',
),
),
);
log('Txn: ${docResp.transactionId} Eval: ${docResp.evaluationResult}');
for (final seg in docResp.segmentResults) {
log('Segment → ${seg.arrival.point}→${seg.departure.point} '
'Result: ${seg.segmentEvaluationResult}');
for (final rs in seg.ruleSetEvaluations.take(3)) {
log(' ${rs.ruleSetType.name} = ${rs.evaluationResult}');
for (final dr in rs.documentResults) {
for (final reg in dr.regulations) {
// HTML text strings are in reg.texts[].text
final hint = reg.texts?.isNotEmpty == true
? reg.texts!.first.text.replaceAll(RegExp(r'\s+'), ' ')
: '';
log(' - ${reg.name}: ${reg.evaluationResult} ${hint.isEmpty ? "" : "…"}');
}
}
}
}
} catch (e, st) {
// minimal error log
stderr.writeln('❌ Error: $e');
stderr.writeln(st);
}
}