removed some unused members; improved error handling
This commit is contained in:
parent
918036f2f8
commit
cb4611d02b
15
src/tags.rs
15
src/tags.rs
@ -7,15 +7,12 @@ use serde::Deserialize;
|
|||||||
struct ImageDetails {
|
struct ImageDetails {
|
||||||
architecture: String,
|
architecture: String,
|
||||||
os: String,
|
os: String,
|
||||||
size: i32,
|
size: usize,
|
||||||
last_pulled: String,
|
|
||||||
last_pushed: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Images {
|
pub struct Images {
|
||||||
images: Vec<ImageDetails>,
|
images: Vec<ImageDetails>,
|
||||||
last_updater_username: String,
|
|
||||||
#[serde(rename(deserialize = "name"))]
|
#[serde(rename(deserialize = "name"))]
|
||||||
pub tag_name: String,
|
pub tag_name: String,
|
||||||
last_updated: String,
|
last_updated: String,
|
||||||
@ -23,13 +20,13 @@ pub struct Images {
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Tags {
|
pub struct Tags {
|
||||||
count: i32,
|
// count: i32,
|
||||||
next_page: Option<String>,
|
next_page: Option<String>,
|
||||||
prev_page: Option<String>,
|
prev_page: Option<String>,
|
||||||
pub results: Vec<Images>,
|
pub results: Vec<Images>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Display)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
InvalidCharacter(char),
|
InvalidCharacter(char),
|
||||||
Fetching(String),
|
Fetching(String),
|
||||||
@ -48,20 +45,19 @@ impl fmt::Display for Error {
|
|||||||
|
|
||||||
impl Tags {
|
impl Tags {
|
||||||
pub fn new(repo: String) -> Result<Self, Error> {
|
pub fn new(repo: String) -> Result<Self, Error> {
|
||||||
// let repo = Self::check_repo(repo)?;
|
|
||||||
let request = format!("https://hub.docker.com/v2/repositories/{}/tags", repo);
|
let request = format!("https://hub.docker.com/v2/repositories/{}/tags", repo);
|
||||||
|
|
||||||
//get response
|
//get response
|
||||||
let res = match reqwest::blocking::get(request) {
|
let res = match reqwest::blocking::get(request) {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err(_) => return Err(Error::Fetching(String::from("reqwest error"))),
|
Err(e) => return Err(Error::Fetching(format!("reqwest error: {}", e))),
|
||||||
};
|
};
|
||||||
|
|
||||||
//convert it to json
|
//convert it to json
|
||||||
let raw = res.text().unwrap();
|
let raw = res.text().unwrap();
|
||||||
let tags: Self = match serde_json::from_str(&raw) {
|
let tags: Self = match serde_json::from_str(&raw) {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err(_) => return Err(Error::Converting(String::from("invalid json"))),
|
Err(e) => return Err(Error::Converting(format!("invalid json: {}", e))),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(tags)
|
Ok(tags)
|
||||||
@ -135,5 +131,6 @@ mod tests {
|
|||||||
check_neq("mysql", "mysql");
|
check_neq("mysql", "mysql");
|
||||||
check_err("nginxä");
|
check_err("nginxä");
|
||||||
check_err("nginx²");
|
check_err("nginx²");
|
||||||
|
check_eq("selim13/automysqlbackup", "selim13/automysqlbackup");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user