-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
7 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
tests/fixtures/v2/api/disableDomainTransferLock/success.http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
tests/fixtures/v2/api/enableDomainTransferLock/success.http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |