Skip to content

Commit

Permalink
Domain transfer lock API (#50)
Browse files Browse the repository at this point in the history
This PR introduces 3 new endpoints that are part of the domain transfer lock API that is introduced in dnsimple/dnsimple-developer#519.

The following endpoints have been added:
- **getDomainTransferLock**: GET `/{account}/registrar/domains/{domain}/transfer_lock`
- **enableDomainTransferLock**: POST `/{account}/registrar/domains/{domain}/transfer_lock`
- **disableDomainTransferLock**: DELETE `/{account}/registrar/domains/{domain}/transfer_lock`

Belongs to dnsimple/dnsimple-business#1728
Belongs to https://github.com/dnsimple/dnsimple-external-integrations/issues/18
  • Loading branch information
DXTimer authored Dec 28, 2023
1 parent 720f788 commit 553e6cb
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/dnsimple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 70 additions & 0 deletions src/dnsimple/registrar_transfer_lock.rs
Original file line number Diff line number Diff line change
@@ -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<DNSimpleResponse<TransferLock>, DNSimpleError> {
let path = format!("/{}/registrar/domains/{}/transfer_lock", account_id, domain);

self.client
.post::<DomainTransferLockEndpoint>(&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<DNSimpleResponse<TransferLock>, DNSimpleError> {
let path = format!("/{}/registrar/domains/{}/transfer_lock", account_id, domain);

self.client
.delete_with_response::<DomainTransferLockEndpoint>(&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<DNSimpleResponse<TransferLock>, DNSimpleError> {
let path = format!("/{}/registrar/domains/{}/transfer_lock", account_id, domain);

self.client.get::<DomainTransferLockEndpoint>(&path, None)
}
}
20 changes: 20 additions & 0 deletions tests/fixtures/v2/api/disableDomainTransferLock/success.http
Original file line number Diff line number Diff line change
@@ -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}}
20 changes: 20 additions & 0 deletions tests/fixtures/v2/api/enableDomainTransferLock/success.http
Original file line number Diff line number Diff line change
@@ -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}}
20 changes: 20 additions & 0 deletions tests/fixtures/v2/api/getDomainTransferLock/success.http
Original file line number Diff line number Diff line change
@@ -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}}
68 changes: 68 additions & 0 deletions tests/registrar_transfer_lock_test.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 553e6cb

Please sign in to comment.