-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Dnsimple | ||
class Client | ||
module RegistrarAutoRenewal | ||
|
||
# Enable auto renewal for the domain in the account. | ||
# | ||
# @see https://developer.dnsimple.com/v2/registrar/auto-renewal/ | ||
# | ||
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard | ||
# @param [String] domain_id the domain name | ||
# @param [Hash] options | ||
# @return [Dnsimple::Response<nil>] | ||
# | ||
# @raise [Dnsimple::NotFoundError] | ||
# @raise [Dnsimple::RequestError] | ||
def enable_auto_renewal(account_id, domain_id, options={}) | ||
response = client.put(Client.versioned("/%s/domains/%s/auto_renewal" % [account_id, domain_id]), options) | ||
|
||
Dnsimple::Response.new(response, nil) | ||
end | ||
|
||
# Disable auto renewal for the domain in the account. | ||
# | ||
# @see https://developer.dnsimple.com/v2/registrar/auto-renewal/ | ||
# | ||
# @param [Fixnum, Dnsimple::Client::WILDCARD_ACCOUNT] account_id the account ID or wildcard | ||
# @param [String] domain_id the domain name | ||
# @param [Hash] options | ||
# @return [Dnsimple::Response<nil>] | ||
# | ||
# @raise [Dnsimple::NotFoundError] | ||
# @raise [Dnsimple::RequestError] | ||
def disable_auto_renewal(account_id, domain_id, options={}) | ||
response = client.delete(Client.versioned("/%s/domains/%s/auto_renewal" % [account_id, domain_id]), options) | ||
|
||
Dnsimple::Response.new(response, nil) | ||
end | ||
|
||
end | ||
end | ||
end |
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,80 @@ | ||
require 'spec_helper' | ||
|
||
describe Dnsimple::Client, ".registrar" do | ||
|
||
subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").registrar } | ||
|
||
describe "#enable_auto_renewal" do | ||
let(:account_id) { 1010 } | ||
let(:domain_id) { "example.com" } | ||
|
||
before do | ||
stub_request(:put, %r[/v2/#{account_id}/domains/#{domain_id}]) | ||
.to_return(read_http_fixture("enableAutoRenewal/success.http")) | ||
end | ||
|
||
|
||
it "builds the correct request" do | ||
subject.enable_auto_renewal(account_id, domain_id) | ||
|
||
expect(WebMock).to have_requested(:put, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/auto_renewal") | ||
.with(headers: { 'Accept' => 'application/json' }) | ||
end | ||
|
||
it "returns nothing" do | ||
response = subject.enable_auto_renewal(account_id, domain_id) | ||
expect(response).to be_a(Dnsimple::Response) | ||
|
||
result = response.data | ||
expect(result).to be_nil | ||
end | ||
|
||
context "when the domain does not exist" do | ||
it "raises NotFoundError" do | ||
stub_request(:put, %r[/v2]) | ||
.to_return(read_http_fixture("notfound-domain.http")) | ||
|
||
expect { | ||
subject.enable_auto_renewal(account_id, domain_id) | ||
}.to raise_error(Dnsimple::NotFoundError) | ||
end | ||
end | ||
end | ||
|
||
describe "#disable_auto_renewal" do | ||
let(:account_id) { 1010 } | ||
let(:domain_id) { "example.com" } | ||
|
||
before do | ||
stub_request(:delete, %r[/v2/#{account_id}/domains/#{domain_id}]) | ||
.to_return(read_http_fixture("disableAutoRenewal/success.http")) | ||
end | ||
|
||
|
||
it "builds the correct request" do | ||
subject.disable_auto_renewal(account_id, domain_id) | ||
|
||
expect(WebMock).to have_requested(:delete, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/auto_renewal") | ||
.with(headers: { 'Accept' => 'application/json' }) | ||
end | ||
|
||
it "returns nothing" do | ||
response = subject.disable_auto_renewal(account_id, domain_id) | ||
expect(response).to be_a(Dnsimple::Response) | ||
|
||
result = response.data | ||
expect(result).to be_nil | ||
end | ||
|
||
context "when the domain does not exist" do | ||
it "raises NotFoundError" do | ||
stub_request(:delete, %r[/v2]) | ||
.to_return(read_http_fixture("notfound-domain.http")) | ||
|
||
expect { | ||
subject.disable_auto_renewal(account_id, domain_id) | ||
}.to raise_error(Dnsimple::NotFoundError) | ||
end | ||
end | ||
end | ||
end |
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,12 @@ | ||
HTTP/1.1 204 No Content | ||
Server: nginx | ||
Date: Thu, 04 Feb 2016 13:33:52 GMT | ||
Connection: keep-alive | ||
Status: 204 No Content | ||
X-RateLimit-Limit: 4000 | ||
X-RateLimit-Remaining: 3998 | ||
X-RateLimit-Reset: 1454596042 | ||
Cache-Control: no-cache | ||
X-Request-Id: 192f9a74-c6bd-449f-95cb-b5ced155f251 | ||
X-Runtime: 0.869286 | ||
Strict-Transport-Security: max-age=31536000 |
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,12 @@ | ||
HTTP/1.1 204 No Content | ||
Server: nginx | ||
Date: Thu, 04 Feb 2016 13:27:23 GMT | ||
Connection: keep-alive | ||
Status: 204 No Content | ||
X-RateLimit-Limit: 4000 | ||
X-RateLimit-Remaining: 3999 | ||
X-RateLimit-Reset: 1454596043 | ||
Cache-Control: no-cache | ||
X-Request-Id: c1a38224-2e32-4941-887e-ddfba81e9299 | ||
X-Runtime: 1.485398 | ||
Strict-Transport-Security: max-age=31536000 |