mastodon 1.0.0-beta.7 copy "mastodon: ^1.0.0-beta.7" to clipboard
mastodon: ^1.0.0-beta.7 copied to clipboard

Mastodon API client generated from the unofficial OpenAPI specification.

example/main.dart

import 'package:mastodon/mastodon.dart';

Future<void> getPublicStatuses() async {
  // Set the Mastodon instance URL
  var client = Mastodon(basePathOverride: 'https://mastodon.social');
  // Get a API instance for the REST endpoint group
  var api = client.getTimelinesApi();
  // Call the specific endpoint
  var timeline = await api.getTimelinePublic();

  for (var status in timeline.data!) {
    var text = status.content.replaceAll(RegExp(r'<[^>]*>'), '');
    var displayText = text.substring(0, text.length > 100 ? 100 : text.length);
    print('${status.account.displayName}: ${displayText}');
  }
}

Future<void> createStatus(
  String server,
  String token,
  String statusText,
) async {
  // Set the Mastodon instance URL and OAuth2 token
  var client = Mastodon(basePathOverride: server)
    ..setOAuthToken('OAuth2', token);
  // Get a API instance for the REST endpoint group
  var api = client.getStatusesApi();
  // Create a request to post a text status
  var request = CreateStatusRequest(
    type: CreateStatusRequestType.text,
    text: TextStatus(status: statusText),
  );
  var response = await api.createStatus(createStatusRequest: request);
  // createStatus returns a CreateStatus200Response instance that might contain a status or a scheduled status
  var status = response.data!.status!;
  print('Posted status with ID: ${status.id}');
}

void main() async {
  await getPublicStatuses();
  // await createStatus(
  //   'https://mastodon.social',
  //   'YOUR_OAUTH2_TOKEN_HERE',
  //   'Hello from the Mastodon Dart SDK!',
  // );
}
5
likes
130
points
701
downloads

Publisher

unverified uploader

Weekly Downloads

Mastodon API client generated from the unofficial OpenAPI specification.

Repository (GitHub)
View/report issues

Topics

#mastodon #social #api #openapi #fediverse

Documentation

API reference

License

MIT (license)

Dependencies

copy_with_extension, dio, json_annotation

More

Packages that depend on mastodon