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
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
use response;
use request::RequestBuilder;

/// The main structure through which all calls are made. This holds a slice of the AUTH TOKEN
pub struct DoManager<'t> {
    auth: &'t str,
}

impl<'t> DoManager<'t> {
    /// Creates a new instance of `DoManager` with a string slice of your AUTH TOKEN
    pub fn with_token(token: &'t str) -> DoManager<'t> {
        DoManager {
            auth: token
        }
    }

    /// Returns a request that can be used to view account information.     
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.account()
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn account(&self) -> RequestBuilder<'t, response::Account> {
        RequestBuilder::new(self.auth, "https://api.digitalocean.com/v2/account")
    }

    /// Returns a request that can be used to list all regions
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.regions()
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn regions(&self) -> RequestBuilder<'t, response::Regions> {
        RequestBuilder::new(self.auth, "https://api.digitalocean.com/v2/regions")
    }

    /// Returns a request that can be used to list all available sizes
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.sizes()
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn sizes(&self) -> RequestBuilder<'t, response::Sizes> {
        RequestBuilder::new(self.auth, "https://api.digitalocean.com/v2/sizes")
    }

    /// Returns a request that can be used gain additional requests for a particular image
    ///
    /// **NOTE**: `id` may either be an image ID, or slug
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// // Or domgr.image("some slug")
    /// match domgr.image("1234")
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn image(&self, id: &str) -> RequestBuilder<'t, response::Image> {
        RequestBuilder::new(self.auth, format!("https://api.digitalocean.com/v2/images/{}", id))
    }

    /// Returns a request that can be used to view all available images, or actions on multiple     
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.images()
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn images(&self) -> RequestBuilder<'t, response::Images> {
        RequestBuilder::new(self.auth, "https://api.digitalocean.com/v2/images")
    }

    /// Returns a request that can be used to view all SSH keys or actions on multiple keys
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.ssh_keys()
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn ssh_keys(&self) -> RequestBuilder<'t, response::SshKeys> {
        RequestBuilder::new(self.auth, "https://api.digitalocean.com/v2/account/keys")
    }

    /// Returns a request that can be used to view a single SSH key, or actions that apply to only
    /// one key
    ///
    /// **NOTE**: `id` may either be an image ID, or slug
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// // or domgr.ssh_key("some finger print")
    /// match domgr.ssh_key("1234")
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn ssh_key(&self, id: &str) -> RequestBuilder<'t, response::SshKey> {
        RequestBuilder::new(self.auth, format!("https://api.digitalocean.com/v2/account/keys/{}", id))
    }


    /// Returns a request that can be used to view a single droplet, or actions that only apply to
    /// one droplet
    ///
    /// **NOTE**: `id` may either be an image ID, or slug
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.droplet("1234")
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn droplet(&self, id: &str) -> RequestBuilder<'t, response::Droplet> {
        RequestBuilder::new(self.auth, format!("https://api.digitalocean.com/v2/droplets/{}", id))
    }

    /// Returns a request that can be used to view all available droplets, or actions that apply to
    /// multiple droplets
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.droplets()
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn droplets(&self) -> RequestBuilder<'t, response::Droplets> {
        RequestBuilder::new(self.auth, "https://api.digitalocean.com/v2/droplets")
    }

    /// Returns a request that can be used to view all domains, or actions that apply to multiple
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.domains()
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn domains(&self) -> RequestBuilder<'t, response::Domains> {
        RequestBuilder::new(self.auth, "https://api.digitalocean.com/v2/domains")
    }

    /// Returns a request that can be used to view a single domain, or actions that apply to only 
    /// one
    ///
    /// # Example
    ///
    /// ```no_run
    /// # use doapi::DoManager;
    /// # use doapi::DoRequest;
    /// let domgr = DoManager::with_token("asfasdfasdf");
    /// match domgr.domain("super.com")
    ///            .retrieve() {
    ///     Ok(_)  => println!("Success"),
    ///     Err(_) => println!("Error")
    /// }
    /// ```
    pub fn domain(&self, name: &str) -> RequestBuilder<'t, response::Domain> {
        RequestBuilder::new(self.auth, format!("https://api.digitalocean.com/v2/domains/{}", name))
    }
}