-
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
6 changed files
with
169 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Dnsimple | ||
class Client | ||
module Certificates | ||
|
||
# Lists the certificates in the account. | ||
# | ||
# @see https://developer.dnsimple.com/v2/certificates/#list | ||
# @see #all_certificates | ||
# | ||
# @example List certificates in the first page | ||
# client.certificates.list(1010) | ||
# | ||
# @example List certificates, provide a specific page | ||
# client.certificates.list(1010, page: 2) | ||
# | ||
# @example List certificates, provide a sorting policy | ||
# client.certificates.list(1010, sort: "email:asc") | ||
# | ||
# @param [Fixnum] account_id the account ID | ||
# @param [#to_s] domain_name the domain name | ||
# @param [Hash] options the filtering and sorting options | ||
# @option options [Integer] :page current page (pagination) | ||
# @option options [Integer] :per_page number of entries to return (pagination) | ||
# @return [Dnsimple::PaginatedResponse<Dnsimple::Struct::Certificate>] | ||
# | ||
# @raise [Dnsimple::RequestError] | ||
def certificates(account_id, domain_name, options = {}) | ||
response = client.get(Client.versioned("/%s/domains/%s/certificates" % [account_id, domain_name]), Options::ListOptions.new(options)) | ||
|
||
Dnsimple::PaginatedResponse.new(response, response["data"].map { |r| Struct::Certificate.new(r) }) | ||
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
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,40 @@ | ||
module Dnsimple | ||
module Struct | ||
|
||
class Certificate < Base | ||
# @return [Fixnum] The certificate ID in DNSimple. | ||
attr_accessor :id | ||
|
||
# @return [Fixnum] The associated domain ID. | ||
attr_accessor :domain_id | ||
|
||
# @return [String] The certificate name. | ||
attr_accessor :name | ||
|
||
# @return [String] The certificate common name. | ||
attr_accessor :common_name | ||
|
||
# @return [Fixnum] The years the certificate will last. | ||
attr_accessor :years | ||
|
||
# @return [String] The certificate CSR. | ||
attr_accessor :csr | ||
|
||
# @return [String] The certificate state. | ||
attr_accessor :state | ||
|
||
# @return [String] The Certificate Authority (CA) that issued the certificate. | ||
attr_accessor :authority_identifier | ||
|
||
# @return [String] When the certificate was created in DNSimple. | ||
attr_accessor :created_at | ||
|
||
# @return [String] When the certificate was last updated in DNSimple. | ||
attr_accessor :updated_at | ||
|
||
# @return [String] When the certificate will expire. | ||
attr_accessor :expires_on | ||
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,60 @@ | ||
require 'spec_helper' | ||
|
||
describe Dnsimple::Client, ".certificates" do | ||
|
||
subject { described_class.new(base_url: "https://api.dnsimple.test", access_token: "a1b2c3").certificates } | ||
|
||
|
||
describe "#certificates" do | ||
let(:account_id) { 1010 } | ||
let(:domain_id) { "example.com" } | ||
|
||
before do | ||
stub_request(:get, %r{/v2/#{account_id}/domains/#{domain_id}/certificates}). | ||
to_return(read_http_fixture("listCertificates/success.http")) | ||
end | ||
|
||
it "builds the correct request" do | ||
subject.certificates(account_id, domain_id) | ||
|
||
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/certificates"). | ||
with(headers: { 'Accept' => 'application/json' }) | ||
end | ||
|
||
it "supports pagination" do | ||
subject.certificates(account_id, domain_id, page: 2) | ||
|
||
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/certificates?page=2") | ||
end | ||
|
||
it "supports extra request options" do | ||
subject.certificates(account_id, domain_id, query: { foo: "bar" }) | ||
|
||
expect(WebMock).to have_requested(:get, "https://api.dnsimple.test/v2/#{account_id}/domains/#{domain_id}/certificates?foo=bar") | ||
end | ||
|
||
it "returns the certificates" do | ||
response = subject.certificates(account_id, domain_id) | ||
|
||
expect(response).to be_a(Dnsimple::PaginatedResponse) | ||
expect(response.data).to be_a(Array) | ||
expect(response.data.size).to eq(2) | ||
|
||
response.data.each do |result| | ||
expect(result).to be_a(Dnsimple::Struct::Certificate) | ||
expect(result.id).to be_a(Fixnum) | ||
end | ||
end | ||
|
||
it "exposes the pagination information" do | ||
response = subject.certificates(account_id, domain_id) | ||
|
||
expect(response.respond_to?(:page)).to be_truthy | ||
expect(response.page).to eq(1) | ||
expect(response.per_page).to be_a(Fixnum) | ||
expect(response.total_entries).to be_a(Fixnum) | ||
expect(response.total_pages).to be_a(Fixnum) | ||
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,21 @@ | ||
HTTP/1.1 200 OK | ||
Server: nginx | ||
Date: Fri, 08 Jul 2016 15:38:52 GMT | ||
Content-Type: application/json; charset=utf-8 | ||
Transfer-Encoding: chunked | ||
Connection: keep-alive | ||
X-RateLimit-Limit: 2400 | ||
X-RateLimit-Remaining: 2394 | ||
X-RateLimit-Reset: 1467993483 | ||
ETag: W/"69a9ce919d99cc8f27183b74a5eb22a9" | ||
Cache-Control: max-age=0, private, must-revalidate | ||
X-Request-Id: 8936089b-f44a-4303-bb65-b39e835f9973 | ||
X-Runtime: 0.036570 | ||
X-Content-Type-Options: nosniff | ||
X-Download-Options: noopen | ||
X-Frame-Options: DENY | ||
X-Permitted-Cross-Domain-Policies: none | ||
X-XSS-Protection: 1; mode=block | ||
Strict-Transport-Security: max-age=31536000 | ||
|
||
{"data":[{"id":1,"domain_id":10,"name":"www","common_name":"www.weppos.net","years":1,"csr":"-----BEGIN CERTIFICATE REQUEST-----\nMIICljCCAX4CAQAwGTEXMBUGA1UEAwwOd3d3LndlcHBvcy5uZXQwggEiMA0GCSqG\nSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC3MJwx9ahBG3kAwRjQdRvYZqtovUaxY6jp\nhd09975gO+2eYPDbc1yhNftVJ4KBT0zdEqzX0CwIlxE1MsnZ2YOsC7IJO531hMBp\ndBxM4tSG07xPz70AVUi9rY6YCUoJHmxoFbclpHFbtXZocR393WyzUK8047uM2mlz\n03AZKcMdyfeuo2/9TcxpTSCkklGqwqS9wtTogckaDHJDoBunAkMioGfOSMe7Yi6E\nYRtG4yPJYsDaq2yPJWV8+i0PFR1Wi5RCnPt0YdQWstHuZrxABi45+XVkzKtz3TUc\nYxrvPBucVa6uzd953u8CixNFkiOefvb/dajsv1GIwH6/Cvc1ftz1AgMBAAGgODA2\nBgkqhkiG9w0BCQ4xKTAnMCUGA1UdEQQeMByCDnd3dy53ZXBwb3MubmV0ggp3ZXBw\nb3MubmV0MA0GCSqGSIb3DQEBCwUAA4IBAQCDnVBO9RdJX0eFeZzlv5c8yG8duhKP\n0000000000000/cbNj9qFPkKTK0vTXmS2XUFBChKPtLucp8+Z754UswX+QCsdc7U\nTTSG0CkyilcSubdZUERGej1XfrVQhrokk7Fu0Jh3BdT6REP0SIDTpA8ku/aRQiAp\np+h19M37S7+w/DMGDAq2LSX8jOpJ1yIokRDyLZpmwyLxutC21DXMGoJ3xZeUFrUT\nqRNwzkn2dJzgTrPkzhaXalUBqv+nfXHqHaWljZa/O0NVCFrHCdTdd53/6EE2Yabv\nq5SFTkRCpaxrvM/7a8Tr4ixD1/VKD6rw3+WCvyS4GWK7knhiI1nZH3PI\n-----END CERTIFICATE REQUEST-----\n","state":"issued","authority_identifier":"letsencrypt","created_at":"2016-06-11T18:47:08.949Z","updated_at":"2016-06-11T18:47:37.546Z","expires_on":"2016-09-09"},{"id":2,"domain_id":10,"name":"www","common_name":"www.weppos.net","years":1,"csr":"-----BEGIN CERTIFICATE REQUEST-----\nMIICljCCAX4CAQAwGTEXMBUGA1UEAwwOd3d3LndlcHBvcy5uZXQwggEiMA0GCSqG\nSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEhv18Sz4nQtjCDseXREuFIZW88yK7M5gM\nw2WuVmxTfn3MGprPtIevPJ0gzR4foMpnOKjR/wW8DpbvvNPNo5FAsYf+mr84rMft\nUjOQWfqcraWWHmss/Ytq45uTie8M1/C4Pr+FFfbOwwWz/DqVao5RQ34q+LIPpV62\nwRkg0m14FqT8gjNNM0XAsrfT7M+kvfsS+FbyJ7G9K0tj3wgqaEuKAQtJn7MPflM8\nfG0TqLJ+NSuI/Zfmtol3XzBD/AoViu0F8Sqp5OR8Ej4ZdmbKR+om+U+MX9LwF8MD\nwCtMAIaGF4JkgrpiGrbAKIpXwkuxJ8wWrkwhxu18z/OhJEBW+wFjAgMBAAGgODA2\nBgkqhkiG9w0BCQ4xKTAnMCUGA1UdEQQeMByCDnd3dy53ZXBwb3MubmV0ggp3ZXBw\nb3MubmV0MA0GCSqGSIb3DQEBCwUAA4IBAQBuDDwhTjU7pAGHU1dUthfznvFqjY2I\n7CNEaUSxlXdxyZs34cwx28F7iMDE8Gh7B3QkuS3c2CTtAQsxnWKebgLYJ8w8XLN1\n9mZtNhT8yXKzLDfC9KuzKw467sbxYf8bLsuyFdQ8sBNp+8es9OwVgYsPwZ4NBtOn\nQlwtBBBdxrF5zCQgQXZsFmymf/o4nLU66ouW1MVjoG608dthoBYiIIiPRx3c+Rjd\ni8JHn2qIKF7AJfJy/H8TLgtE1bt08tfDA9ztuX2zb/lvXrVu4aLBjOF+Fn3b+EqX\n6gR0m+Id0b3t3ORN1QU0SBiyrXXJbo6E+cpYKeWlnkf0000000000000\n-----END CERTIFICATE REQUEST-----\n","state":"issued","authority_identifier":"letsencrypt","created_at":"2016-05-25T15:56:06.118Z","updated_at":"2016-05-25T17:10:39.484Z","expires_on":null}],"pagination":{"current_page":1,"per_page":30,"total_entries":2,"total_pages":1}} |