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

Commit 417d446

Browse files
committed
docs: Adds more docs
1 parent da04455 commit 417d446

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed

src/request/builder/account.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,36 @@ use request::DoRequest;
55
impl<'t> RequestBuilder<'t, response::Account> {
66
/// Returns a struct for making requests that send back "Action" objects. The `id` is the
77
/// action ID you'd like to retrieve from DigitalOcean
8+
///
9+
/// # Example
10+
///
11+
/// ```no_run
12+
/// # use doapi::DoManager;
13+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
14+
/// // ... domgr set up same as before
15+
/// match domgr.account().action("1234").retrieve() {
16+
/// Ok(action) => println!("Action: {}", action),
17+
/// Err(e) => println!("Error: {}", e)
18+
/// }
19+
/// ```
820
pub fn action(self, id: &str) -> RequestBuilder<'t, response::Action> {
921
// https://api.digitalocean.com/v2/actions/$ID
1022
RequestBuilder::new(self.auth, format!("https://api.digitalocean.com/v2/actions/{}", id))
1123
}
1224

25+
/// Returns a `Vec<Action>` for making requests that send back multiple "Action" objects.
26+
///
27+
/// # Example
28+
///
29+
/// ```no_run
30+
/// # use doapi::DoManager;
31+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
32+
/// // ... domgr set up same as before
33+
/// match domgr.account().action("1234").retrieve() {
34+
/// Ok(action) => println!("Action: {}", action),
35+
/// Err(e) => println!("Error: {}", e)
36+
/// }
37+
/// ```
1338
pub fn actions(self) -> RequestBuilder<'t, response::Actions> {
1439
// https://api.digitalocean.com/v2/actions
1540
RequestBuilder::new(self.auth, "https://api.digitalocean.com/v2/actions")

src/request/builder/dns.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use response;
88
use request::RequestBuilder;
99
use request::DoRequest;
1010

