Class: DNSimple::Certificate

Inherits:
Base
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from DNSimple::Base

Instance Attribute Details

#approver_emailObject

The approver email address



27
28
29
# File 'lib/dnsimple/certificate.rb', line 27

def approver_email
  @approver_email
end

#available_approver_emailsObject

An array of all emails that can be used to approve the certificate



36
37
38
# File 'lib/dnsimple/certificate.rb', line 36

def available_approver_emails
  @available_approver_emails
end

#certificate_statusObject

The Certificate status



39
40
41
# File 'lib/dnsimple/certificate.rb', line 39

def certificate_status
  @certificate_status
end

#created_atObject

When the certificate was purchased



30
31
32
# File 'lib/dnsimple/certificate.rb', line 30

def created_at
  @created_at
end

#csrObject

The Certificate Signing Request



18
19
20
# File 'lib/dnsimple/certificate.rb', line 18

def csr
  @csr
end

#domainObject

Returns the value of attribute domain.



12
13
14
# File 'lib/dnsimple/certificate.rb', line 12

def domain
  @domain
end

#expiration_dateObject

The date the Certificate will expire



45
46
47
# File 'lib/dnsimple/certificate.rb', line 45

def expiration_date
  @expiration_date
end

#idObject

The certificate ID in DNSimple



10
11
12
# File 'lib/dnsimple/certificate.rb', line 10

def id
  @id
end

#nameObject

The subdomain on the certificate



15
16
17
# File 'lib/dnsimple/certificate.rb', line 15

def name
  @name
end

#order_dateObject

The date the Certificate order was placed



42
43
44
# File 'lib/dnsimple/certificate.rb', line 42

def order_date
  @order_date
end

#private_keyObject

The private key, if DNSimple generated the Certificate Signing Request



24
25
26
# File 'lib/dnsimple/certificate.rb', line 24

def private_key
  @private_key
end

#ssl_certificateObject

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_atObject

When the certificate was last updated



33
34
35
# File 'lib/dnsimple/certificate.rb', line 33

def updated_at
  @updated_at
end

Class Method Details

.all(domain, options = {}) ⇒ Object

Get an array of all certificates for the given domain.



81
82
83
84
85
86
87
88
89
90
# File 'lib/dnsimple/certificate.rb', line 81

def self.all(domain, options={})
  response = DNSimple::Client.get("/v1/domains/#{domain.name}/certificates", options)

  case response.code
  when 200
    response.map { |r| new({:domain => domain}.merge(r["certificate"])) }
  else
    raise RequestError.new("Error listing certificates", response)
  end
end

.find(domain, id, options = {}) ⇒ Object

Find a specific certificate for the given domain.



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/dnsimple/certificate.rb', line 93

def self.find(domain, id, options = {})
  response = DNSimple::Client.get("/v1/domains/#{domain.name}/certificates/#{id}", options)

  case response.code
  when 200
    new({:domain => domain}.merge(response["certificate"]))
  when 404
    raise RecordNotFound, "Could not find certificate #{id} for domain #{domain.name}"
  else
    raise RequestError.new("Error finding certificate", response)
  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)



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dnsimple/certificate.rb', line 60

def self.purchase(domain, name, contact, options={})
  certificate_hash = {
    :name => name,
    :contact_id => contact.id
  }

  options.merge!({:body => {:certificate => certificate_hash}})

  response = DNSimple::Client.post("/v1/domains/#{domain.name}/certificates", options)

  case response.code
  when 201
    new({ :domain => domain }.merge(response["certificate"]))
  when 406
    raise RecordExists, "Certificate for #{domain.name} already exists"
  else
    raise RequestError.new("Error purchasing certificate", response)
  end
end

Instance Method Details

#fqdnObject

Get the fully-qualified domain name for the certificate. This is the domain.name joined with the certificate name, separated by a period.



109
110
111
# File 'lib/dnsimple/certificate.rb', line 109

def fqdn
  [name, domain.name].delete_if { |p| p !~ DNSimple::BLANK_REGEX }.join(".")
end

#submit(approver_email, options = {}) ⇒ Object

Raises:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/dnsimple/certificate.rb', line 113

def submit(approver_email, options={})
  raise DNSimple::Error, "Approver email is required" unless approver_email

  options.merge!(:body => {:certificate => {:approver_email => approver_email}})

  response = DNSimple::Client.put("/v1/domains/#{domain.name}/certificates/#{id}/submit", options)

  case response.code
    when 200
      Certificate.new({ :domain => domain }.merge(response["certificate"]))
    else
      raise RequestError.new("Error submitting certificate", response)
  end
end