Class: DNSimple::Certificate
- Inherits:
-
Object
- Object
- DNSimple::Certificate
- Includes:
- HTTParty
- Defined in:
- lib/dnsimple/certificate.rb
Overview
Represents an SSL certificate that has been purchased. The certificate must also be submitted using the #submit method before the Certificate Authority will issue a signed certificate.
Instance Attribute Summary collapse
-
#approver_email ⇒ Object
The approver email address.
-
#available_approver_emails ⇒ Object
An array of all emails that can be used to approve the certificate.
-
#certificate_status ⇒ Object
The Certificate status.
-
#created_at ⇒ Object
When the certificate was purchased.
-
#csr ⇒ Object
The Certificate Signing Request.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#expiration_date ⇒ Object
The date the Certificate will expire.
-
#id ⇒ Object
The certificate ID in DNSimple.
-
#name ⇒ Object
The subdomain on the certificate.
-
#order_date ⇒ Object
The date the Certificate order was placed.
-
#private_key ⇒ Object
The private key, if DNSimple generated the Certificate Signing Request.
-
#ssl_certificate ⇒ Object
The SSL certificate, if it has been issued by the Certificate Authority.
-
#updated_at ⇒ Object
When the certificate was last updated.
Class Method Summary collapse
-
.all(domain, options = {}) ⇒ Object
Get an array of all certificates for the given domain.
-
.find(domain, certificate_id, options = {}) ⇒ Object
Find a specific certificate for the given domain.
-
.purchase(domain, name, contact, options = {}) ⇒ Object
Purchase a certificate under the given domain with the given name.
Instance Method Summary collapse
-
#fqdn ⇒ Object
Get the fully-qualified domain name for the certificate.
-
#initialize(attributes) ⇒ Certificate
constructor
:nodoc:.
- #submit(approver_email, options = {}) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Certificate
:nodoc:
50 51 52 53 54 55 |
# File 'lib/dnsimple/certificate.rb', line 50 def initialize(attributes) attributes.each do |key, value| m = "#{key}=".to_sym self.send(m, value) if self.respond_to?(m) end end |
Instance Attribute Details
#approver_email ⇒ Object
The approver email address
36 37 38 |
# File 'lib/dnsimple/certificate.rb', line 36 def approver_email @approver_email end |
#available_approver_emails ⇒ Object
An array of all emails that can be used to approve the certificate
39 40 41 |
# File 'lib/dnsimple/certificate.rb', line 39 def available_approver_emails @available_approver_emails end |
#certificate_status ⇒ Object
The Certificate status
27 28 29 |
# File 'lib/dnsimple/certificate.rb', line 27 def certificate_status @certificate_status end |
#created_at ⇒ Object
When the certificate was purchased
42 43 44 |
# File 'lib/dnsimple/certificate.rb', line 42 def created_at @created_at end |
#csr ⇒ Object
The Certificate Signing Request
24 25 26 |
# File 'lib/dnsimple/certificate.rb', line 24 def csr @csr end |
#domain ⇒ Object
Returns the value of attribute domain.
12 13 14 |
# File 'lib/dnsimple/certificate.rb', line 12 def domain @domain end |
#expiration_date ⇒ Object
The date the Certificate will expire
33 34 35 |
# File 'lib/dnsimple/certificate.rb', line 33 def expiration_date @expiration_date end |
#id ⇒ Object
The certificate ID in DNSimple
10 11 12 |
# File 'lib/dnsimple/certificate.rb', line 10 def id @id end |
#name ⇒ Object
The subdomain on the certificate
15 16 17 |
# File 'lib/dnsimple/certificate.rb', line 15 def name @name end |
#order_date ⇒ Object
The date the Certificate order was placed
30 31 32 |
# File 'lib/dnsimple/certificate.rb', line 30 def order_date @order_date end |
#private_key ⇒ Object
The private key, if DNSimple generated the Certificate Signing Request
18 19 20 |
# File 'lib/dnsimple/certificate.rb', line 18 def private_key @private_key end |
#ssl_certificate ⇒ Object
The SSL certificate, if it has been issued by the Certificate Authority
21 22 23 |
# File 'lib/dnsimple/certificate.rb', line 21 def ssl_certificate @ssl_certificate end |
#updated_at ⇒ Object
When the certificate was last updated
45 46 47 |
# File 'lib/dnsimple/certificate.rb', line 45 def updated_at @updated_at end |
Class Method Details
.all(domain, options = {}) ⇒ Object
Get an array of all certificates for the given domain.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/dnsimple/certificate.rb', line 121 def self.all(domain, ={}) .merge!(DNSimple::Client.) response = self.get("#{DNSimple::Client.base_uri}/domains/#{domain.name}/certificates", ) pp response if DNSimple::Client.debug? case response.code when 200 response.map { |r| DNSimple::Certificate.new({:domain => domain}.merge(r["certificate"])) } when 401 raise DNSimple::AuthenticationFailed, "Authentication failed" else raise DNSimple::Error.new("List certificates error: #{response["errors"]}") end end |
.find(domain, certificate_id, options = {}) ⇒ Object
Find a specific certificate for the given domain.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/dnsimple/certificate.rb', line 139 def self.find(domain, certificate_id, ={}) .merge!(DNSimple::Client.) response = self.get("#{DNSimple::Client.base_uri}/domains/#{domain.name}/certificates/#{certificate_id}", ) pp response if DNSimple::Client.debug? case response.code when 200 DNSimple::Certificate.new({:domain => domain}.merge(response["certificate"])) when 401 raise DNSimple::AuthenticationFailed, "Authentication failed" when 404 raise DNSimple::CertificateNotFound, "Could not find certificate #{certificate_id} for domain #{domain.name}" else raise DNSimple::Error.new("Find certificate error: #{response["errors"]}") end end |
.purchase(domain, name, contact, options = {}) ⇒ Object
Purchase a certificate under the given domain with the given name. The name will be appended to the domain name, and thus should only be the subdomain part.
Example: DNSimple::Certificate.purchase(domain, âwwwâ, contact)
Please note that by invoking this method DNSimple will immediately charge your credit card on file at DNSimple for the full certificate price.
For wildcard certificates an asterisk must appear in the name.
Example: DNSimple::Certificate.purchase(domain, â*â, contact)
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/dnsimple/certificate.rb', line 95 def self.purchase(domain, name, contact, ={}) certificate_hash = { :name => name, :contact_id => contact.id } .merge!(DNSimple::Client.) .merge!({:body => {:certificate => certificate_hash}}) response = self.post("#{DNSimple::Client.base_uri}/domains/#{domain.name}/certificates", ) pp response if DNSimple::Client.debug? case response.code when 201 return DNSimple::Certificate.new({:domain => domain}.merge(response["certificate"])) when 401 raise DNSimple::AuthenticationFailed, "Authentication failed" when 406 raise DNSimple::CertificateExists.new("#{name}.#{domain.name}", response["errors"]) else raise DNSimple::Error.new("#{name}.#{domain.name}", response["errors"]) end end |
Instance Method Details
#fqdn ⇒ Object
Get the fully-qualified domain name for the certificate. This is the domain.name joined with the certificate name, separated by a period.
59 60 61 |
# File 'lib/dnsimple/certificate.rb', line 59 def fqdn [name, domain.name].delete_if { |p| p !~ DNSimple::BLANK_REGEX }.join(".") end |
#submit(approver_email, options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dnsimple/certificate.rb', line 63 def submit(approver_email, ={}) raise DNSimple::Error, "Approver email is required" unless approver_email .merge!(DNSimple::Client.) .merge!(:body => {:certificate => {:approver_email => approver_email}}) response = self.class.put("#{DNSimple::Client.base_uri}/domains/#{domain.name}/certificates/#{id}/submit", ) pp response if DNSimple::Client.debug? case response.code when 200 return DNSimple::Certificate.new({:domain => domain}.merge(response["certificate"])) when 401 raise DNSimple::AuthenticationFailed, "Authentication failed" else raise DNSimple::Error.new("Error submitting certificate: #{response["errors"]}") end end |