Git Product home page Git Product logo

mastodon_dart's Introduction

mastodon_dart

The unofficial Dart library for accessing the Mastodon API through REST or WebSockets.

Mastodon API documentation

Goals

  • To implement >98% of documented endpoints and models.

Promises

  • To provide fast code reviews that add support for endpoints or models.

Contributing

Create a PR, explain what it solves, and be willing to engage with a code review.

mastodon_dart's People

Contributors

abraham avatar groovinchip avatar lukepighetti avatar skywavetm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mastodon_dart's Issues

TimelineBloc does not like Poll entities

Steps to reproduce:

  1. Check out the add_missing_entity_data branch
  2. Run the mastodon_flutter example app while depending on mastodon_dart from path
  3. The below stack trace will appear in the console

Stack trace:

E/flutter ( 1696): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast
E/flutter ( 1696): #0      _$PollFromJson (package:mastodon_dart/src/data/poll.g.dart:21:31)
E/flutter ( 1696): #1      new Poll.fromJson (package:mastodon_dart/src/data/poll.dart:69:55)
E/flutter ( 1696): #2      _$StatusFromJson (package:mastodon_dart/src/data/status.g.dart:55:16)
E/flutter ( 1696): #3      new Status.fromJson (package:mastodon_dart/src/data/status.dart:170:57)
E/flutter ( 1696): #4      Timelines.publicTimeline.<anonymous closure> (package:mastodon_dart/src/endpoints/timelines.dart:92:55)
E/flutter ( 1696): #5      MappedListIterable.elementAt (dart:_internal/iterable.dart:417:31)
E/flutter ( 1696): #6      ListIterator.moveNext (dart:_internal/iterable.dart:346:26)
E/flutter ( 1696): #7      new List.from (dart:core-patch/array_patch.dart:54:19)
E/flutter ( 1696): #8      Timelines.publicTimeline (package:mastodon_dart/src/endpoints/timelines.dart:91:12)
E/flutter ( 1696): <asynchronous suspension>
E/flutter ( 1696): #9      _LocalTimelineState.updateTimelineBloc.<anonymous closure> (package:jiminy_for_mastodon/screens/timelines/local_timeline.dart:61:49)
E/flutter ( 1696): #10     TimelineBloc._handleRequest (package:mastodon_dart/src/bloc/timeline.dart:40:42)
E/flutter ( 1696): #11     _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter ( 1696): #12     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 1696): #13     _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter ( 1696): #14     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 1696): #15     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
E/flutter ( 1696): #16     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:779:19)
E/flutter ( 1696): #17     _StreamController._add (dart:async/stream_controller.dart:655:7)
E/flutter ( 1696): #18     _StreamController.add (dart:async/stream_controller.dart:597:5)
E/flutter ( 1696): #19     BackpressureStreamTransformer._buildTransformer.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:rxdart/src/transformers/backpressure/backpressure.dart:99:53)
E/flutter ( 1696): #20     BackpressureStreamTransformer._buildTransformer.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:rxdart/src/transformers/backpressure/backpressure.dart:214:39)
E/flutter ( 1696): #21     BackpressureStreamTransformer._buildTransformer.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:rxdart/src/transformers/backpressure/backpressure.dart:249:32)
E/flutter ( 1696): #22     _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter ( 1696): #23     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 1696): #24     _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter ( 1696): #25     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 1696): #26     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:266:7)
E/flutter ( 1696): #27     _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:134:11)
E/flutter ( 1696): #28     _WhereStream._handleData (dart:async/stream_pipe.dart:209:12)
E/flutter ( 1696): #29     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:166:13)
E/flutter ( 1696): #30     _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter ( 1696): #31     _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 1696): #32     _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter ( 1696): #33     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 1696): #34     _DelayedData.perform (dart:async/stream_impl.dart:594:14)
E/flutter ( 1696): #35     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:710:11)
E/flutter ( 1696): #36     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:670:7)
E/flutter ( 1696): #37     _rootRun (dart:async/zone.dart:1180:38)
E/flutter ( 1696): #38     _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter ( 1696): #39     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter ( 1696): #40     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
E/flutter ( 1696): #41     _rootRun (dart:async/zone.dart:1184:13)
E/flutter ( 1696): #42     _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter ( 1696): #43     _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter ( 1696): #44     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
E/flutter ( 1696): #45     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter ( 1696): #46     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter ( 1696): 

Discussion - add documentation comments to entity properties or simply link to masto docs

