diff --git a/src/request/builder/arrays.rs b/src/request/builder/arrays.rs index 600091c..fa40c52 100644 --- a/src/request/builder/arrays.rs +++ b/src/request/builder/arrays.rs @@ -11,6 +11,7 @@ impl response::NamedResponse for String { "".into() } } + impl<'t> DoRequest for RequestBuilder<'t, response::ResponseStringArray> { #[allow(unused_variables)] fn retrieve_obj(&self, obj: String) -> Result { @@ -37,4 +38,33 @@ impl<'t> DoRequest for RequestBuilder<'t, respons } } } -} \ No newline at end of file +} + +impl<'t> DoRequest for RequestBuilder<'t, response::Neighbors> {} +// impl<'t> DoRequest for RequestBuilder<'t, response::Neighbors> { +// #[allow(unused_variables)] +// fn retrieve_obj(&self, obj: String) -> Result { +// debug!("Inside retrieve_obj() of ResponseStringArray"); +// debug!("Retrieveing JSON"); +// match self.retrieve_json() { +// Ok(ref s) => { +// debug!("Success"); +// debug!("Retrieving Value"); +// match json::from_str::(s) { +// Ok(ob) => { +// debug!("Success"); +// Ok(ob) +// }, +// Err(e) => { +// debug!("Failed"); +// Err(e.to_string()) +// } +// } +// }, +// Err(e) => { +// debug!("Failed"); +// Err(e.to_string()) +// } +// } +// } +// } \ No newline at end of file diff --git a/src/response/neighbors.rs b/src/response/neighbors.rs index 4d2109a..296350f 100644 --- a/src/response/neighbors.rs +++ b/src/response/neighbors.rs @@ -2,55 +2,51 @@ use std::fmt; use std::borrow::Cow; -use response::{self, Kernel, Region, Backup, Network, Image, Size, NamedResponse}; - -pub type Neighbors = Vec; +use response::{Kernel, Region, Backup, Networks, Image, Size, NamedResponse}; +// Have to duplicate Droplet because of lack of negative trait bounds #[derive(Deserialize, Debug)] -pub struct Neighbor { +pub struct DropletNeighbor { id: f64, name: String, memory: f64, vcpus: f64, disk: f64, locked: bool, - created_at: String, status: String, - backup_ids: Vec, - snapshot_ids: Vec, + kernel: Option, + created_at: String, features: Vec, - region: Region, + backup_ids: Vec>, + next_backup_window: Option, + snapshot_ids: Vec>, image: Image, + region: Region, size: Size, size_slug: String, - networks: Network, - kernel: Option, - next_backup_window: Option + networks: Networks, } -impl response::NotArray for Neighbor {} - -impl fmt::Display for Neighbor { +impl fmt::Display for DropletNeighbor { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Droplet:\n\ - ID: {:.0}\n\ - Name: {}\n\ - Memory: {} MB\n\ - Virtual CPUs: {:.0}\n\ - Disk: {} GB\n\ - Locked: {}\n\ - Created At: {}\n\ - Status: {}\n\ - Backup IDs: {}\n\ - Snapshot IDs: {}\n\ - Features: {}\n\ - Droplet: \n{}\n\ - Image: \n{}\n\ - Size: \n{}\n\ - Size Slug: {}\n\ - Network: \n{}\n\ - Kernel: {}\ - Next Backup Window: {}", + write!(f, "ID: {:.0}\n\ + Name: {}\n\ + Memory: {} MB\n\ + Virtual CPUs: {:.0}\n\ + Disk: {} GB\n\ + Locked: {}\n\ + Created At: {}\n\ + Status: {}\n\ + Backup IDs: {}\n\ + Snapshot IDs: {}\n\ + Features: {}\n\ + Region: \n\t{}\n\ + Image: \n\t{}\n\ + Size: \n\t{}\n\ + Size Slug: {}\n\ + Network: \n\t{}\n\ + Kernel: \n\t{}\n\ + Next Backup Window: {}\n", self.id, self.name, self.memory, @@ -59,30 +55,47 @@ impl fmt::Display for Neighbor { self.locked, self.created_at, self.status, - self.backup_ids.iter().fold(String::new(), |acc, s| acc + &format!(" {},", s)[..]), - self.snapshot_ids.iter().fold(String::new(), |acc, s| acc + &format!(" {},", s)[..]), - self.features.iter().fold(String::new(), |acc, s| acc + &format!(" {},", s)[..]), - self.region, - self.image, - self.size, + self.backup_ids.iter() + .filter_map(|n| if n.is_some() { + Some(n.clone().unwrap().to_string()) + }else{ + None + }) + .fold(String::new(), |acc, s| acc + &format!(" {},", s)[..]), + self.snapshot_ids.iter() + .filter_map(|n| if n.is_some() { + Some(n.clone().unwrap().to_string()) + }else{ + None + }) + .fold(String::new(), |acc, s| acc + &format!(" {},", s)[..]), + self.features.iter() + .fold(String::new(), |acc, s| acc + &format!(" {},", s)[..]), + &self.region.to_string()[..].replace("\n","\n\t"), + &self.image.to_string()[..].replace("\n","\n\t"), + &self.size.to_string()[..].replace("\n","\n\t"), self.size_slug, - self.networks, + &self.networks.to_string()[..].replace("\n","\n\t"), if let Some(ref k) = self.kernel { - format!("\n{}\n", k) + format!("{}", &k.to_string()[..].replace("\n","\n\t")) } else { - "None\n".to_owned() + "None".to_owned() }, if let Some(ref k) = self.next_backup_window { - format!("\n{}\n", k) + format!("{}", &k.to_string()[..].replace("\n","\n\t")) } else { - "None\n".to_owned() + "None".to_owned() }) } } +pub type Neighbor = Vec; + impl NamedResponse for Neighbor { fn name<'a>() -> Cow<'a, str> { "neighbor".into() } -} \ No newline at end of file +} + +pub type Neighbors = Vec;