Skip to content

Commit

Permalink
Merge efe1886 into 4822353
Browse files Browse the repository at this point in the history
  • Loading branch information
aeden committed Feb 5, 2016
2 parents 4822353 + efe1886 commit 8deb3b8
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/dnsimple/client/clients.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ class OauthService < ClientService


require_relative 'registrar'
require_relative 'registrar_auto_renewal'

class RegistrarService < ClientService
include Client::Registrar
include Client::RegistrarAutoRenewal
end


Expand Down
41 changes: 41 additions & 0 deletions lib/dnsimple/client/registrar_auto_renewal.rb
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
80 changes: 80 additions & 0 deletions spec/dnsimple/client/registrar_auto_renewal_spec.rb
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
12 changes: 12 additions & 0 deletions spec/fixtures.http/disableAutoRenewal/success.http
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
12 changes: 12 additions & 0 deletions spec/fixtures.http/enableAutoRenewal/success.http
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

0 comments on commit 8deb3b8

Please sign in to comment.