onvaca_connect 0.2.1
onvaca_connect: ^0.2.1 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
/// Complete usage example showing the full SDK workflow.
///
/// See also:
/// - `setup_example.dart` — PMS connection setup and teardown
/// - `booking_flow_example.dart` — Full booking lifecycle
/// - `pagination_example.dart` — Pagination and filtering
/// - `async_operations_example.dart` — Async jobs and polling
/// - `error_handling_example.dart` — Exhaustive error handling
library;
import 'package:onvaca_connect/onvaca_connect.dart';
Future<void> main() async {
// 1. Initialize the client
final connect = OnvacaConnect(
apiKey: 'your-api-key',
baseUrl: 'https://connect.onvaca.com',
);
try {
// 2. Set up a PMS connection
final setup = await connect.setups.create(
const CreateSetupInput(
provider: 'rentalwise',
userId: 'user-123',
workspace: 'my-workspace',
apiKey: 'users-pms-api-key',
),
);
print('Setup created: ${setup.setupId} (linked: ${setup.linked})');
// 3. Check connected providers and supported operations
final connections = await connect.connections();
print('Providers: ${connections.map((c) => c.label).join(', ')}');
if (await connect.supportsOperation('create-booking')) {
print('Booking creation is supported');
}
// 4. List properties
final properties = await connect.properties.list();
print('Found ${properties.total} properties');
for (final property in properties.data) {
print(' - ${property.rawData['name']} (${property.pmsEntityId})');
}
// 5. 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}');
// 6. 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}');
// 7. Create a payment
final payment = await connect.payments.create({
'bookingId': booking.data?['entityId'],
'amount': quote.data?['total'],
'currency': 'USD',
});
print('Payment recorded: ${payment.providerRef}');
// 8. Send a message
final message = await connect.messages.send({
'threadId': 'thread-1',
'body': 'Welcome! Your booking is confirmed.',
});
print('Message sent: ${message.success}');
// 9. Check rates
final rates = await connect.rates.get({'property': '100'});
print('Rates: ${rates.data}');
// 10. Pagination
final bookings = await connect.bookings.list(
options: const EntityListOptions(page: 1, perPage: 10),
);
print('Bookings: ${bookings.total} total, page ${bookings.page}');
if (bookings.hasNextPage) {
print('More pages available');
}
// 11. Disconnect when done
await connect.setups.delete(setup.setupId);
print('Setup disconnected');
// Error handling with pattern matching
} on OnvacaConnectException catch (e) {
switch (e) {
case AuthenticationException():
print('Auth failed: ${e.message}');
case RateLimitException(:final retryAfter):
print('Rate limited. Retry after: $retryAfter');
case EntityNotFoundException(:final message):
print('Not found: $message');
case ProviderUnavailableException(:final message, :final details):
print('Provider down: $message');
print('Details: $details');
case OperationNotSupportedException(:final message):
print('Not supported: $message');
case UnknownApiException(:final statusCode, :final message):
print('Error ($statusCode): $message');
}
} finally {
connect.close();
}
}