Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint response type with partial parsing #65

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

abraham
Copy link
Contributor

@abraham abraham commented Jan 14, 2023

Initial take on #55 with the timeline, status, and search endpoints updated.

New Response class that contains instances of Result as a single result or multiple results which each have a model or exception.

One upside of this is the new response objects can start surfacing rate limit details.
One downside is the searchend point is considered having single model response and if any one of them failed to parse none of the other results would be available.

  final client = Mastodon(website);
  client.token = bearerToken;

  final statusResponse = await client.status(statusId);
  final status = statusResponse.result.model;
  if (status is Status) {
    print('status: ${status.uri}');
  } else {
    print(statusResponse.result.error!.exception);
  }

  final timelineResponse = await client.timeline(limit: 40);
  for (final result in timelineResponse.results) {
    if (result.model is Status) {
      print('timeline: ${result.model!.uri}');
    } else {
      print(result.error!.exception);
    }
  }

  final searchResponse = await client.search('apple');
  final result = searchResponse.result.model;
  if (result is Results) {
    for (final account in result.accounts) {
      print('search: ${account.url}');
    }
  } else {
    print(searchResponse.result.error!.exception);
  }

Fixes #55

@lukepighetti
Copy link
Owner

Is there a reason to have ModelsResponse<T> instead of using ModelResponse<List<T>>?

@abraham
Copy link
Contributor Author

abraham commented Jan 19, 2023

I don't think there was any particular reason to have two Response classes other than to have .singular and .plural getters but I don't think there isn't a reason not to have a single method where one of those is an alias of the other.

@lukepighetti
Copy link
Owner

This looks good to me

@abraham
Copy link
Contributor Author

abraham commented Jan 21, 2023

I've got the implementation where it's now easy to upgrade endpoints to Responses. I'm going to integrate it into my app to validate the changes work well before finishing up the work.

@abraham abraham mentioned this pull request Jan 22, 2023
@abraham abraham force-pushed the models branch 2 times, most recently from be1f501 to cad893a Compare January 26, 2023 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle parsing exceptions
2 participants