Commit 2705a467 authored by Leonardo Schwarz's avatar Leonardo Schwarz

Convert artist to new entity API

parent 80b3c02f
......@@ -12,7 +12,7 @@ use xpath_reader::reader::{FromXml, Reader};
use std::time::{Duration, Instant};
use std::thread::sleep;
use crate::search::{ArtistSearchBuilder, ReleaseGroupSearchBuilder, SearchBuilder};
use crate::search::{ReleaseGroupSearchBuilder, SearchBuilder};
mod error;
pub(crate) use self::error::check_response_error;
......@@ -200,12 +200,12 @@ impl Client {
/// Returns a search builder to search for an area.
pub fn search_area<'cl>(&'cl mut self) -> AreaSearchBuilder<'cl> {
AreaSearchBuilder::new(self)
}*/
}
/// Returns a search biulder to search for an artist.
pub fn search_artist<'cl>(&'cl mut self) -> ArtistSearchBuilder<'cl> {
ArtistSearchBuilder::new(self)
}
}*/
/// Returns a search builder to search for a release group.
pub fn search_release_group<'cl>(&'cl mut self) -> ReleaseGroupSearchBuilder<'cl> {
......
use xpath_reader::{FromXml, Reader};
use xpath_reader::{FromXml, FromXmlOptional, Reader};
use crate::entities::Language;
enum_mb_xml_optional!(
pub enum AliasType {
var SearchHint = "Search hint",
var ArtistName = "Artist name",
var LegalName = "Legal name",
}
);
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Alias {
type_: String,
sort_name: String,
name: String,
locale: Option<Language>,
primary: bool,
pub(crate) alias_type: Option<AliasType>,
pub(crate) sort_name: String,
pub(crate) name: String,
pub(crate) locale: Option<Language>,
pub(crate) primary: bool,
}
impl FromXml for Alias {
fn from_xml<'d>(reader: &'d Reader<'d>) -> Result<Self, xpath_reader::Error> {
let primary: Option<String> = reader.read(".//@primary")?;
let lang: Option<String> = reader.read(".//@locale")?;
let locale = match lang {
Some(l) => Some(
Language::from_639_1(l.as_ref()).map_err(|e| xpath_reader::Error::custom_err(e))?,
),
None => None,
};
Ok(Alias {
type_: reader.read(".//@type")?,
alias_type: reader.read(".//@type")?,
sort_name: reader.read(".//@sort-name")?,
name: reader.read(".//text()")?,
locale: reader.read(".//@locale")?,
locale,
primary: primary == Some("primary".into()),
})
}
}
impl Alias {
pub fn name(&self) -> &String {
&self.name
}
}
......@@ -49,9 +49,7 @@ pub struct AreaResponse {
mbid: Mbid,
name: String,
sort_name: String,
area_type: AreaType,
iso_3166: Option<String>,
}
......@@ -102,7 +100,7 @@ impl Resource for Area {
const NAME: &'static str = "area";
fn request(options: &Self::Options) -> Request {
fn request(_: &Self::Options) -> Request {
Request {
name: "area".to_string(),
include: "".to_string(),
......
This diff is collapsed.
......@@ -14,7 +14,7 @@ impl Language {
pub fn from_639_1(code: &str) -> Result<Language, Error> {
Ok(Language {
inner: IsoLang::from_639_1(code)
.ok_or_else(|| Error::parse_error(format!("Invalid ISO 639-1 code: {}", code)))?,
.ok_or_else(|| Error::parse_error(format!("Invalid ISO 639-1 code: '{}'", code)))?,
})
}
......@@ -24,7 +24,7 @@ impl Language {
pub fn from_639_3(code: &str) -> Result<Language, Error> {
Ok(Language {
inner: IsoLang::from_639_3(code)
.ok_or_else(|| Error::parse_error(format!("Invalid ISO 639-3 code: {}", code)))?,
.ok_or_else(|| Error::parse_error(format!("Invalid ISO 639-3 code: '{}'", code)))?,
})
}
......
......@@ -28,9 +28,9 @@ mod series;
// mod track
// mod url
// mod work
pub use self::alias::Alias;
pub use self::alias::{Alias, AliasType};
pub use self::area::{Area, AreaType};
pub use self::artist::{Artist, ArtistType, Gender};
pub use self::artist::{Artist, ArtistType, ArtistOptions, Gender};
pub use self::event::{Event, EventType};
pub use self::label::Label;
pub use self::place::{Coordinates, Place, PlaceType};
......
......@@ -161,12 +161,12 @@ macro_rules! ref_fetch_full_old
}
ref_fetch_full!(
ReleaseRef, crate::entities::Release, crate::entities::ReleaseOptions;
AreaRef, crate::entities::Area, ()
AreaRef, crate::entities::Area, ();
ArtistRef, crate::entities::Artist, crate::entities::ArtistOptions;
ReleaseRef, crate::entities::Release, crate::entities::ReleaseOptions
);
ref_fetch_full_old!(
ArtistRef, crate::entities::Artist;
LabelRef, crate::entities::Label;
RecordingRef, crate::entities::Recording
);
......@@ -150,7 +150,7 @@ define_search_builder!(
"area-list"
);
*/
/*
define_search_builder!(
ArtistSearchBuilder,
ArtistSearchField,
......@@ -158,7 +158,7 @@ define_search_builder!(
full_entities::Artist,
"artist-list"
);
*/
/* TODO
define_search_builder!(
ReleaseSearchBuilder,
......
......@@ -14,7 +14,7 @@ pub trait SearchEntity {
/// The full entity that is refered by this search entity.
type FullEntity: ResourceOld + FromXml;
/// Fetch the full entity from the API.
/// Fetch the full entity from the API.2
fn fetch_full(&self, client: &mut Client) -> Result<Self::FullEntity, Error>;
}
......@@ -29,17 +29,17 @@ impl SearchEntity for Area {
Ok(self.to_owned())
}
}
*/
pub use self::full_entities::Artist;
pub use self::full_entities::ArtistResponse;
impl SearchEntity for Artist {
type FullEntity = Artist;
impl SearchEntity for ArtistResponse {
type FullEntity = ArtistResponse;
fn fetch_full(&self, _: &mut Client) -> Result<Self::FullEntity, Error> {
Ok(self.to_owned())
}
}
*/
pub struct Release {
pub mbid: Mbid,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment