1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
use url::Url;
use super::sequence;
/// A refget client.
#[derive(Clone, Debug)]
pub struct Client {
http_client: reqwest::Client,
base_url: Url,
}
impl Client {
/// Creates a new refget client.
///
/// # Examples
///
/// ```
/// use noodles_refget as refget;
/// let client = refget::Client::new("https://localhost/".parse()?);
/// # Ok::<_, url::ParseError>(())
/// ```
pub fn new(base_url: Url) -> Self {
Self {
http_client: reqwest::Client::new(),
base_url,
}
}
/// Creates a refget client with the given HTTP client.
///
/// # Examples
///
/// ```
/// use noodles_refget as refget;
/// let http_client = reqwest::Client::new();
/// let base_url = "https://localhost/".parse()?;
/// let client = refget::Client::with_http_client(http_client, base_url);
/// # Ok::<_, url::ParseError>(())
/// ```
pub fn with_http_client(http_client: reqwest::Client, base_url: Url) -> Self {
Self {
http_client,
base_url,
}
}
pub(crate) fn http_client(&self) -> &reqwest::Client {
&self.http_client
}
pub(crate) fn base_url(&self) -> &Url {
&self.base_url
}
/// Creates a sequence request for the given ID.
///
/// # Examples
///
/// ```
/// use noodles_refget as refget;
/// let client = refget::Client::new("https://localhost/".parse()?);
/// let sequence_builder = client.sequence("d7eba311421bbc9d3ada44709dd61534");
/// # Ok::<_, url::ParseError>(())
/// ```
pub fn sequence<I>(&self, id: I) -> sequence::Builder
where
I: Into<String>,
{
sequence::Builder::new(self.clone(), id)
}
/// Creates a sequence metadata request for the given ID.
///
/// # Examples
///
/// ```
/// use noodles_refget as refget;
/// let client = refget::Client::new("https://localhost/".parse()?);
/// let sequence_builder = client.sequence_metadata("d7eba311421bbc9d3ada44709dd61534");
/// # Ok::<_, url::ParseError>(())
/// ```
pub fn sequence_metadata<I>(&self, id: I) -> sequence::metadata::Builder
where
I: Into<String>,
{
sequence::metadata::Builder::new(self.clone(), id)
}
/// Creates a service info request.
pub fn service_info(&self) -> sequence::service::Builder {
sequence::service::Builder::new(self.clone())
}
}