11+
/// Lists the types of supported DNS records
1112
doapi_enum! {
1213
#[derive(Debug)]
1314
pub enum DnsRecType {
@@ -27,14 +28,24 @@ doapi_enum! {
2728
// priority nullable number The priority of the host (for SRV and MX records. null otherwise). MX, SRV
2829
// port nullable number The port that the service is accessible on (for SRV records only. null otherwise). SRV
2930
// weight nullable number The weight of records with the same priority (for SRV records only. null otherwise). SRV
31+
/// A struct for creating a DNS Record
3032
#[derive(Serialize)]
3133
pub struct DnsRecord {
34+
/// The type of record (A, AAAA, MX, NS, etc.)
35+
///
36+
/// **NOTE:** You can use the `DnsRecType`'s implementation of `std::fmt::Display` to get a
37+
/// `String`
3238
#[serde(rename = "type")]
3339
pub rec_type: String,
40+
/// The name of the record (Required for: A, AAAA, CNAME, TXT, and SRV)
3441
pub name: Option<String>,
42+
/// The priority of the record (Required for: MX and SRV)
3543
pub priority: Option<u64>,
44+
/// The port of the record (Required for: SRV)
3645
pub port: Option<u64>,
46+
/// Various data used for record (Required for: A, AAAA, CNAME, MX, TXT, SRV, NS)
3747
pub data: Option<String>,
48+
/// The weight of the record (Required for: SRV)
3849
pub weight: Option<u64>,
3950
}
4051

@@ -78,6 +89,24 @@ impl fmt::Display for DnsRecord {
7889
}
7990

8091
impl<'t> RequestBuilder<'t, response::DnsRecords> {
92+
/// Returns a request that can be used to create a new DNS record. Returns a
93+
/// `doapi::response::DnsRecord` from DigitalOcean of the newly created record
94+
///
95+
/// # Example
96+
///
97+
/// ```no_run
98+
/// # use doapi::DoManager;
99+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
100+
/// // ... domgr set up same as before
101+
/// // ... assumes "record" is an instance of doapi::request::DnsRecord
102+
/// match domgr.domain("super.com")
103+
/// .dns_records()
104+
/// .create(&record)
105+
/// .retrieve() {
106+
/// Ok(dns_rec) => println!("Record: {}", dns_rec),
107+
/// Err(e) => println!("Error: {}", e)
108+
/// }
109+
/// ```
81110
pub fn create(self, rec: &DnsRecord) -> RequestBuilder<'t, response::DnsRecord> {
82111
// POST: "https://api.digitalocean.com/v2/domains/$DOMAIN/records"
83112
// body:
@@ -100,6 +129,24 @@ impl<'t> RequestBuilder<'t, response::DnsRecords> {
100129
}
101130

102131
impl<'t> RequestBuilder<'t, response::DnsRecord> {
132+
/// Returns a request that can be used to update an existing DNS record. Returns a
133+
/// `doapi::response::DnsRecord` from DigitalOcean of the updated created record
134+
///
135+
/// # Example
136+
///
137+
/// ```no_run
138+
/// # use doapi::DoManager;
139+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
140+
/// // ... domgr set up same as before
141+
/// // ... assumes "record" is an instance of doapi::request::DnsRecord
142+
/// match domgr.domain("super.com")
143+
/// .dns_record("1234")
144+
/// .update(&record)
145+
/// .retrieve() {
146+
/// Ok(dns_rec) => println!("Record: {}", dns_rec),
147+
/// Err(e) => println!("Error: {}", e)
148+
/// }
149+
/// ```
103150
pub fn update(self, record: &DnsRecord) -> RequestBuilder<'t, response::DnsRecord> {
104151
// PUT: "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$ID"
105152
// body:
@@ -118,6 +165,24 @@ impl<'t> RequestBuilder<'t, response::DnsRecord> {
118165
body: Some(json::to_string(record).ok().unwrap())
119166
}
120167
}
168+
169+
/// Returns a request that can be used to delete an existing DNS record. Returns a header with
170+
/// "status: 204 No Content" if successful
171+
///
172+
/// # Example
173+
///
174+
/// ```no_run
175+
/// # use doapi::DoManager;
176+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
177+
/// // ... domgr set up same as before
178+
/// match domgr.domain("super.com")
179+
/// .dns_record("1234")
180+
/// .delete()
181+
/// .retrieve() {
182+
/// Ok(_) => println!("Success"),
183+
/// Err(_) => println!("Error")
184+
/// }
185+
/// ```
121186
pub fn delete(self) -> RequestBuilder<'t, response::HeaderOnly> {
122187
// DELETE: "https://api.digitalocean.com/v2/domains/$id"
123188
RequestBuilder {

src/request/builder/domains.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ use request::RequestBuilder;
77
use request::DoRequest;
88

99
impl<'t> RequestBuilder<'t, response::Domains> {
10+
/// Returns a request that can be used to create a new domain.
11+
///
12+
/// # Example
13+
///
14+
/// ```no_run
15+
/// # use doapi::DoManager;
16+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
17+
/// // ... domgr set up same as before
18+
/// match domgr.domains()
19+
/// .create("super.com", "10.10.10.1")
20+
/// .retrieve() {
21+
/// Ok(domain) => println!("Domain: {}", domain),
22+
/// Err(e) => println!("Error: {}", e)
23+
/// }
24+
/// ```
1025
pub fn create(self, name: &str, ip: &str) -> RequestBuilder<'t, response::Domain> {
1126
// POST: "https://api.digitalocean.com/v2/domains"
1227
// body:
@@ -23,6 +38,22 @@ impl<'t> RequestBuilder<'t, response::Domains> {
2338
}
2439

2540
impl<'t> RequestBuilder<'t, response::Domain> {
41+
/// Returns a request that can be used to an existing domain. Returns a header with
42+
/// "status: 204 No Content" if successful
43+
///
44+
/// # Example
45+
///
46+
/// ```no_run
47+
/// # use doapi::DoManager;
48+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
49+
/// // ... domgr set up same as before
50+
/// match domgr.domain("super.com")
51+
/// .delete()
52+
/// .retrieve() {
53+
/// Ok(_) => println!("Success"),
54+
/// Err(_) => println!("Error")
55+
/// }
56+
/// ```
2657
pub fn delete(self) -> RequestBuilder<'t, response::HeaderOnly> {
2758
// DELETE: "https://api.digitalocean.com/v2/domains/$id"
2859
RequestBuilder {
@@ -33,12 +64,44 @@ impl<'t> RequestBuilder<'t, response::Domain> {
3364
body: None
3465
}
3566
}
67+
68+
/// Returns a request that can be used to list all domains, or perform domain tasks
69+
///
70+
/// # Example
71+
///
72+
/// ```no_run
73+
/// # use doapi::DoManager;
74+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
75+
/// // ... domgr set up same as before
76+
/// match domgr.domains()
77+
/// .create("super.com", "10.10.10.1")
78+
/// .retrieve() {
79+
/// Ok(domain) => println!("Domain: {}", domain),
80+
/// Err(e) => println!("Error: {}", e)
81+
/// }
82+
/// ```
3683
pub fn dns_records(mut self) -> RequestBuilder<'t, response::DnsRecords> {
3784
// GET: "https://api.digitalocean.com/v2/domains/$DOMAIN/records"
3885
self.url.push('/');
3986
self.url.push_str("records");
4087
RequestBuilder::new(self.auth, self.url)
4188
}
89+
90+
/// Returns a request that can be used to list a single domain, or perform tasks on a single
91+
/// domain
92+
///
93+
/// # Example
94+
///
95+
/// ```no_run
96+
/// # use doapi::DoManager;
97+
/// # let domgr = DoManager::with_auth("asfasdfasdf");
98+
/// // ... domgr set up same as before
99+
/// match domgr.domain("super.com")
100+
/// .retrieve() {
101+
/// Ok(domain) => println!("Domain: {}", domain),
102+
/// Err(e) => println!("Error: {}", e)
103+
/// }
104+
/// ```
42105
pub fn dns_record(mut self, id: &str) -> RequestBuilder<'t, response::DnsRecord> {
43106
// GET "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$ID"
44107
self.url.push('/');

0 commit comments

Comments
 (0)