mastodon_dart
mastodon_dart copied to clipboard
Endpoint response type with partial parsing
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
Is there a reason to have ModelsResponse<T> instead of using ModelResponse<List<T>>?
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.
This looks good to me
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.