Skip to content

Commit

Permalink
Merge c7b06d7 into efb842e
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jan 7, 2019
2 parents efb842e + c7b06d7 commit 4de67c9
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/dnsimple/client/registrar_whois_privacy.rb
Expand Up @@ -62,6 +62,26 @@ def disable_whois_privacy(account_id, domain_name, options = {})
Dnsimple::Response.new(response, Struct::WhoisPrivacy.new(response["data"]))
end

# Renews whois privacy for the domain.
#
# @see https://developer.dnsimple.com/v2/registrar/whois-privacy/#renew
#
# @example Renew whois privacy for "example.com":
# client.registrar.renew_whois_privacy(1010, "example.com")
#
# @param [Integer] account_id the account ID
# @param [#to_s] domain_name The domain name to check.
# @param [Hash] options
# @return [Struct::WhoisPrivacy]
#
# @raise [RequestError] When the request fails.
def renew_whois_privacy(account_id, domain_name, options = {})
endpoint = whois_privacy_endpoint(account_id, domain_name) + "/renewals"
response = client.post(endpoint, nil, options)

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


private

Expand Down
1 change: 1 addition & 0 deletions lib/dnsimple/struct.rb
Expand Up @@ -40,6 +40,7 @@ def initialize(attributes = {})
require_relative 'struct/user'
require_relative 'struct/vanity_name_server'
require_relative 'struct/whois_privacy'
require_relative 'struct/whois_privacy_order'
require_relative 'struct/zone'
require_relative 'struct/zone_file'
require_relative 'struct/zone_distribution'
Expand Down
28 changes: 28 additions & 0 deletions lib/dnsimple/struct/whois_privacy_order.rb
@@ -0,0 +1,28 @@
module Dnsimple
module Struct

class WhoisPrivacyOrder < Base
# @return [Integer] The associated domain ID.
attr_accessor :domain_id

# @return [Integer] The associated WHOIS Privacy ID.
attr_accessor :whois_privacy_id

# @return [String] The WHOIS Privacy order state.
attr_accessor :state

# @return [Boolean] Whether the WHOIS Privacy is enabled for the domain.
attr_accessor :enabled

# @return [String] The date the WHOIS Privacy will expire on.
attr_accessor :expires_on

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

# @return [String] When the WHOIS Privacy was last updated in DNSimple.
attr_accessor :updated_at
end

end
end
55 changes: 55 additions & 0 deletions spec/dnsimple/client/registrar_whois_privacy_spec.rb
Expand Up @@ -116,4 +116,59 @@
end
end


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

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

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

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

it "returns the whois privacy order" do
response = subject.renew_whois_privacy(account_id, "example.com")
expect(response).to be_a(Dnsimple::Response)

result = response.data
expect(result).to be_a(Dnsimple::Struct::WhoisPrivacyOrder)
expect(result.domain_id).to be_kind_of(Integer)
expect(result.whois_privacy_id).to be_kind_of(Integer)
expect(result.enabled).to be(true)
expect(result.expires_on).to be_kind_of(String)
end

context "when whois privacy was't previously purchased" do
before do
stub_request(:post, %r{/v2/#{account_id}/registrar/domains/.+/whois_privacy/renewals$})
.to_return(read_http_fixture("renewWhoisPrivacy/whois-privacy-was-not-found.http"))
end

it "raises error" do
expect do
subject.renew_whois_privacy(account_id, "example.com")
end.to raise_error(Dnsimple::RequestError, "WHOIS privacy not found for example.com")
end
end

context "when there is already a whois privacy renewal order in progress" do
before do
stub_request(:post, %r{/v2/#{account_id}/registrar/domains/.+/whois_privacy/renewals$})
.to_return(read_http_fixture("renewWhoisPrivacy/duplicated-order.http"))
end

it "raises error" do
expect do
subject.renew_whois_privacy(account_id, "example.com")
end.to raise_error(Dnsimple::RequestError, "The whois privacy for example.com has just been renewed, a new renewal cannot be started at this time")
end
end
end

end
17 changes: 17 additions & 0 deletions spec/fixtures.http/renewWhoisPrivacy/duplicated-order.http
@@ -0,0 +1,17 @@
HTTP/1.1 400
server: nginx
date: Fri, 21 Dec 2018 16:21:31 GMT
content-type: application/json; charset=utf-8
x-ratelimit-limit: 2400
x-ratelimit-remaining: 2398
x-ratelimit-reset: 1545411828
cache-control: no-cache
x-request-id: 762d810d-a42c-4b1b-9382-9f56e5a339ff
x-runtime: 0.141307
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-download-options: noopen
x-permitted-cross-domain-policies: none

{"message":"The whois privacy for example.com has just been renewed, a new renewal cannot be started at this time","errors":{}}
19 changes: 19 additions & 0 deletions spec/fixtures.http/renewWhoisPrivacy/success.http
@@ -0,0 +1,19 @@
HTTP/1.1 200
server: nginx
date: Fri, 21 Dec 2018 14:10:06 GMT
content-type: application/json; charset=utf-8
x-ratelimit-limit: 2400
x-ratelimit-remaining: 2397
x-ratelimit-reset: 1545404617
etag: W/"23030fb7c68d7b7da22a374b5f1b1743"
cache-control: max-age=0, private, must-revalidate
x-request-id: 0c31a341-8078-4851-b232-d0f3819910c8
x-runtime: 2.015707
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-download-options: noopen
x-permitted-cross-domain-policies: none
strict-transport-security: max-age=31536000

{"data":{"id":9,"domain_id":35879,"whois_privacy_id":478,"state":"new","expires_on":"2018-12-27","enabled":true,"created_at":"2018-12-21T14:10:04Z","updated_at":"2018-12-21T14:10:04Z"}}
@@ -0,0 +1,17 @@
HTTP/1.1 400
server: nginx
date: Mon, 07 Jan 2019 13:58:34 GMT
content-type: application/json; charset=utf-8
x-ratelimit-limit: 2400
x-ratelimit-remaining: 2399
x-ratelimit-reset: 1546873114
cache-control: no-cache
x-request-id: 5a43c5f0-4900-4563-ae9d-bd4a996312fa
x-runtime: 0.066139
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
x-download-options: noopen
x-permitted-cross-domain-policies: none

{"message":"WHOIS privacy not found for example.com","errors":{}}

0 comments on commit 4de67c9

Please sign in to comment.