Change all Client methods from &mut self to &self

This commit is contained in:
Koen Bolhuis 2021-01-14 23:48:27 +01:00
parent 8780a3231f
commit 6309a544ef
10 changed files with 29 additions and 29 deletions

View File

@ -7,7 +7,7 @@ fn main() {
let listened_at = args.next().expect("No listened_at provided"); let listened_at = args.next().expect("No listened_at provided");
let recording_msid = args.next().expect("No recording_msid provided"); let recording_msid = args.next().expect("No recording_msid provided");
let mut client = Client::new(); let client = Client::new();
let delete = DeleteListen { let delete = DeleteListen {
listened_at: listened_at.parse().unwrap(), listened_at: listened_at.parse().unwrap(),

View File

@ -1,7 +1,7 @@
use listenbrainz::Client; use listenbrainz::Client;
fn main() { fn main() {
let mut client = Client::new(); let client = Client::new();
let result = client.stats_sitewide_artists(None, None, Some("year")); let result = client.stats_sitewide_artists(None, None, Some("year"));
println!("{:#?}", result); println!("{:#?}", result);

View File

@ -13,7 +13,7 @@ fn now() -> i64 {
fn main() { fn main() {
let token = std::env::args().nth(1).expect("No token provided"); let token = std::env::args().nth(1).expect("No token provided");
let mut client = Client::new(); let client = Client::new();
// Submit single // Submit single

View File

@ -3,7 +3,7 @@ use listenbrainz::Client;
fn main() { fn main() {
let user_name = std::env::args().nth(1).expect("No username provided"); let user_name = std::env::args().nth(1).expect("No username provided");
let mut client = Client::new(); let client = Client::new();
let result = client.stats_user_listening_activity(&user_name, None); let result = client.stats_user_listening_activity(&user_name, None);
println!("{:#?}", result); println!("{:#?}", result);

View File

@ -3,7 +3,7 @@ use listenbrainz::Client;
fn main() { fn main() {
let user_name = std::env::args().nth(1).expect("No username provided"); let user_name = std::env::args().nth(1).expect("No username provided");
let mut client = Client::new(); let client = Client::new();
let result = client.stats_user_artist_map(&user_name, None, None); let result = client.stats_user_artist_map(&user_name, None, None);
println!("{:#?}", result); println!("{:#?}", result);

View File

@ -3,7 +3,7 @@ use listenbrainz::Client;
fn main() { fn main() {
let user_name = std::env::args().nth(1).expect("No username provided"); let user_name = std::env::args().nth(1).expect("No username provided");
let mut client = Client::new(); let client = Client::new();
let result = client.user_listen_count(&user_name); let result = client.user_listen_count(&user_name);
println!("Listen count: {:#?}", result); println!("Listen count: {:#?}", result);

View File

@ -5,7 +5,7 @@ fn main() {
let subject = args.next().expect("No subject provided"); let subject = args.next().expect("No subject provided");
let user_name = args.next().expect("No username provided"); let user_name = args.next().expect("No username provided");
let mut client = Client::new(); let client = Client::new();
match subject.as_str() { match subject.as_str() {
"recordings" => { "recordings" => {

View File

@ -4,7 +4,7 @@ fn main() {
let users: Vec<String> = std::env::args().skip(1).collect(); let users: Vec<String> = std::env::args().skip(1).collect();
let users_ref: Vec<&str> = users.iter().map(String::as_str).collect(); let users_ref: Vec<&str> = users.iter().map(String::as_str).collect();
let mut client = Client::new(); let client = Client::new();
let result = client.users_recent_listens(&users_ref); let result = client.users_recent_listens(&users_ref);
println!("{:#?}", result); println!("{:#?}", result);

View File

@ -3,7 +3,7 @@ use listenbrainz::Client;
fn main() { fn main() {
let token = std::env::args().nth(1).expect("No token provided"); let token = std::env::args().nth(1).expect("No token provided");
let mut client = Client::new(); let client = Client::new();
let result = client.validate_token(&token); let result = client.validate_token(&token);
println!("{:#?}", result); println!("{:#?}", result);

View File

@ -26,7 +26,7 @@ impl Client {
} }
} }
fn get<R: DeserializeOwned>(&mut self, endpoint: Endpoint) -> Result<R, Error> { fn get<R: DeserializeOwned>(&self, endpoint: Endpoint) -> Result<R, Error> {
let endpoint = format!("{}{}", API_ROOT_URL, endpoint); let endpoint = format!("{}{}", API_ROOT_URL, endpoint);
self.agent self.agent
@ -37,7 +37,7 @@ impl Client {
} }
fn get_stats<R: DeserializeOwned>( fn get_stats<R: DeserializeOwned>(
&mut self, &self,
endpoint: Endpoint, endpoint: Endpoint,
count: Option<u64>, count: Option<u64>,
offset: Option<u64>, offset: Option<u64>,
@ -67,7 +67,7 @@ impl Client {
} }
} }
fn post<D, R>(&mut self, endpoint: Endpoint, token: &str, data: D) -> Result<R, Error> fn post<D, R>(&self, endpoint: Endpoint, token: &str, data: D) -> Result<R, Error>
where where
D: Serialize, D: Serialize,
R: DeserializeOwned, R: DeserializeOwned,
@ -86,7 +86,7 @@ impl Client {
/// Endpoint: [`submit-listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-submit-listens) /// Endpoint: [`submit-listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-submit-listens)
pub fn submit_listens( pub fn submit_listens(
&mut self, &self,
token: &str, token: &str,
data: SubmitListens, data: SubmitListens,
) -> Result<SubmitListensResponse, Error> { ) -> Result<SubmitListensResponse, Error> {
@ -94,7 +94,7 @@ impl Client {
} }
/// Endpoint: [`validate-token`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-validate-token) /// Endpoint: [`validate-token`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-validate-token)
pub fn validate_token(&mut self, token: &str) -> Result<ValidateTokenResponse, Error> { pub fn validate_token(&self, token: &str) -> Result<ValidateTokenResponse, Error> {
let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::ValidateToken); let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::ValidateToken);
self.agent self.agent
@ -107,7 +107,7 @@ impl Client {
/// Endpoint: [`delete-listen`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-delete-listen) /// Endpoint: [`delete-listen`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-delete-listen)
pub fn delete_listen( pub fn delete_listen(
&mut self, &self,
token: &str, token: &str,
data: DeleteListen, data: DeleteListen,
) -> Result<DeleteListenResponse, Error> { ) -> Result<DeleteListenResponse, Error> {
@ -116,25 +116,25 @@ impl Client {
/// Endpoint: [`users/{user_list}/recent-listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-users-(user_list)-recent-listens) /// Endpoint: [`users/{user_list}/recent-listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-users-(user_list)-recent-listens)
pub fn users_recent_listens( pub fn users_recent_listens(
&mut self, &self,
user_list: &[&str], user_list: &[&str],
) -> Result<UsersRecentListensResponse, Error> { ) -> Result<UsersRecentListensResponse, Error> {
self.get(Endpoint::UsersRecentListens(user_list)) self.get(Endpoint::UsersRecentListens(user_list))
} }
/// Endpoint: [`user/{user_name}/listen-count`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-listen-count) /// Endpoint: [`user/{user_name}/listen-count`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-listen-count)
pub fn user_listen_count(&mut self, user_name: &str) -> Result<UserListenCountResponse, Error> { pub fn user_listen_count(&self, user_name: &str) -> Result<UserListenCountResponse, Error> {
self.get(Endpoint::UserListenCount(user_name)) self.get(Endpoint::UserListenCount(user_name))
} }
/// Endpoint: [`user/{user_name}/playing-now`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-playing-now) /// Endpoint: [`user/{user_name}/playing-now`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-playing-now)
pub fn user_playing_now(&mut self, user_name: &str) -> Result<UserPlayingNowResponse, Error> { pub fn user_playing_now(&self, user_name: &str) -> Result<UserPlayingNowResponse, Error> {
self.get(Endpoint::UserPlayingNow(user_name)) self.get(Endpoint::UserPlayingNow(user_name))
} }
/// Endpoint: [`user/{user_name}/listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-listens) /// Endpoint: [`user/{user_name}/listens`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-user-(user_name)-listens)
pub fn user_listens( pub fn user_listens(
&mut self, &self,
user_name: &str, user_name: &str,
min_ts: Option<i64>, min_ts: Option<i64>,
max_ts: Option<i64>, max_ts: Option<i64>,
@ -162,7 +162,7 @@ impl Client {
} }
/// Endpoint: [`latest-import`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-latest-import) (`GET`) /// Endpoint: [`latest-import`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-latest-import) (`GET`)
pub fn get_latest_import(&mut self, user_name: &str) -> Result<GetLatestImportResponse, Error> { pub fn get_latest_import(&self, user_name: &str) -> Result<GetLatestImportResponse, Error> {
let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::LatestImport); let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::LatestImport);
self.agent self.agent
@ -175,7 +175,7 @@ impl Client {
/// Endpoint: [`latest-import`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-latest-import) (`POST`) /// Endpoint: [`latest-import`](https://listenbrainz.readthedocs.io/en/production/dev/api/#post--1-latest-import) (`POST`)
pub fn update_latest_import( pub fn update_latest_import(
&mut self, &self,
token: &str, token: &str,
data: UpdateLatestImport, data: UpdateLatestImport,
) -> Result<UpdateLatestImportResponse, Error> { ) -> Result<UpdateLatestImportResponse, Error> {
@ -184,7 +184,7 @@ impl Client {
/// Endpoint: [`stats/sitewide/artists`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-sitewide-artists) /// Endpoint: [`stats/sitewide/artists`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-sitewide-artists)
pub fn stats_sitewide_artists( pub fn stats_sitewide_artists(
&mut self, &self,
count: Option<u64>, count: Option<u64>,
offset: Option<u64>, offset: Option<u64>,
range: Option<&str>, range: Option<&str>,
@ -194,7 +194,7 @@ impl Client {
/// Endpoint: [`stats/user/{user_name}/listening-activity`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-listening-activity) /// Endpoint: [`stats/user/{user_name}/listening-activity`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-listening-activity)
pub fn stats_user_listening_activity( pub fn stats_user_listening_activity(
&mut self, &self,
user_name: &str, user_name: &str,
range: Option<&str>, range: Option<&str>,
) -> Result<Option<StatsUserListeningActivityResponse>, Error> { ) -> Result<Option<StatsUserListeningActivityResponse>, Error> {
@ -222,7 +222,7 @@ impl Client {
/// Endpoint: [`stats/user/{user_name}/daily-activity`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-daily-activity) /// Endpoint: [`stats/user/{user_name}/daily-activity`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-daily-activity)
pub fn stats_user_daily_activity( pub fn stats_user_daily_activity(
&mut self, &self,
user_name: &str, user_name: &str,
range: Option<&str>, range: Option<&str>,
) -> Result<Option<StatsUserDailyActivityResponse>, Error> { ) -> Result<Option<StatsUserDailyActivityResponse>, Error> {
@ -250,7 +250,7 @@ impl Client {
/// Endpoint: [`stats/user/{user_name}/recordings`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-recordings) /// Endpoint: [`stats/user/{user_name}/recordings`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-recordings)
pub fn stats_user_recordings( pub fn stats_user_recordings(
&mut self, &self,
user_name: &str, user_name: &str,
count: Option<u64>, count: Option<u64>,
offset: Option<u64>, offset: Option<u64>,
@ -266,7 +266,7 @@ impl Client {
/// Endpoint: [`stats/user/{user_name}/artist-map`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-artist-map) /// Endpoint: [`stats/user/{user_name}/artist-map`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-artist-map)
pub fn stats_user_artist_map( pub fn stats_user_artist_map(
&mut self, &self,
user_name: &str, user_name: &str,
range: Option<&str>, range: Option<&str>,
force_recalculate: Option<bool>, force_recalculate: Option<bool>,
@ -291,7 +291,7 @@ impl Client {
/// Endpoint: [`stats/user/{user_name}/releases`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-releases) /// Endpoint: [`stats/user/{user_name}/releases`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-releases)
pub fn stats_user_releases( pub fn stats_user_releases(
&mut self, &self,
user_name: &str, user_name: &str,
count: Option<u64>, count: Option<u64>,
offset: Option<u64>, offset: Option<u64>,
@ -302,7 +302,7 @@ impl Client {
/// Endpoint: [`stats/user/{user_name}/artists`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-artists) /// Endpoint: [`stats/user/{user_name}/artists`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-stats-user-(user_name)-artists)
pub fn stats_user_artists( pub fn stats_user_artists(
&mut self, &self,
user_name: &str, user_name: &str,
count: Option<u64>, count: Option<u64>,
offset: Option<u64>, offset: Option<u64>,
@ -313,7 +313,7 @@ impl Client {
/// Endpoint: [`status/get-dump-info`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-status-get-dump-info) /// Endpoint: [`status/get-dump-info`](https://listenbrainz.readthedocs.io/en/production/dev/api/#get--1-status-get-dump-info)
pub fn status_get_dump_info( pub fn status_get_dump_info(
&mut self, &self,
id: Option<i64>, id: Option<i64>,
) -> Result<StatusGetDumpInfoResponse, Error> { ) -> Result<StatusGetDumpInfoResponse, Error> {
let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::StatusGetDumpInfo); let endpoint = format!("{}{}", API_ROOT_URL, Endpoint::StatusGetDumpInfo);