youversion_sdk 0.0.1
youversion_sdk: ^0.0.1 copied to clipboard
A production-ready Dart and Flutter SDK for the YouVersion REST API, featuring a clean, type-safe, and idiomatic wrapper with exhaustive error handling.
YouVersion SDK #
A production-ready, open-source Dart/Flutter SDK for the YouVersion REST API. This package provides a clean, idiomatic, and strongly-typed wrapper around YouVersion's API, enabling developers to easily fetch Bibles, Chapters, and Verses in their Flutter apps.
Features #
- Singleton Client: Centralized
YouVersionClientfor easy API consumption. - Robust Error Handling: Exhaustive sealed classes (
YouVersionException) for pattern-matching HTTP errors (e.g.,YouVersionAuthException,YouVersionRateLimitException). - Type-safe Models: Data is parsed into immutable
@freezedmodels (Bible,Chapter,Verse). - Automatic Headers: Custom Dio interceptor automatically injects developer tokens and handles standard content-type headers.
Getting started #
You'll need a developer token from YouVersion to use this SDK.
- Add
youversion_sdkto yourpubspec.yamldependencies. - Ensure you have network permissions enabled in your target platforms (Android, iOS, macOS).
Usage #
import 'package:youversion_sdk/youversion_sdk.dart';
void main() async {
// 1. Initialize the client
final client = YouVersionClient(
developerToken: 'YOUR_DEVELOPER_TOKEN',
language: 'en',
);
// 2. Fetch data via repositories
try {
final bibles = await client.bibles.list();
for (final bible in bibles) {
print('Bible: ${bible.title} (${bible.abbreviation})');
}
} on YouVersionException catch (e) {
// 3. Exhaustive error handling via sealed classes
switch (e) {
case YouVersionAuthException():
print('Check your developer token!');
case YouVersionRateLimitException():
print('Too many requests. Slow down.');
case YouVersionNetworkException():
print('No internet connection.');
case YouVersionNotFoundException():
case YouVersionUnknownException():
print('An error occurred: ${e.message}');
}
}
}
Additional information #
This package uses dio for networking and freezed for models. Contributions, bug reports, and feature requests are welcome via the repository's issue tracker.