Commit Graph

44 Commits

Author SHA1 Message Date
Dom Rodriguez e0d25815f0
Add support for alternative Listenbrainz hosts
This commit adds support for alternative Listenbrainz hosts.

L10 defines the most used official host for Listenbrainz.

I have refactored the Client struct to have the `api_root_url` field.
This is automatically set to the value L10 defines, when a Client is
instantiated with `new()`. On the invocation of `client_with_url(url:
&str)`, the `api_root_url` field is set to the Listenbrainz instance
API root URL passed to the function.

The 1:1 functions <-> API methods have been modified to use
`self.api_root_url` as the base of the `format!()` macro invoked, rather
than the global constant of `API_ROOT_URL`.

This commit has been tested with the examples, and appears to be
functional.

Fixes #2.

Signed-off-by: Dom Rodriguez <shymega@shymega.org.uk>
2021-08-30 16:26:39 +01:00
Koen Bolhuis 508f697a51 Add rate limiting information to response types
Add the `rate_limit` field to all response types,
which contains rate limiting information such as
maximum and remaining requests in the current
time frame, as well as when the next time frame
starts.

All response types now also implement the `ResponseType`
trait (internal for now). Currently this trait allows
converting from `ureq::Response` to the response type,
by extracting rate limiting information from the response
headers and deserializing the response body into the
response type.
2021-01-30 03:06:02 +01:00
Koen Bolhuis fd9c7823d7 Update comment for ListenBrainz::playing_now 2021-01-30 02:31:57 +01:00
Koen Bolhuis 2ff97ce9d2 Run rustfmt 2021-01-20 01:13:13 +01:00
Koen Bolhuis c76d0d9d89 Add example to crate root 2021-01-20 01:11:47 +01:00
Koen Bolhuis ca86b987e4 Polish ListenBrainz docs 2021-01-20 01:11:39 +01:00
Koen Bolhuis ae9b342474 Improve docs for the ListenBrainz type 2021-01-20 00:57:03 +01:00
Koen Bolhuis b4c4226677 Represent invalid tokens with an error instead of a boolean 2021-01-20 00:52:10 +01:00
Koen Bolhuis 5f6c5f5375 Improve crate documentation 2021-01-20 00:37:39 +01:00
Koen Bolhuis f72ab1cbdf Add error documentation to ListenBrainz::playing_now 2021-01-20 00:26:27 +01:00
Koen Bolhuis 9ed9ebfe0f Move Endpoint to raw module 2021-01-20 00:23:35 +01:00
Koen Bolhuis 7f07ecfb32 Add ListenBrainz type
The ListenBrainz struct is a more ergonomic client
than raw::Client. It supports authentication using
a ListenBrainz token. Currently, it allows submitting
"listened" and "now playing" requests to the API
in a more convenient way than manually creating all
request data.
2021-01-20 00:16:53 +01:00
Koen Bolhuis 56a50d936c Move Client to raw module 2021-01-19 23:51:17 +01:00
Koen Bolhuis a22fcff2bf Move low-level models to raw module 2021-01-19 23:41:54 +01:00
Koen Bolhuis 83fa18e048 Improve Client documentation
Add information on errors returned by Client's methods,
as well as comments for internal helper methods.
2021-01-15 23:35:00 +01:00
Koen Bolhuis 6309a544ef Change all Client methods from &mut self to &self 2021-01-15 01:04:46 +01:00
Koen Bolhuis 64e180fb84 Run rustfmt 2021-01-14 03:29:21 +01:00
Koen Bolhuis fb9c892a3b URL encode usernames with commas 2021-01-14 03:26:41 +01:00
Koen Bolhuis 6080a94774 Add doc for UserListenCountPayload 2021-01-14 03:09:17 +01:00
Koen Bolhuis 605d5a43ca Link to API endpoints in docs for Client functions 2021-01-14 03:03:04 +01:00
Koen Bolhuis 9ec6dabb48 Add several example programs 2021-01-14 02:49:41 +01:00
Koen Bolhuis 06bd7997b6 Fix response models 2021-01-14 02:49:08 +01:00
Koen Bolhuis 6eefbc96d9 Fix request models 2021-01-14 02:44:45 +01:00
Koen Bolhuis 67d9bf9632 Fix handling of HTTP 204 on statistics endpoints
The ListenBrainz API returns 204 and an empty document
when there are no statistics, which can't be parsed as
JSON. Therefore the return types of statistics endpoints
now includes an Option to reflect this.
2021-01-14 02:42:33 +01:00
Koen Bolhuis cce6d09b35 Use better import form 2021-01-14 02:42:17 +01:00
Koen Bolhuis 16b7d643c9 Extract stats code to get_stats function 2021-01-13 17:28:12 +01:00
Koen Bolhuis 3588436e53 Run rustfmt 2021-01-13 14:28:59 +01:00
Koen Bolhuis 9581ce45cb Box ureq::Error because it is 1000+ bytes 2021-01-13 14:28:28 +01:00
Koen Bolhuis 6c0eff415e Implement StatsUserArtists 2021-01-13 14:15:32 +01:00
Koen Bolhuis 2bc3291a61 Implement StatsUserReleases 2021-01-13 14:11:11 +01:00
Koen Bolhuis bd263af244 Implement StatsUserArtistMap 2021-01-13 14:02:23 +01:00
Koen Bolhuis 59491fc56f Implement StatsUserRecordings 2021-01-13 13:58:32 +01:00
Koen Bolhuis 9c40b2522b Implement StatsUserListeningActivity and StatsUserDailyActivity 2021-01-13 13:06:48 +01:00
Koen Bolhuis 7f5d67ba74 Document Error::ApiError fields 2021-01-13 13:05:50 +01:00
Koen Bolhuis ae0c47750a Extract Client to client module 2021-01-13 11:52:58 +01:00
Koen Bolhuis 22b04846b2 Implement StatsSitewideArtists endpoint 2021-01-10 21:42:40 +01:00
Koen Bolhuis 727ba956b7 Add doc comments for response model field types 2021-01-10 21:40:49 +01:00
Koen Bolhuis 7ef861f151 Add doc comments to models 2021-01-10 20:48:54 +01:00
Koen Bolhuis ad89493233 Implement UserPlayingNowListen 2021-01-10 19:31:06 +01:00
Koen Bolhuis 14428576a8 Extract Error to error module 2021-01-10 19:30:03 +01:00
Koen Bolhuis a3265dceac Extract Endpoint to endpoint module 2021-01-10 19:22:50 +01:00
Koen Bolhuis 2d23b4cccf Implement more endpoints
- users/{user_list}/recent-listens
- user/{user_name}/playing-now
- user/{user_name}/listens
- latest-import
2021-01-10 18:02:05 +01:00
Koen Bolhuis d7b36ff18d Rename Submission to SubmitListens 2021-01-09 17:03:03 +01:00
Koen Bolhuis e82b685776 Initial commit 2021-01-09 04:36:14 +01:00