Skip to content

Commit

Permalink
Add certificates.all_certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed May 25, 2017
1 parent 3feaf68 commit 63f77dd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ This project uses [Semantic Versioning 2.0.0](http://semver.org/).

#### master

- NEW: Added `certificates.all_certificates` (dnsimple/dnsimple-ruby#155)

- CHANGED: Updated registrar URLs (dnsimple/dnsimple-ruby#153)

#### 4.2.0
Expand Down
24 changes: 24 additions & 0 deletions lib/dnsimple/client/certificates.rb
Expand Up @@ -30,6 +30,30 @@ def certificates(account_id, domain_name, options = {})
Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Certificate.new(r) })
end

# Lists ALL the certificates for the domain.
#
# This method is similar to {#certificates}, but instead of returning the results of a specific page
# it iterates all the pages and returns the entire collection.
#
# Please use this method carefully, as fetching the entire collection will increase the number of requests
# you send to the API server and you may eventually risk to hit the throttle limit.
#
# @see https://developer.dnsimple.com/v2/domains/certificates/#list
# @see #certificates
#
# @param [Integer] account_id the account ID
# @param [#to_s] domain_name The domain ID or domain name
# @param [Hash] options the filtering and sorting option
# @option options [Integer] :page current page (pagination)
# @option options [Integer] :per_page number of entries to return (pagination)
# @option options [String] :sort sorting policy
# @return [Dnsimple::CollectionResponse<Dnsimple::Struct::Certificate>]
#
# @raise [Dnsimple::RequestError]
def all_certificates(account_id, domain_name, options = {})
paginate(:certificates, account_id, domain_name, options)
end

# Gets a certificate associated to the domain.
#
# @see https://developer.dnsimple.com/v2/domains/certificates/#get
Expand Down
21 changes: 21 additions & 0 deletions spec/dnsimple/client/certificates_spec.rb
Expand Up @@ -56,6 +56,27 @@
end
end

describe "#all_certificates" do
before do
stub_request(:get, %r{/v2/#{account_id}/domains/#{domain_id}/certificates}).
to_return(read_http_fixture("listCertificates/success.http"))
end

let(:account_id) { 1010 }
let(:domain_id) { "example.com" }

it "delegates to client.paginate" do
expect(subject).to receive(:paginate).with(:certificates, account_id, domain_id, foo: "bar")
subject.all_certificates(account_id, domain_id, foo: "bar")
end

it "supports sorting" do
subject.all_certificates(account_id, domain_id, sort: "id:asc,expires_on:desc")

expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/certificates?page=1&per_page=100&sort=id:asc,expires_on:desc")
end
end

describe "#certificate" do
let(:account_id) { 1010 }
let(:domain_id) { "weppos.net" }
Expand Down

0 comments on commit 63f77dd

Please sign in to comment.