An Gelboory API client written in Dart and powered by the http
package !
Compatible with all Dart supported platforms, this package allows you to interact with the Gelbooru API in a more Dart idiomatic way.
Features
- Implements all the #5 endpoints of the Gelbooru API
- No scrapping, all requests are made to the API properly, gently and respecting the API rate limits.
- Use Dart's native
http
package for making requests allowing for using more advanced implementation on the fly.
Getting started
Run the following command:
# You may also add the http and xml packages for their respective exceptions
$ dart pub add gelbooru
Usage
import 'dart:io';
import 'package:gelbooru/gelbooru.dart';
/// Get last 10 posts from Gelbooru
void main() async {
final client = GelbooruClient(baseUrl: 'https://gelbooru.com');
/// You can also you a custom http based client
/// like the cupertino_http package
/// final client = GelbooruClient(baseUrl: 'https://gelbooru.com', httpClient: CupertinoClient.fromSessionConfiguration(config));
/// The [PostResponsePage] is a iterable of [Post]
/// with also the metadata of the request
/// such as the [offset], [limit] and [count]
final PostResponsePage posts = await client.getPosts(
limit: 10,
page: 1,
tags: 'rating:safe',
);
/// [PostResponsePage] is iterable so it can use all the method from [UnmodifiableListView]
if(posts.isEmpty) {
print('No posts found');
return;
}
for(final Post post in posts) {
print('Post id: ${post.id} @ Tags : ${post.tags.join(', ')} @ Link : ${post.fileUrl}');
}
/// Same as above for the tags, comments, and users
/// The [TagResponsePage], [CommentResponsePage] and [UserResponsePage] are iterable of [Tag], [Comment] and [User]
final TagResponsePage tags = await client.getTags(
limit: 10,
page: 1,
order: TagOrder.count,
orderBy: TagOrderBy.desc,
);
final CommentResponsePage comments = await client.getComments(
limit: 10,
page: 1,
);
final UserResponsePage users = await client.getUsers(
limit: 10,
page: 1,
);
exit(0);
}
Quirks and sparks
- The
GelbooruClient
is a stateless object, you can use it as a singleton or create a new instance for each request. - There's no check to see if the API is up or not, if the API is down, the client will throw a
ClientException
from thehttp
package.
No AI project / AI free Project
Use the project or any parts for any commercial (meaning generating revenue) purposes WITHOUT written authorization from the project owner See the LICENSE file for more details.