Skip to content

Commit

Permalink
Added support for applyTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Jul 21, 2016
1 parent 46e7e62 commit b8e796b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/dnsimple/client/templates.rb
Expand Up @@ -146,6 +146,28 @@ def delete_template(account_id, template_id, options = {})
end
alias delete delete_template

# Applies a template to the domain.
#
# @see https://developer.dnsimple.com/v2/templates/domains/#apply
#
# @example Apply template 5401 for example.com in account 1010:
# client.templates.apply_template(1010, "example.com", 5401)
#
# @param [Fixnum] account_id The account ID
# @param [#to_s] domain_id The Domain ID or name
# @param [#to_s] template_id The template ID
# @param [Hash] options
# @return [Dnsimple::Response<nil>]
#
# @raise [Dnsimple::NotFoundError]
# @raise [Dnsimple::RequestError]
def apply_template(account_id, domain_id, template_id, options = {})
endpoint = Client.versioned("/%s/domains/%s/templates/%s" % [account_id, domain_id, template_id])
response = client.post(endpoint, options)

Dnsimple::Response.new(response, nil)
end

end
end
end
24 changes: 24 additions & 0 deletions spec/dnsimple/client/templates_spec.rb
Expand Up @@ -189,4 +189,28 @@
end
end

describe "#apply_template" do
let(:account_id) { 1010 }
let(:domain_id) { 'example.com' }
let(:template_id) { 5410 }

before do
stub_request(:post, %r{/v2/#{account_id}/domains/#{domain_id}/templates/#{template_id}$}).
to_return(read_http_fixture("applyTemplate/success.http"))
end

it "builds the correct request" do
subject.apply_template(account_id, domain_id, template_id)

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

it "returns the list of templates" do
response = subject.apply_template(account_id, domain_id, template_id)
expect(response).to be_a(Dnsimple::Response)
expect(response.data).to be_nil
end
end

end
13 changes: 13 additions & 0 deletions spec/fixtures.http/applyTemplate/success.http
@@ -0,0 +1,13 @@
HTTP/1.1 204 No Content
Server: nginx
Date: Thu, 24 Mar 2016 11:05:38 GMT
Connection: keep-alive
Status: 204 No Content
X-RateLimit-Limit: 2400
X-RateLimit-Remaining: 2397
X-RateLimit-Reset: 1458821049
Cache-Control: no-cache
X-Request-Id: 967713d5-a203-40ee-875c-1df07868b7eb
X-Runtime: 0.147576
Strict-Transport-Security: max-age=31536000

0 comments on commit b8e796b

Please sign in to comment.