As suggested by 'mattn, use a `TeeReader` with an `io.Writer` to keep
the semantics of `json.NewDecoder().Decode()` whilst also being able
to save the JSON if requested by the client.
However we need to use our own interface (`WriteResetter`) in order to
be able to call `Reset()` on the underlying buffer (which does somewhat
limit the usage to buffers instead of generic `io.Writer` and may not
be the 100% ideal solution.)
For my archival purposes, I like to keep the raw API JSON around
as it often contains things not picked up by the various objects.
e.g. getting a status from my Akkoma instance contains a whole
`pleroma` extension block that's not reflected in `mastodon.Status`.
Maybe this should be gated by an option when creating the `Client`
since it's probably only relevant to 1% of library users.
Doubling the backoff every iteration turned out to be a bit
too relaxed for the common situations where you run into API
throttling. This change gives the API enough room to breathe,
but re-tries requests just a little more often.
Mastodon API's pagination IDs are not guaranteed to be in a numeric format.
This happens to be the case for the tootsuite implementation, but others
use UUIDs or flake IDs for pagination.
This also simplifies the code a bit and luckily shouldn't break backwards
compatibility since they're already of type ID in the Pagination struct.
Since it's difficult to wrap all possible go-mastodon API calls in a backoff
algorithm outside of the package itself, I decided to implement a simple
version of it in go-mastodon's doAPI itself.
This works nicely, but could be improved in two ways still:
- Abort sleeping when context gets cancelled
- Make backoff optional / configurable
Personally, I still think this is a good start and probably fits most of
go-mastodon's use-cases. It certainly beats string-grepping for status code
"429" in clients.
Added missing fields to various structs and sorted them in the same order as
the original mastodon API documentation does. This should make it easier to
compare go-mastodon's structs with the original documentation.
This is required for users who have 2-factor authentication enabled, and is generally safer because users don't need to give their password to third-party software.
`doAPI`'s `context` does not work due to `WithContext` immutability.
`Authenticate` and `RegisterApp` does not use `context` although they
needs `context`, so their `context` does not work also. This commit fixes
them and add test cases.