As I go through the entities and update the docs links and add missing data, I wonder if we should include the descriptions given for the data from the docs. Would it make including the doc links moot? I can see it form both sides: having the documentation comments helps the API docs for pub, and developers who use that will not have to leave it to read about the data. On the other hand, we link to the masto docs and everything is there.

Thoughts?

publishStatus throws a NoSuchMethodError for the getter 'length'

Sample code:

Provider.of<Mastodon>(context).publishStatus(
  status: postContentController.text,
  visibility: Visibility.public,
).catchError((error) => print(error));

produces the below error:

I/flutter (10922): NoSuchMethodError: The getter 'length' was called on null.
I/flutter (10922): Receiver: null
I/flutter (10922): Tried calling: length

Add blurhash to media model

https://docs.joinmastodon.org/methods/statuses/media/

{
  "id": "22348641",
  "type": "image",
  "url": "https://files.mastodon.social/media_attachments/files/022/348/641/original/cebc6d51be03e509.jpeg",
  "preview_url": "https://files.mastodon.social/media_attachments/files/022/348/641/small/cebc6d51be03e509.jpeg",
  "remote_url": null,
  "text_url": "https://mastodon.social/media/4Zj6ewxzzzDi0g8JnZQ",
  "meta": {
    "focus": {
      "x": -0.69,
      "y": 0.42
    },
    "original": {
      "width": 640,
      "height": 480,
      "size": "640x480",
      "aspect": 1.3333333333333333
    },
    "small": {
      "width": 461,
      "height": 346,
      "size": "461x346",
      "aspect": 1.3323699421965318
    }
  },
  "description": "test uploaded via api",
  "blurhash": "UFBWY:8_0Jxv4mx]t8t64.%M-:IUWGWAt6M}" //////////////////////////////////
}

context https://github.com/woltapp/blurhash https://blurha.sh

Add error entity?

Related to #14

Is this needed? I've seen this error get printed in the console, I don't know that we need this as its own entity.

What do you think @lukepighetti

Tests

This is a big topic. The general concept seems to be:

  1. Get a real JSON response (Postman is useful here)
  2. Remove any personal data.
  3. Create an HTTP Override https://docs.flutter.io/flutter/dart-io/HttpOverrides-class.html
  4. Mock a response to the endpoint you're testing. (JSON in a string literal?)
  5. Call the method that hits that endpoint
  6. Make sure the data class deserializes without errors.
  7. Check a couple fields.

Handle parsing exceptions

I expect API response formats to become more divergent and buggy as more servers and forks of Mastodon popup. Currently if you request a timeline and one posts triggers a parsing exception (like #51) the entire response is lost. I'd like to see a way to get all the successful statuses and a list of exceptions for the failed statuses. This way users can be shown most of the content and the option to report parse issues to developers.

I'm noodling something similar to the following. What do you think?

Pattern 1:

class StatusException {
  final Exception exception;
  final String unparsed;
  final String? id;
  final Uri? uri;
  final String? attribute;

  StatusException({
    required this.exception,
    required this.unparsed,
    this.id,
    this.uri,
    this.attribute,
  });
}

class Response {
  final List<Status> statuses;
  final List<StatusException> exceptions;

  Response({
    required this.statuses,
    this.exceptions = const [],
  });
}

client.partialReponse = true; // some way of enabling partial responses
final Response response = await client.timeline();

When building my app on a new machine, I get the following error after copying my token and returning to the app

E/flutter (21006): [ERROR:flutter/shell/common/shell.cc(186)] Dart Error: Unhandled exception:
E/flutter (21006): Unsupported operation: Cannot modify an unmodifiable Map
E/flutter (21006): #0      _ImmutableMap.removeWhere (dart:core/runtime/libimmutable_map.dart:118:5)
E/flutter (21006): #1      __Base&Authentication&Utilities.request (package:mastodon/src/utilities.dart:23:31)
E/flutter (21006): <asynchronous suspension>
E/flutter (21006): #2      _Mastodon&_Base&Accounts.verifyCredentials (package:mastodon/src/endpoints/accounts.dart:57:28)
E/flutter (21006): <asynchronous suspension>
E/flutter (21006): #3      AuthBloc._handleToken (package:mastodon/src/bloc/auth.dart:131:38)
E/flutter (21006): <asynchronous suspension>
E/flutter (21006): #4      _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10)
E/flutter (21006): #5      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11)
E/flutter (21006): #6      _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter (21006): #7      _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11)
E/flutter (21006): #8      _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7)
E/flutter (21006): #9      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (21006): #10     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)```

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.