From b4a2a91d653b01f5c07f454b349fb995f2c15dc0 Mon Sep 17 00:00:00 2001 From: "Michael Ziminsky (Z)" Date: Sun, 4 Dec 2022 11:54:40 -0700 Subject: [PATCH] Make release optional in API wrapper Fixes #10 --- src/lib.rs | 4 ++-- src/wrapper.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c1481fd..d6585bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ //! client.authenticate("LISTENBRAINZ TOKEN") //! .expect("Could not authenticate with ListenBrainz"); //! -//! client.playing_now("The Beatles", "Here Comes the Sun", "Abbey Road") +//! client.playing_now("The Beatles", "Here Comes the Sun", Some("Abbey Road")) //! .expect("Could not submit 'playing now' request"); //! ``` //! @@ -34,7 +34,7 @@ //! client.authenticate("MALOJA API KEY") //! .expect("Could not authenticate with Maloja"); //! -//! client.listen("Lymbyc Systym", "Split Stones", "Split Stones") +//! client.listen("Lymbyc Systym", "Split Stones", None) //! .expect("Could not submit listen"); //! ``` //! diff --git a/src/wrapper.rs b/src/wrapper.rs index 9d5be33..fc3ca23 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -89,7 +89,7 @@ impl ListenBrainz { timestamp: Option, artist: &str, track: &str, - release: &str, + release: Option<&str>, ) -> Result<(), Error> { if !self.is_authenticated() { return Err(Error::NotAuthenticated); @@ -100,7 +100,7 @@ impl ListenBrainz { track_metadata: TrackMetadata { artist_name: artist, track_name: track, - release_name: Some(release), + release_name: release, additional_info: None, }, }; @@ -125,7 +125,7 @@ impl ListenBrainz { /// If not authenticated, returns [`Error::NotAuthenticated`]. /// Otherwise, see the Errors section of [`Client`] for more info on /// what errors might occur. - pub fn listen(&self, artist: &str, track: &str, release: &str) -> Result<(), Error> { + pub fn listen(&self, artist: &str, track: &str, release: Option<&str>) -> Result<(), Error> { let now = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() @@ -144,7 +144,7 @@ impl ListenBrainz { /// If not authenticated, returns [`Error::NotAuthenticated`]. /// Otherwise, see the Errors section of [`Client`] for more info on /// what errors might occur. - pub fn import(&self, artist: &str, track: &str, release: &str, timestamp: i64) -> Result<(), Error> { + pub fn import(&self, artist: &str, track: &str, release: Option<&str>, timestamp: i64) -> Result<(), Error> { self.submit_listen(ListenType::Import, Some(timestamp), artist, track, release) } @@ -155,7 +155,7 @@ impl ListenBrainz { /// If not authenticated, returns [`Error::NotAuthenticated`]. /// Otherwise, see the Errors section of [`Client`] for more info on /// what errors might occur. - pub fn playing_now(&self, artist: &str, track: &str, release: &str) -> Result<(), Error> { + pub fn playing_now(&self, artist: &str, track: &str, release: Option<&str>) -> Result<(), Error> { self.submit_listen(ListenType::PlayingNow, None, artist, track, release) } }