diff --git a/CHANGELOG.md b/CHANGELOG.md index 402c658..30c6636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ This project uses [Semantic Versioning 2.0.0](http://semver.org/). ## main +FEATURES: + +- NEW: Added `Registrar::enable_domain_transfer_lock` to enable the domain transfer lock for a domain. (#50) +- NEW: Added `Registrar::disable_domain_transfer_lock` to disable the domain transfer lock for a domain. (#50) +- NEW: Added `Registrar::get_domain_transfer_lock` to get the domain transfer lock status for a domain. (#50) + ## 0.6.0 ENHANCEMENTS: diff --git a/src/dnsimple.rs b/src/dnsimple.rs index 2420ede..a9dd9a1 100644 --- a/src/dnsimple.rs +++ b/src/dnsimple.rs @@ -33,6 +33,7 @@ pub mod oauth; pub mod registrar; pub mod registrar_auto_renewal; pub mod registrar_name_servers; +pub mod registrar_transfer_lock; pub mod registrar_whois_privacy; pub mod services; pub mod templates; diff --git a/src/dnsimple/registrar_transfer_lock.rs b/src/dnsimple/registrar_transfer_lock.rs new file mode 100644 index 0000000..c7f8ff3 --- /dev/null +++ b/src/dnsimple/registrar_transfer_lock.rs @@ -0,0 +1,70 @@ +use crate::dnsimple::registrar::Registrar; +use crate::dnsimple::{DNSimpleResponse, Endpoint}; +use crate::errors::DNSimpleError; +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +/// Represents Transfer Lock status for a domain +#[derive(Debug, Deserialize, Serialize)] +pub struct TransferLock { + /// True if domain transfer is locked, otherwise false + pub enabled: bool, +} + +struct DomainTransferLockEndpoint; + +impl Endpoint for DomainTransferLockEndpoint { + type Output = TransferLock; +} + +impl Registrar<'_> { + /// Enable domain transfer lock + /// + /// # Arguments + /// + /// `account_id`: The account ID + /// `domain`: The domain name or id + pub fn enable_domain_transfer_lock( + &self, + account_id: u64, + domain: String, + ) -> Result, DNSimpleError> { + let path = format!("/{}/registrar/domains/{}/transfer_lock", account_id, domain); + + self.client + .post::(&path, Value::Null) + } + + /// Disable domain transfer lock + /// + /// # Arguments + /// + /// `account_id`: The account ID + /// `domain`: The domain name or id + pub fn disable_domain_transfer_lock( + &self, + account_id: u64, + domain: String, + ) -> Result, DNSimpleError> { + let path = format!("/{}/registrar/domains/{}/transfer_lock", account_id, domain); + + self.client + .delete_with_response::(&path) + } + + /// Get domain transfer lock status + /// + /// # Arguments + /// + /// `account_id`: The account ID + /// `domain`: The domain name or id + pub fn get_domain_transfer_lock( + &self, + account_id: u64, + domain: String, + ) -> Result, DNSimpleError> { + let path = format!("/{}/registrar/domains/{}/transfer_lock", account_id, domain); + + self.client.get::(&path, None) + } +} diff --git a/tests/fixtures/v2/api/disableDomainTransferLock/success.http b/tests/fixtures/v2/api/disableDomainTransferLock/success.http new file mode 100644 index 0000000..d562c1e --- /dev/null +++ b/tests/fixtures/v2/api/disableDomainTransferLock/success.http @@ -0,0 +1,20 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Tue, 15 Aug 2023 09:58:37 GMT +Content-Type: application/json; charset=utf-8 +Connection: keep-alive +X-RateLimit-Limit: 2400 +X-RateLimit-Remaining: 2398 +X-RateLimit-Reset: 1488538623 +ETag: W/"fc2368a31a1b6a3afcca33bb37ff6b9d" +Cache-Control: max-age=0, private, must-revalidate +X-Request-Id: 8b0fe49a-c810-4552-84ab-a1cd9b4a7786 +X-Runtime: 0.024780 +X-Content-Type-Options: nosniff +X-Download-Options: noopen +X-Frame-Options: DENY +X-Permitted-Cross-Domain-Policies: none +X-XSS-Protection: 1; mode=block +Strict-Transport-Security: max-age=31536000 + +{"data":{"enabled":false}} diff --git a/tests/fixtures/v2/api/enableDomainTransferLock/success.http b/tests/fixtures/v2/api/enableDomainTransferLock/success.http new file mode 100644 index 0000000..e90c83c --- /dev/null +++ b/tests/fixtures/v2/api/enableDomainTransferLock/success.http @@ -0,0 +1,20 @@ +HTTP/1.1 201 Created +Server: nginx +Date: Tue, 15 Aug 2023 09:58:37 GMT +Content-Type: application/json; charset=utf-8 +Connection: keep-alive +X-RateLimit-Limit: 2400 +X-RateLimit-Remaining: 2398 +X-RateLimit-Reset: 1488538623 +ETag: W/"fc2368a31a1b6a3afcca33bb37ff6b9d" +Cache-Control: max-age=0, private, must-revalidate +X-Request-Id: 8b0fe49a-c810-4552-84ab-a1cd9b4a7786 +X-Runtime: 0.024780 +X-Content-Type-Options: nosniff +X-Download-Options: noopen +X-Frame-Options: DENY +X-Permitted-Cross-Domain-Policies: none +X-XSS-Protection: 1; mode=block +Strict-Transport-Security: max-age=31536000 + +{"data":{"enabled":true}} diff --git a/tests/fixtures/v2/api/getDomainTransferLock/success.http b/tests/fixtures/v2/api/getDomainTransferLock/success.http new file mode 100644 index 0000000..f93ffb3 --- /dev/null +++ b/tests/fixtures/v2/api/getDomainTransferLock/success.http @@ -0,0 +1,20 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Tue, 15 Aug 2023 09:58:37 GMT +Content-Type: application/json; charset=utf-8 +Connection: keep-alive +X-RateLimit-Limit: 2400 +X-RateLimit-Remaining: 2398 +X-RateLimit-Reset: 1488538623 +ETag: W/"fc2368a31a1b6a3afcca33bb37ff6b9d" +Cache-Control: max-age=0, private, must-revalidate +X-Request-Id: 8b0fe49a-c810-4552-84ab-a1cd9b4a7786 +X-Runtime: 0.024780 +X-Content-Type-Options: nosniff +X-Download-Options: noopen +X-Frame-Options: DENY +X-Permitted-Cross-Domain-Policies: none +X-XSS-Protection: 1; mode=block +Strict-Transport-Security: max-age=31536000 + +{"data":{"enabled":true}} diff --git a/tests/registrar_transfer_lock_test.rs b/tests/registrar_transfer_lock_test.rs new file mode 100644 index 0000000..c8c3852 --- /dev/null +++ b/tests/registrar_transfer_lock_test.rs @@ -0,0 +1,68 @@ +use crate::common::setup_mock_for; +mod common; + +#[test] +fn enable_domain_transfer_lock_test() { + let setup = setup_mock_for( + "/1385/registrar/domains/example.com/transfer_lock", + "enableDomainTransferLock/success", + "POST", + ); + let client = setup.0; + let account_id = 1385; + let domain = "example.com"; + + let response = client + .registrar() + .enable_domain_transfer_lock(account_id, String::from(domain)) + .unwrap(); + let transfer_lock = response.data.unwrap(); + + assert_eq!(response.status, 201); + + assert!(transfer_lock.enabled); +} + +#[test] +fn disable_domain_transfer_lock_test() { + let setup = setup_mock_for( + "/1385/registrar/domains/example.com/transfer_lock", + "disableDomainTransferLock/success", + "DELETE", + ); + let client = setup.0; + let account_id = 1385; + let domain = "example.com"; + + let response = client + .registrar() + .disable_domain_transfer_lock(account_id, String::from(domain)) + .unwrap(); + let transfer_lock = response.data.unwrap(); + + assert_eq!(response.status, 200); + + assert!(!transfer_lock.enabled); +} + +#[test] +fn get_domain_transfer_lock_test() { + let setup = setup_mock_for( + "/1385/registrar/domains/example.com/transfer_lock", + "getDomainTransferLock/success", + "GET", + ); + let client = setup.0; + let account_id = 1385; + let domain = "example.com"; + + let response = client + .registrar() + .get_domain_transfer_lock(account_id, String::from(domain)) + .unwrap(); + let transfer_lock = response.data.unwrap(); + + assert_eq!(response.status, 200); + + assert!(transfer_lock.enabled); +}