chanomhub_flutter 1.0.1
chanomhub_flutter: ^1.0.1 copied to clipboard
Official Flutter SDK for Chanomhub API. Access articles, authentication, downloads, and automated image processing with imgproxy support.
Chanomhub Flutter SDK #
A professional, feature-rich Flutter SDK for the Chanomhub API. This package provides a seamless way to interact with Chanomhub's backend, supporting both GraphQL and REST operations with automated image processing.
๐ Features #
- โก GraphQL v2 Integration: High-performance data fetching with custom field selection (Presets).
- ๐ผ๏ธ Auto Image Transform: Automated
imgproxyURL generation for all image fields. - ๐ Full Auth Support: Login, Registration, Token Refresh, and Session Management.
- ๐ฆ Complete Modules:
- Articles: Search, Filter, and Paginated article lists.
- Users: Profile management, Follow/Unfollow system.
- Downloads: Manage download links with VIP & Versioning support.
- Subscriptions: Access plans and user subscription status.
- Mods & Sponsored: Specialized modules for community content and promotions.
- ๐ ๏ธ Robust Error Handling: Domain-specific exceptions for easy debugging.
๐ Installation #
Add this to your pubspec.yaml:
dependencies:
chanomhub_flutter: ^1.0.0
Then run:
flutter pub get
๐ฆ Quick Start #
Initialize the Client #
import 'package:chanomhub_flutter/chanomhub_flutter.dart';
final sdk = ChanomhubClient(
baseUrl: 'https://api.chanomhub.com',
cdnUrl: 'https://imgproxy.chanomhub.com', // Required for image processing
token: 'YOUR_AUTH_TOKEN', // Optional: for authenticated requests
);
Fetch Articles (GraphQL) #
// Fetch paginated articles with 'standard' field preset
final response = await sdk.articles.getAllPaginated(
options: ArticleListOptions(limit: 10, offset: 0),
);
for (var article in response.items) {
print(article.title);
print(article.mainImage); // Automatically transformed to imgproxy URL!
}
Search Articles #
final searchResult = await sdk.search.articles(
'visual novel',
options: SearchOptions(tag: 'Thai'),
);
๐จ Image Processing (Imgproxy) #
All image fields returned by the SDK are automatically transformed based on the cdnUrl provided. You can also manually transform URLs using the resolveImageUrl utility:
final customUrl = resolveImageUrl(
article.mainImage,
sdk.cdnUrl,
options: ImgproxyOptions(
width: 300,
height: 200,
resizeType: 'fill',
format: 'webp',
),
);
๐งฉ Advanced Usage #
Authentication Flow #
try {
final response = await sdk.auth.login(
email: 'user@example.com',
password: 'secure_password',
);
print('Welcome, ${response.user.username}!');
// Re-initialize or update headers with the new token
sdk.dio.options.headers['Authorization'] = 'Bearer ${response.user.token}';
} on UnauthorizedException {
print('Invalid credentials!');
} on ChanomhubException catch (e) {
print('API Error: ${e.message}');
}
๐งช Testing #
The SDK comes with a built-in mock testing suite. To run the tests:
flutter test
๐ License #
This SDK is released under the MIT License. See LICENSE for details.
๐ค Contributing #
Contributions are welcome! Please feel free to submit a Pull Request or open an Issue on GitHub.