onvaca_connect 0.1.0
onvaca_connect: ^0.1.0 copied to clipboard
Dart SDK for the OnVaca Connect Platform — a unified interface for multiple property management system providers.
example/example.dart
// ignore_for_file: avoid_print, unused_local_variable
import 'package:onvaca_connect/onvaca_connect.dart';
Future<void> main() async {
// Initialize the client
final connect = OnvacaConnect(
apiKey: 'your-api-key',
baseUrl: 'https://connect.onvaca.com',
);
try {
// List available connections
final connections = await connect.connections();
print('Connected providers: ${connections.map((c) => c.label).join(', ')}');
// Check if an operation is supported
final canCreateBooking = await connect.supportsOperation('create-booking');
print('Supports create-booking: $canCreateBooking');
// List properties
final properties = await connect.properties.list();
print('Found ${properties.total} properties');
if (properties.data.isNotEmpty) {
final property = properties.data.first;
print('First property: ${property.rawData['name']}');
}
// List bookings with pagination
final bookings = await connect.bookings.list(
options: const EntityListOptions(page: 1, perPage: 10),
);
// Get a booking quote
final quote = await connect.bookings.quote({
'property': '100',
'daterange': {'start': '2026-06-01', 'end': '2026-06-07'},
'adults': 2,
});
print('Quote: ${quote.data}');
// Create a booking
final booking = await connect.bookings.create({
'property': '100',
'daterange': {'start': '2026-06-01', 'end': '2026-06-07'},
'adults': 2,
'source_name': 'MyApp',
});
print('Booking created: ${booking.providerRef}');
// Error handling with pattern matching
} on OnvacaConnectException catch (e) {
switch (e) {
case AuthenticationException():
print('Bad API key: ${e.message}');
case RateLimitException(:final retryAfter):
print('Rate limited. Retry after: $retryAfter');
case EntityNotFoundException(:final entityId):
print('Entity $entityId not found');
case ProviderUnavailableException():
print('PMS provider is down');
case OperationNotSupportedException(:final slug):
print('Operation $slug not supported by this provider');
case UnknownApiException(:final statusCode):
print('Unexpected error ($statusCode): ${e.message}');
}
} finally {
connect.close();
}
}