@@ -8,6 +8,7 @@ use response;
88use request:: RequestBuilder ;
99use request:: DoRequest ;
1010
11+ /// Lists the types of supported DNS records
1112doapi_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 ) ]
3133pub 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
8091impl < ' 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
102131impl < ' 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 {
0 commit comments