Sha256: 713c90209d1335bd53b3da47c81a57dbce883284cc094a8eda9591680382d58e

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

class Acme::Client::Resources::Order
  attr_reader :url, :status, :contact, :finalize_url, :identifiers, :authorization_urls, :expires, :certificate_url

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

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

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

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

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

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

  private

  def assign_attributes(url:, status:, expires:, finalize_url:, authorization_urls:, identifiers:, certificate_url: nil)
    @url = url
    @status = status
    @expires = expires
    @finalize_url = finalize_url
    @authorization_urls = authorization_urls
    @identifiers = identifiers
    @certificate_url = certificate_url
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
acme-client-2.0.6 lib/acme/client/resources/order.rb
acme-client-2.0.5 lib/acme/client/resources/order.rb
acme-client-2.0.4 lib/acme/client/resources/order.rb
acme-client-2.0.3 lib/acme/client/resources/order.rb
acme-client-2.0.2 lib/acme/client/resources/order.rb