Browse Source

fix a few things due to api changes

Steven Jacobs 8 months ago
parent
commit
16b514eab0
4 changed files with 47 additions and 49 deletions
  1. 1 1
      Cargo.toml
  2. 36 0
      src/image.rs
  3. 2 1
      src/lib.rs
  4. 8 47
      src/linode.rs

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "linode"
-version = "0.1.0"
+version = "0.2.0"
 authors = ["Steven Jacobs <stjacobs@fastmail.fm>"]
 
 [dependencies]

+ 36 - 0
src/image.rs

@@ -0,0 +1,36 @@
+pub mod images {
+    use helper;
+
+    #[derive(Debug, Deserialize)]
+    pub struct Image {
+        pub created: String,
+        pub id: String,
+        // TODO: created with chrono and serde
+        // pub created: DateTime<UTC>,
+        pub label: String,
+        pub size: u32,
+        pub deprecated: bool,
+        pub description: String,
+        pub vendor: String
+    }
+
+    #[derive(Debug, Deserialize)]
+    struct ResponseImages {
+        page: u32,
+        results: u32,
+        data: Vec<Image>,
+        pages: u32,
+    }
+
+    pub fn list() -> Vec<Image> {
+        let mut res = helper::gen_request("get", "images");
+        let results: ResponseImages = res.json().expect("Can't parse API data");
+        results.data
+    }
+
+    pub fn get(id: String) -> Image {
+        let path = format!("images/{}", id);
+        let mut res = helper::gen_request("get", path.as_str());
+        res.json().expect("Can't parse API data")
+    }
+}

+ 2 - 1
src/lib.rs

@@ -7,7 +7,8 @@ extern crate serde_derive;
 
 mod helper;
 pub mod linode;
+pub mod image;
 
-pub use linode::distributions;
 pub use linode::instances;
 pub use linode::types;
+pub use image::images;

+ 8 - 47
src/linode.rs

@@ -1,39 +1,3 @@
-pub mod distributions {
-    use helper;
-
-    #[derive(Debug, Deserialize)]
-    pub struct Distribution {
-        pub id: String,
-        // TODO: created with chrono and serde
-        // pub created: DateTime<UTC>,
-        pub label: String,
-        pub minimum_storage_size: u32,
-        pub deprecated: bool,
-        pub vendor: String,
-        pub x64: bool,
-    }
-
-    #[derive(Debug, Deserialize)]
-    struct ResponseDistributions {
-        page: u32,
-        total_results: u32,
-        distributions: Vec<Distribution>,
-        total_pages: u32,
-    }
-
-    pub fn index() -> Vec<Distribution> {
-        let mut res = helper::gen_request("get", "linode/distributions");
-        let results: ResponseDistributions = res.json().expect("Can't parse API data");
-        results.distributions
-    }
-
-    pub fn get(id: String) -> Distribution {
-        let path = format!("linode/distributions/{}", id);
-        let mut res = helper::gen_request("get", path.as_str());
-        res.json().expect("Can't parse API data")
-    }
-}
-
 pub mod instances {
     use helper;
 
@@ -74,31 +38,28 @@ pub mod types {
 
     #[derive(Debug, Deserialize)]
     pub struct Type {
-        pub ram: u32,
+        pub memory: u32,
         pub class: String,
-        pub backups_price: u32,
-        pub storage: u32,
+        pub disk: u32,
         pub label: String,
-        pub monthly_price: u32,
-        pub hourly_price: u32,
         pub vcpus: u32,
         pub transfer: u32,
-        pub mbits_out: u32,
+        pub network_out: u32,
         pub id: String,
     }
 
     #[derive(Debug, Deserialize)]
     struct ResponseTypes {
         page: u32,
-        total_results: u32,
-        types: Vec<Type>,
-        total_pages: u32,
+        results: u32,
+        data: Vec<Type>,
+        pages: u32,
     }
 
-    pub fn index() -> Vec<Type> {
+    pub fn list() -> Vec<Type> {
         let mut res = helper::gen_request("get", "linode/types");
         let results: ResponseTypes = res.json().expect("Can't parse API data");
-        results.types
+        results.data
     }
 
     pub fn get(id: String) -> Type {