Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add domain restore methods #379

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions lib/dnsimple/client/registrar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,49 @@ def transfer_domain_out(account_id, domain_name, options = {})
Dnsimple::Response.new(response, nil)
end

# Restores a domain.
#
# @see https://developer.dnsimple.com/v2/registrar/#restore
#
# @example Restore example.com:
# client.registrar.restore_domain(1010, "example.com", {})
#
# @param [Integer] account_id the account ID
# @param [#to_s] domain_name the domain name to renew
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# @param [#to_s] domain_name the domain name to renew
# @param [#to_s] domain_name the domain name to restore

# @param [Hash] attributes
# @param [Hash] options
# @return [Struct::DomainRestore]
#
# @raise [RequestError] When the request fails.
def restore_domain(account_id, domain_name, attributes = nil, options = {})
endpoint = Client.versioned("/%s/registrar/domains/%s/restores" % [account_id, domain_name])
response = client.post(endpoint, attributes, options)

Dnsimple::Response.new(response, Struct::DomainRestore.new(response["data"]))
end

# Retrieve the details of an existing domain restore.
#
# @see https://developer.dnsimple.com/v2/registrar/#getDomainRestore
#
# @example Retrieve the restore 42 for example.com:
# client.registrar.get_domain_restore(1010, "example.com", 42)
#
# @param [Integer] account_id the account ID
# @param [#to_s] domain_name the domain name
# @param [Integer] domain_restore_id the domain restore ID
# @param [Hash] options
# @return [Struct::DomainRestore]
#
# @raise [NotFoundError] When record is not found.
# @raise [RequestError] When the request fails.
def get_domain_restore(account_id, domain_name, domain_restore_id, options = {})
endpoint = Client.versioned("/%s/registrar/domains/%s/restores/%s" % [account_id, domain_name, domain_restore_id])
response = client.get(endpoint, options)

Dnsimple::Response.new(response, Struct::DomainRestore.new(response["data"]))
end

end
end
end
1 change: 1 addition & 0 deletions lib/dnsimple/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def initialize(attributes = {})
require_relative 'struct/domain_price'
require_relative 'struct/domain_push'
require_relative 'struct/domain_registration'
require_relative 'struct/domain_restore'
require_relative 'struct/domain_transfer'
require_relative 'struct/domain_renewal'
require_relative 'struct/dns_analytics'
Expand Down
24 changes: 24 additions & 0 deletions lib/dnsimple/struct/domain_restore.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module Dnsimple
module Struct
class DomainRestore < Base

# @return [Integer] The domain restore ID in DNSimple.
attr_accessor :id

# @return [Integer] The associated domain ID.
attr_accessor :domain_id

# @return [String] The state of the restore.
attr_accessor :state

# @return [String] When the domain restore was created in DNSimple.
attr_accessor :created_at

# @return [String] When the domain restore was last updated in DNSimple.
attr_accessor :updated_at

end
end
end
53 changes: 53 additions & 0 deletions spec/dnsimple/client/registrar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,57 @@
expect(result).to be_nil
end
end

describe "#restore_domain" do
let(:account_id) { 1010 }

before do
stub_request(:post, %r{/v2/#{account_id}/registrar/domains/.+/restores$})
.to_return(read_http_fixture("restoreDomain/success.http"))
end


it "builds the correct request" do
subject.restore_domain(account_id, domain_name = "example.com", {})

expect(WebMock).to have_requested(:post, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/restores")
.with(headers: { "Accept" => "application/json" })
end

it "returns the domain" do
response = subject.restore_domain(account_id, "example.com", {})
expect(response).to be_a(Dnsimple::Response)

result = response.data
expect(result).to be_a(Dnsimple::Struct::DomainRestore)
expect(result.id).to be_a(Integer)
expect(result.domain_id).to be_a(Integer)
end
end

describe "#get_domain_restore" do
let(:account_id) { 1010 }

before do
stub_request(:get, %r{/v2/#{account_id}/registrar/domains/.+/restores/.+$})
.to_return(read_http_fixture("getDomainRestore/success.http"))
end

it "builds the correct request" do
subject.get_domain_restore(account_id, domain_name = "example.com", restore_id = 361)

expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/registrar/domains/#{domain_name}/restores/#{restore_id}")
.with(headers: { "Accept" => "application/json" })
end

it "returns the domain restore" do
response = subject.get_domain_restore(account_id, "example.com", 361)
expect(response).to be_a(Dnsimple::Response)

result = response.data
expect(result).to be_a(Dnsimple::Struct::DomainRestore)
expect(result.id).to be_a(Integer)
expect(result.domain_id).to be_a(Integer)
end
end
end
20 changes: 20 additions & 0 deletions spec/fixtures.http/getDomainRestore/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
HTTP/1.1 201 Created
Server: nginx
Date: Fri, 09 Dec 2016 19:46:57 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2394
X-RateLimit-Reset: 1481315245
ETag: W/"179d85ea8a26a3d5dc76e42de2d7918e"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: ba6f2707-5df0-4ffa-b91b-51d4460bab8e
X-Runtime: 13.571302
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":{"id":1,"domain_id":999,"state":"restored","created_at":"2016-12-09T19:46:45Z","updated_at":"2016-12-12T19:46:45Z"}}
20 changes: 20 additions & 0 deletions spec/fixtures.http/restoreDomain/success.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
HTTP/1.1 201 Created
Server: nginx
Date: Fri, 09 Dec 2016 19:46:57 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2394
X-RateLimit-Reset: 1481315245
ETag: W/"179d85ea8a26a3d5dc76e42de2d7918e"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: ba6f2707-5df0-4ffa-b91b-51d4460bab8e
X-Runtime: 13.571302
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":{"id":1,"domain_id":999,"state":"new","created_at":"2016-12-09T19:46:45Z","updated_at":"2016-12-09T19:46:45Z"}}