MB API requests as references
This commit is contained in:
parent
70e510a1de
commit
2d88e45d25
@ -62,7 +62,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.lookup_artist(request)
|
.lookup_artist(&request)
|
||||||
.expect("failed to make API call");
|
.expect("failed to make API call");
|
||||||
|
|
||||||
println!("{response:#?}");
|
println!("{response:#?}");
|
||||||
@ -72,7 +72,7 @@ fn main() {
|
|||||||
let request = LookupReleaseGroupRequest::new(&mbid);
|
let request = LookupReleaseGroupRequest::new(&mbid);
|
||||||
|
|
||||||
let response = client
|
let response = client
|
||||||
.lookup_release_group(request)
|
.lookup_release_group(&request)
|
||||||
.expect("failed to make API call");
|
.expect("failed to make API call");
|
||||||
|
|
||||||
println!("{response:#?}");
|
println!("{response:#?}");
|
||||||
|
@ -107,7 +107,7 @@ fn main() {
|
|||||||
println!("Query: {query}");
|
println!("Query: {query}");
|
||||||
|
|
||||||
let matches = client
|
let matches = client
|
||||||
.search_artist(query)
|
.search_artist(&query)
|
||||||
.expect("failed to make API call");
|
.expect("failed to make API call");
|
||||||
|
|
||||||
println!("{matches:#?}");
|
println!("{matches:#?}");
|
||||||
@ -139,7 +139,7 @@ fn main() {
|
|||||||
println!("Query: {query}");
|
println!("Query: {query}");
|
||||||
|
|
||||||
let matches = client
|
let matches = client
|
||||||
.search_release_group(query)
|
.search_release_group(&query)
|
||||||
.expect("failed to make API call");
|
.expect("failed to make API call");
|
||||||
|
|
||||||
println!("{matches:#?}");
|
println!("{matches:#?}");
|
||||||
|
8
src/external/musicbrainz/api/lookup.rs
vendored
8
src/external/musicbrainz/api/lookup.rs
vendored
@ -14,7 +14,7 @@ use super::{MbArtistMeta, MbReleaseGroupMeta, SerdeMbArtistMeta, SerdeMbReleaseG
|
|||||||
impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
|
impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
|
||||||
pub fn lookup_artist(
|
pub fn lookup_artist(
|
||||||
&mut self,
|
&mut self,
|
||||||
request: LookupArtistRequest,
|
request: &LookupArtistRequest,
|
||||||
) -> Result<LookupArtistResponse, Error> {
|
) -> Result<LookupArtistResponse, Error> {
|
||||||
let mut include: Vec<String> = vec![];
|
let mut include: Vec<String> = vec![];
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ impl<Http: IMusicBrainzHttp> MusicBrainzClient<Http> {
|
|||||||
|
|
||||||
pub fn lookup_release_group(
|
pub fn lookup_release_group(
|
||||||
&mut self,
|
&mut self,
|
||||||
request: LookupReleaseGroupRequest,
|
request: &LookupReleaseGroupRequest,
|
||||||
) -> Result<LookupReleaseGroupResponse, Error> {
|
) -> Result<LookupReleaseGroupResponse, Error> {
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{MB_BASE_URL}/release-group/{mbid}",
|
"{MB_BASE_URL}/release-group/{mbid}",
|
||||||
@ -177,7 +177,7 @@ mod tests {
|
|||||||
let mbid: Mbid = "00000000-0000-0000-0000-000000000000".try_into().unwrap();
|
let mbid: Mbid = "00000000-0000-0000-0000-000000000000".try_into().unwrap();
|
||||||
let mut request = LookupArtistRequest::new(&mbid);
|
let mut request = LookupArtistRequest::new(&mbid);
|
||||||
request.include_release_groups();
|
request.include_release_groups();
|
||||||
let result = client.lookup_artist(request).unwrap();
|
let result = client.lookup_artist(&request).unwrap();
|
||||||
|
|
||||||
assert_eq!(result, response);
|
assert_eq!(result, response);
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ mod tests {
|
|||||||
|
|
||||||
let mbid: Mbid = "00000000-0000-0000-0000-000000000000".try_into().unwrap();
|
let mbid: Mbid = "00000000-0000-0000-0000-000000000000".try_into().unwrap();
|
||||||
let request = LookupReleaseGroupRequest::new(&mbid);
|
let request = LookupReleaseGroupRequest::new(&mbid);
|
||||||
let result = client.lookup_release_group(request).unwrap();
|
let result = client.lookup_release_group(&request).unwrap();
|
||||||
|
|
||||||
assert_eq!(result, response);
|
assert_eq!(result, response);
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ mod tests {
|
|||||||
|
|
||||||
let query = SearchArtistRequest::new().string(name);
|
let query = SearchArtistRequest::new().string(name);
|
||||||
|
|
||||||
let matches = client.search_artist(query).unwrap();
|
let matches = client.search_artist(&query).unwrap();
|
||||||
assert_eq!(matches, response);
|
assert_eq!(matches, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
src/external/musicbrainz/api/search/mod.rs
vendored
2
src/external/musicbrainz/api/search/mod.rs
vendored
@ -27,7 +27,7 @@ macro_rules! impl_search_entity {
|
|||||||
paste! {
|
paste! {
|
||||||
pub fn [<search_ $name:snake>](
|
pub fn [<search_ $name:snake>](
|
||||||
&mut self,
|
&mut self,
|
||||||
query: [<Search $name Request>]
|
query: &[<Search $name Request>]
|
||||||
) -> Result<[<Search $name Response>], Error> {
|
) -> Result<[<Search $name Response>], Error> {
|
||||||
let query: String =
|
let query: String =
|
||||||
form_urlencoded::byte_serialize(format!("{query}").as_bytes()).collect();
|
form_urlencoded::byte_serialize(format!("{query}").as_bytes()).collect();
|
||||||
|
@ -161,7 +161,7 @@ mod tests {
|
|||||||
|
|
||||||
let query = SearchReleaseGroupRequest::new().string(title);
|
let query = SearchReleaseGroupRequest::new().string(title);
|
||||||
|
|
||||||
let matches = client.search_release_group(query).unwrap();
|
let matches = client.search_release_group(&query).unwrap();
|
||||||
assert_eq!(matches, response);
|
assert_eq!(matches, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ mod tests {
|
|||||||
.and()
|
.and()
|
||||||
.first_release_date(&date);
|
.first_release_date(&date);
|
||||||
|
|
||||||
let matches = client.search_release_group(query).unwrap();
|
let matches = client.search_release_group(&query).unwrap();
|
||||||
assert_eq!(matches, response);
|
assert_eq!(matches, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ mod tests {
|
|||||||
|
|
||||||
let query = SearchReleaseGroupRequest::new().rgid(&rgid);
|
let query = SearchReleaseGroupRequest::new().rgid(&rgid);
|
||||||
|
|
||||||
let matches = client.search_release_group(query).unwrap();
|
let matches = client.search_release_group(&query).unwrap();
|
||||||
assert_eq!(matches, response);
|
assert_eq!(matches, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
src/tui/lib/external/musicbrainz/api/mod.rs
vendored
8
src/tui/lib/external/musicbrainz/api/mod.rs
vendored
@ -41,7 +41,7 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
|
|||||||
fn lookup_artist(&mut self, mbid: &Mbid) -> Result<Lookup<ArtistMeta>, Error> {
|
fn lookup_artist(&mut self, mbid: &Mbid) -> Result<Lookup<ArtistMeta>, Error> {
|
||||||
let request = LookupArtistRequest::new(mbid);
|
let request = LookupArtistRequest::new(mbid);
|
||||||
|
|
||||||
let mb_response = self.client.lookup_artist(request)?;
|
let mb_response = self.client.lookup_artist(&request)?;
|
||||||
|
|
||||||
Ok(from_lookup_artist_response(mb_response))
|
Ok(from_lookup_artist_response(mb_response))
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
|
|||||||
fn lookup_release_group(&mut self, mbid: &Mbid) -> Result<Lookup<AlbumMeta>, Error> {
|
fn lookup_release_group(&mut self, mbid: &Mbid) -> Result<Lookup<AlbumMeta>, Error> {
|
||||||
let request = LookupReleaseGroupRequest::new(mbid);
|
let request = LookupReleaseGroupRequest::new(mbid);
|
||||||
|
|
||||||
let mb_response = self.client.lookup_release_group(request)?;
|
let mb_response = self.client.lookup_release_group(&request)?;
|
||||||
|
|
||||||
Ok(from_lookup_release_group_response(mb_response))
|
Ok(from_lookup_release_group_response(mb_response))
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
|
|||||||
fn search_artist(&mut self, artist: &ArtistMeta) -> Result<Vec<Match<ArtistMeta>>, Error> {
|
fn search_artist(&mut self, artist: &ArtistMeta) -> Result<Vec<Match<ArtistMeta>>, Error> {
|
||||||
let query = SearchArtistRequest::new().string(&artist.id.name);
|
let query = SearchArtistRequest::new().string(&artist.id.name);
|
||||||
|
|
||||||
let mb_response = self.client.search_artist(query)?;
|
let mb_response = self.client.search_artist(&query)?;
|
||||||
|
|
||||||
Ok(mb_response
|
Ok(mb_response
|
||||||
.artists
|
.artists
|
||||||
@ -82,7 +82,7 @@ impl<Http: IMusicBrainzHttp> IMusicBrainz for MusicBrainz<Http> {
|
|||||||
.and()
|
.and()
|
||||||
.release_group(&album.id.title);
|
.release_group(&album.id.title);
|
||||||
|
|
||||||
let mb_response = self.client.search_release_group(query)?;
|
let mb_response = self.client.search_release_group(&query)?;
|
||||||
|
|
||||||
Ok(mb_response
|
Ok(mb_response
|
||||||
.release_groups
|
.release_groups
|
||||||
|
Loading…
Reference in New Issue
Block a user