Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
feat: adds network response objects
Browse files Browse the repository at this point in the history
  • Loading branch information
kbknapp committed Jun 4, 2015
1 parent f972678 commit 49b225c
Show file tree
Hide file tree
Showing 17 changed files with 327 additions and 122 deletions.
126 changes: 126 additions & 0 deletions droplet
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{"droplets":
[{
"id":3193993,
"name":"neo",
"memory":512,
"vcpus":1,
"disk":20,
"locked":false,
"status":"active",
"kernel":{
"id":2233,
"name":"Ubuntu 14.04 x64 vmlinuz-3.13.0-37-generic",
"version":"3.13.0-37-generic"
},
"created_at":"2014-11-18T00:33:09Z",
"features":["virtio"],
"backup_ids":[],
"next_backup_window":null,
"snapshot_ids":[],
"image":{
"id":7518201,
"name":"GitLab 7.4.3 CE on 14.04",
"distribution":"Ubuntu",
"slug":null,
"public":false,
"regions":["nyc1","ams1","sfo1","nyc2","ams2","sgp1","lon1","nyc3","ams3","fra1"],
"created_at":"2014-11-03T23:32:54Z",
"min_disk_size":20,
"type":"snapshot"
},
"size":{
"slug":"512mb",
"memory":512,
"vcpus":1,
"disk":20,
"transfer":1.0,
"price_monthly":5.0,
"price_hourly":0.00744,
"regions":["nyc1","sgp1","ams1","sfo1","nyc2","lon1","nyc3","ams3","ams2","fra1"],
"available":true
},
"size_slug":"512mb",
"networks":{
"v4":[
{
"ip_address":"104.236.38.103",
"netmask":"255.255.192.0",
"gateway":"104.236.0.1",
"type":"public"
}
],
"v6":[]
},
"region":{
"name":"New York 3",
"slug":"nyc3",
"sizes":["32gb","16gb","2gb","1gb","4gb","8gb","512mb","64gb","48gb"],
"features":["private_networking","backups","ipv6","metadata"],
"available":true
}
},
{
"id":3920787,
"name":"wod",
"memory":512,
"vcpus":1,
"disk":20,
"locked":false,
"status":"active",
"kernel":{
"id":2134,
"name":"Ubuntu 14.04 x64 vmlinuz-3.13.0-36-generic",
"version":"3.13.0-36-generic"
},
"created_at":"2015-01-26T17:14:17Z",
"features":["virtio"],
"backup_ids":[],
"next_backup_window":null,
"snapshot_ids":[],
"image":{
"id":6732691,
"name":"LAMP on 14.04",
"distribution":"Ubuntu",
"slug":null,
"public":false,
"regions":["nyc1","ams1","sfo1","nyc2","ams2","sgp1","lon1","nyc3","ams3","fra1"],
"created_at":"2014-10-10T16:31:57Z",
"min_disk_size":20,
"type":"snapshot"
},
"size":{
"slug":"512mb",
"memory":512,
"vcpus":1,
"disk":20,
"transfer":1.0,
"price_monthly":5.0,
"price_hourly":0.00744,
"regions":["nyc1","sgp1","ams1","sfo1","nyc2","lon1","nyc3","ams3","ams2","fra1"],
"available":true
},
"size_slug":"512mb",
"networks":{
"v4":[
{
"ip_address":"104.236.254.57",
"netmask":"255.255.192.0",
"gateway":"104.236.192.1",
"type":"public"
}
],
"v6":[]
},
"region":{
"name":"New York 3",
"slug":"nyc3",
"sizes":["32gb","16gb","2gb","1gb","4gb","8gb","512mb","64gb","48gb"],
"features":["private_networking","backups","ipv6","metadata"],
"available":true
}
}],
"links":{},
"meta":{
"total":2
}
}
2 changes: 1 addition & 1 deletion src/request/builder/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'t, T> fmt::Display for RequestBuilder<'t, T> {
self.method,
self.auth,
if !self.url.is_empty() { self.url.clone() } else { "None".to_owned() },
if let Some(ref bdy) = self.body { format!("\n\t{}", bdy) } else { "None".to_owned() } )
if let Some(ref bdy) = self.body { format!("\n{}", bdy) } else { "None".to_owned() } )
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/response/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub struct Account {

impl fmt::Display for Account {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Email: {}\n\t\
Droplet Limit: {:.0}\n\t\
UUID: {}\n\t\
write!(f, "Email: {}\n\
Droplet Limit: {:.0}\n\
UUID: {}\n\
E-Mail Verified: {}",
self.email,
self.droplet_limit,
Expand Down
16 changes: 8 additions & 8 deletions src/response/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ pub struct Action {

impl fmt::Display for Action {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ID: {}\n\t\
Status: {}\n\t\
Type: {}\n\t\
Started At: {}\n\t\
Completed At: {}\n\t\
Resource ID: {}\n\t\
Resource Type: {}\n\t\
Region Slug: {}\n\t\
write!(f, "ID: {}\n\
Status: {}\n\
Type: {}\n\
Started At: {}\n\
Completed At: {}\n\
Resource ID: {}\n\
Resource Type: {}\n\
Region Slug: {}\n\
{}",
self.id,
self.status,
Expand Down
14 changes: 7 additions & 7 deletions src/response/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ pub struct Backup {

impl fmt::Display for Backup {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ID: {:.0}\n\t\
Name: {}\n\t\
Type:{}\n\t\
Distribution:{}\n\t\
Slug:{}\n\t\
Public:{}\n\t\
Regions:{}\n\t\
write!(f, "ID: {:.0}\n\
Name: {}\n\
Type:{}\n\
Distribution:{}\n\
Slug:{}\n\
Public:{}\n\
Regions:{}\n\
Minimum Disk Size: {:.0} MB\n",
self.id,
self.name,
Expand Down
6 changes: 3 additions & 3 deletions src/response/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub struct Domain {

impl fmt::Display for Domain {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Domain:\n\t\
name: {}\n\t\
ttl: {:.0}\n\t\
write!(f, "Domain:\n\
name: {}\n\
ttl: {:.0}\n\
Zone File: {}\n",
self.name,
self.ttl,
Expand Down
79 changes: 46 additions & 33 deletions src/response/droplet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use std::fmt;
use std::borrow::Cow;

use response::{Kernel, Region, Backup, Network, Image, Size, NamedResponse};
use response::{Kernel, Region, Backup, Networks, Image, Size, NamedResponse};

#[derive(Deserialize, Debug)]
pub struct Droplet {
Expand All @@ -30,40 +30,40 @@ pub struct Droplet {
vcpus: f64,
disk: f64,
locked: bool,
created_at: String,
status: String,
backup_ids: Vec<String>,
snapshot_ids: Vec<String>,
kernel: Option<Kernel>,
created_at: String,
features: Vec<String>,
region: Region,
backup_ids: Vec<Option<String>>,
next_backup_window: Option<Backup>,
snapshot_ids: Vec<Option<String>>,
image: Image,
region: Region,
size: Size,
size_slug: String,
networks: Network,
kernel: Option<Kernel>,
next_backup_window: Option<Backup>
networks: Networks,
}

impl fmt::Display for Droplet {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ID: {:.0}\n\t\
Name: {}\n\t\
Memory: {} MB\n\t\
Virtual CPUs: {:.0}\n\t\
Disk: {} GB\n\t\
Locked: {}\n\t\
Created At: {}\n\t\
Status: {}\n\t\
Backup IDs: {}\n\t\
Snapshot IDs: {}\n\t\
Features: {}\n\t\
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\t\
Size Slug: {}\n\
Network: \n\t{}\n\
Kernel: {}\
Next Backup Window: {}",
Kernel: \n\t{}\n\
Next Backup Window: {}\n",
self.id,
self.name,
self.memory,
Expand All @@ -72,23 +72,36 @@ impl fmt::Display for Droplet {
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\t{}\n", k)
format!("{}", &k.to_string()[..].replace("\n","\n\t"))
} else {
"None\n\t".to_owned()
"None".to_owned()
},
if let Some(ref k) = self.next_backup_window {
format!("\n\t{}\n", k)
format!("{}", &k.to_string()[..].replace("\n","\n\t"))
} else {
"None\n".to_owned()
"None".to_owned()
})

}
Expand Down
22 changes: 11 additions & 11 deletions src/response/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ use response::NamedResponse;
pub struct Image {
id: f64,
name: String,
#[serde(rename = "type")]
image_type: String,
distribution: String,
slug: Option<String>,
public: bool,
created_at: String,
regions: Vec<String>,
created_at: String,
min_disk_size: f64,
#[serde(rename = "type")]
image_type: String,
}

impl fmt::Display for Image {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "ID: {:.0}\n\t\
Name: {}\n\t\
Type: {}\n\t\
Distribution: ${}\n\t\
Slug: ${}\n\t\
Public: {} MB\n\t\
Regions: {}\n\t\
Minimum Disk Size: {} GB\n",
write!(f, "ID: {:.0}\n\
Name: {}\n\
Type: {}\n\
Distribution: {}\n\
Slug: {}\n\
Public: {} MB\n\
Regions: {}\n\
Minimum Disk Size: {} GB",
self.id,
self.name,
self.image_type,
Expand Down
9 changes: 7 additions & 2 deletions src/response/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ use response::NamedResponse;

#[derive(Deserialize, Debug)]
pub struct Kernel {
pub id: String,
pub id: f64,
pub name: String,
pub version: String,
}

impl fmt::Display for Kernel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", "kernel!")
write!(f, "ID: {:.0}\n\
Name: {}\n\
Version:{}",
self.id,
self.name,
self.version)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use self::links::Links;
pub use self::meta::Meta;
pub use self::namedresponse::NamedResponse;
pub use self::neighbors::Neighbors;
pub use self::network::Network;
pub use self::network::{Networks, Network};
pub use self::page::{Pages, RawPagedResponse, NewIter};
pub use self::region::{Regions, Region};
pub use self::size::{Sizes, Size};
Expand Down
Loading

0 comments on commit 49b225c

Please sign in to comment.