atproto 0.1.2 copy "atproto: ^0.1.2" to clipboard
atproto: ^0.1.2 copied to clipboard

The Easiest and Powerful Dart/Flutter Library for AT Protocol.

example/example.dart

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

import 'package:atproto/atproto.dart' as atp;

Future<void> main() async {
  try {
    //! First you need to establish session with ATP server.
    final session = await atp.createSession(
      service: 'SERVICE_NAME', //! The default is `bsky.social`
      handle: 'YOUR_HANDLE', //! Like `shinyakato.bsky.social`
      password: 'YOUR_PASSWORD',
    );

    print(session);

    final atproto = atp.ATProto.fromSession(
      session.data,

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

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

    //! Create a record to specific service.
    final createdRecord = await atproto.repositories.createRecord(
      collection: 'app.bsky.feed.post',
      record: {
        'text': 'Hello, Bluesky!',
        "createdAt": DateTime.now().toUtc().toIso8601String(),
      },
    );

    //! And delete it.
    await atproto.repositories.deleteRecord(
      collection: 'app.bsky.feed.post',
      uri: createdRecord.data.uri,
    );
  } on atp.UnauthorizedException catch (e) {
    print(e);
  } on atp.ATProtoException catch (e) {
    print(e);
  }
}
12
likes
0
pub points
44%
popularity

Publisher

verified publisheratprotodart.com

The Easiest and Powerful Dart/Flutter Library for AT Protocol.

Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

github.com

License

unknown (LICENSE)

Dependencies

atproto_core, freezed_annotation, http, json_annotation

More

Packages that depend on atproto