Class: Acme::Client::Resources::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/acme/client/resources/order.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, **arguments) ⇒ Order

Returns a new instance of Order.



6
7
8
9
# File 'lib/acme/client/resources/order.rb', line 6

def initialize(client, **arguments)
  @client = client
  assign_attributes(**arguments)
end

Instance Attribute Details

#authorization_urlsObject (readonly)

Returns the value of attribute authorization_urls.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def authorization_urls
  @authorization_urls
end

#certificate_urlObject (readonly)

Returns the value of attribute certificate_url.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def certificate_url
  @certificate_url
end

#contactObject (readonly)

Returns the value of attribute contact.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def contact
  @contact
end

#expiresObject (readonly)

Returns the value of attribute expires.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def expires
  @expires
end

#finalize_urlObject (readonly)

Returns the value of attribute finalize_url.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def finalize_url
  @finalize_url
end

#identifiersObject (readonly)

Returns the value of attribute identifiers.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def identifiers
  @identifiers
end

#profileObject (readonly)

Returns the value of attribute profile.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def profile
  @profile
end

#replacesObject (readonly)

Returns the value of attribute replaces.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def replaces
  @replaces
end

#retry_afterObject (readonly)

Returns the value of attribute retry_after.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def retry_after
  @retry_after
end

#retry_after_timeObject (readonly)

Returns the value of attribute retry_after_time.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def retry_after_time
  @retry_after_time
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def status
  @status
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/acme/client/resources/order.rb', line 4

def url
  @url
end

Instance Method Details

#authorizationsObject



18
19
20
21
22
# File 'lib/acme/client/resources/order.rb', line 18

def authorizations
  @authorization_urls.map do |authorization_url|
    @client.authorization(url: authorization_url)
  end
end

#certificate(force_chain: nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/acme/client/resources/order.rb', line 29

def certificate(force_chain: nil)
  if certificate_url
    @client.certificate(url: certificate_url, force_chain: force_chain)
  else
    raise Acme::Client::Error::CertificateNotReady, 'No certificate_url to collect the order'
  end
end

#finalize(csr:) ⇒ Object



24
25
26
27
# File 'lib/acme/client/resources/order.rb', line 24

def finalize(csr:)
  assign_attributes(**@client.finalize(url: finalize_url, csr: csr).to_h)
  true
end

#reloadObject



11
12
13
14
15
16
# File 'lib/acme/client/resources/order.rb', line 11

def reload
  raise Acme::Client::Error::OrderUrlNil, 'Cannot reload order with nil url.' if url.nil?

  assign_attributes(**@client.order(url: url).to_h)
  true
end

#renew(replaces: nil, **arguments) ⇒ Object



37
38
39
40
41
# File 'lib/acme/client/resources/order.rb', line 37

def renew(replaces: nil, **arguments)
  replaces ||= renewal_info.ari_id

  @client.new_order(replaces: replaces, **to_h.slice(:identifiers, :profile).merge(arguments))
end

#renewal_info(certificate: nil, ari_id: nil) ⇒ Object



43
44
45
46
47
# File 'lib/acme/client/resources/order.rb', line 43

def renewal_info(certificate: nil, ari_id: nil)
  certificate ||= self.certificate if ari_id.nil?

  @client.renewal_info(certificate:, ari_id:)
end

#to_hObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/acme/client/resources/order.rb', line 49

def to_h
  {
    url: url,
    status: status,
    expires: expires,
    finalize_url: finalize_url,
    authorization_urls: authorization_urls,
    identifiers: identifiers,
    certificate_url: certificate_url,
    profile: profile,
    replaces: replaces,
    retry_after: retry_after
  }
end