mastodon_api 0.5.0 copy "mastodon_api: ^0.5.0" to clipboard
mastodon_api: ^0.5.0 copied to clipboard

The easiest and powerful Dart/Flutter library for Mastodon API.

example/example.dart

// Copyright 2022 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

import 'package:mastodon_api/mastodon_api.dart';

Future<void> main() async {
  //! You need to specify mastodon instance (domain) you want to access.
  //! Also you need to get bearer token from your developer page, or OAuth 2.0.
  final mastodon = MastodonApi(
    instance: 'MASTODON_INSTANCE',
    bearerToken: 'YOUR_BEARER_TOKEN',

    //! Automatic retry is available when server error or network error occurs
    //! when communicating with the API.
    retryConfig: RetryConfig(
      maxAttempts: 5,
      onExecute: (event) => print(
        'Retry after ${event.intervalInSeconds} seconds...'
        '[${event.retryCount} times]',
      ),
    ),

    //! The default timeout is 10 seconds.
    timeout: Duration(seconds: 20),
  );

  try {
    //! Let's Toot from v1 endpoint!
    final status = await mastodon.v1.statuses.createStatus(
      text: 'Toot!',
    );

    print(status.rateLimit);
    print(status.data);

    //! Search contents includes accounts, statuses, hashtags.
    final contents = await mastodon.v2.search.searchContents(
      query: 'test',
      excludeUnreviewedTags: true,
      limit: 10,
      offset: 2,
    );

    print(contents);
  } on UnauthorizedException catch (e) {
    print(e);
  } on RateLimitExceededException catch (e) {
    print(e);
  } on MastodonException catch (e) {
    print(e.response);
    print(e.body);
    print(e);
  }
}
22
likes
0
pub points
52%
popularity

Publisher

verified publishershinyakato.dev

The easiest and powerful Dart/Flutter library for Mastodon API.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

freezed_annotation, http, json_annotation, universal_io

More

Packages that depend on mastodon_api