Class: Hcloud::CertificateResource
- Inherits:
-
AbstractResource
- Object
- AbstractResource
- Hcloud::CertificateResource
- Defined in:
- lib/hcloud/certificate_resource.rb
Instance Attribute Summary
Attributes inherited from AbstractResource
Instance Method Summary collapse
- #[](arg) ⇒ Object
- #create(name:, type: :uploaded, certificate: nil, private_key: nil, domain_names: nil, labels: {}) ⇒ Object
Methods inherited from AbstractResource
#all, bind_to, #each, filter_attributes, #find, #find_by, #initialize, #limit, #order, #page, #pagination, #per_page, resource, resource_class, resource_path, resource_url, #run, #where
Constructor Details
This class inherits a constructor from Hcloud::AbstractResource
Instance Method Details
#[](arg) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/hcloud/certificate_resource.rb', line 7 def [](arg) case arg when Integer then find_by(id: arg) when String then find_by(name: arg) end end |
#create(name:, type: :uploaded, certificate: nil, private_key: nil, domain_names: nil, labels: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hcloud/certificate_resource.rb', line 14 def create( name:, type: :uploaded, certificate: nil, private_key: nil, domain_names: nil, labels: {} ) raise Hcloud::Error::InvalidInput, 'no name given' if name.blank? case type when :uploaded raise Hcloud::Error::InvalidInput, 'no certificate given' if certificate.blank? raise Hcloud::Error::InvalidInput, 'no private_key given' if private_key.blank? when :managed raise Hcloud::Error::InvalidInput, 'no domain_names given' if domain_names.to_a.empty? end prepare_request( 'certificates', j: COLLECT_ARGS.call(__method__, binding), expected_code: 201 ) do |response| [ Action.new(client, response.parsed_json[:action]), Certificate.new(client, response.parsed_json[:certificate]) ] end end |