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
use api::error::MtgApiErrorKind;
use failure::Error;
use failure::ResultExt;
use reqwest::Client;
use std::rc::Weak;
use api::response::ApiResponse;
use api::util;
pub struct FormatApi {
client: Weak<Client>,
url: String,
}
impl FormatApi {
pub(crate) fn new(client: Weak<Client>, url: String) -> FormatApi {
FormatApi { client, url }
}
#[allow(dead_code)]
pub fn all(&self) -> Result<ApiResponse<Vec<String>>, Error> {
let url = [&self.url, "/formats"].join("");
let mut response = util::send_response(&url, &self.client)?;
let body = response.text().context(MtgApiErrorKind::BodyReadError)?;
let formats = util::retrieve_formats_from_body(&body)?;
Ok(ApiResponse::new(formats, response.headers()))
}
}