Commit 6eaa0e35 authored by Leonardo Schwarz's avatar Leonardo Schwarz

fetch_full for ref entities

parent d4fece54
......@@ -12,7 +12,7 @@ mod lang;
pub use self::lang::Language;
pub mod refs;
pub use self::refs::{AreaRef, ArtistRef, LabelRef, RecordingRef, ReleaseRef};
pub use self::refs::{AreaRef, ArtistRef, LabelRef, RecordingRef, ReleaseRef, FetchFull};
mod area;
mod artist;
......@@ -72,7 +72,6 @@ pub trait Resource {
/// Base url of the entity, e. g. `"https://musicbrainz.org/ws/2/artist/"`.
///
/// These are used for building search requests.
///
/// TODO: Consider moving this to the search code.
fn base_url() -> String
{
......
//! This module contains structs for types we call *reference types* in this
//! library.
//!
//! These types only contain some basic data but reference a full entity in the
//! MusicBrainz
//! database which can be retrieved.
//! Reference entities holding some basic information about an entity and
//! pointing to a full entity.
// TODO: Better documentation in this file.
// TODO: When writing the API interfacing code, provide some form of helpers so
// the full referenced
// types corresponding to these ref types can be easily retrieved from
// the server.
use std::time::Duration;
use xpath_reader::{FromXml, FromXmlError, XpathReader};
......@@ -19,6 +11,15 @@ use entities::Mbid;
use entities::date::PartialDate;
use entities::release::ReleaseStatus;
use client::Client;
use errors::ClientError;
pub trait FetchFull {
type Full;
fn fetch_full(&self, client: &mut Client) -> Result<Self::Full, ClientError>;
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct AreaRef {
pub mbid: Mbid,
......@@ -42,10 +43,6 @@ impl FromXml for AreaRef {
}
}
/// A small variation of `Artist` which is used only to refer to an actual
/// artist entity from other
/// entities.
/// TODO: new docstring
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ArtistRef {
pub mbid: Mbid,
......@@ -135,3 +132,29 @@ impl FromXml for ReleaseRef {
})
}
}
macro_rules! ref_fetch_full
{
($($ref:ty, $full:ty);+)
=>
{
$(
impl FetchFull for $ref {
type Full = $full;
fn fetch_full(&self, client: &mut Client) -> Result<Self::Full, ClientError>
{
client.get_by_mbid(&self.mbid)
}
}
)+
}
}
ref_fetch_full!(
AreaRef, ::entities::Area;
ArtistRef, ::entities::Artist;
LabelRef, ::entities::Label;
RecordingRef, ::entities::Recording;
ReleaseRef, ::entities::Release
);
......@@ -33,6 +33,8 @@ pub struct Series {
/// Any additional free form annotation for this `Series`.
pub annotation: Option<String>,
// TODO parse work rels
}
impl FromXmlContained for Series {}
......@@ -59,7 +61,7 @@ impl Resource for Series {
fn get_incs() -> &'static str
{
"annotation+aliases"
"annotation+aliases+work-rels"
}
}
......
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