Class: ChefLicensing::Api::LicenseFeatureEntitlement

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-licensing/api/license_feature_entitlement.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(license_keys: [], feature_name: nil, feature_id: nil, restful_client: ChefLicensing::RestfulClient::V1) ⇒ LicenseFeatureEntitlement

Returns a new instance of LicenseFeatureEntitlement.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
# File 'lib/chef-licensing/api/license_feature_entitlement.rb', line 14

def initialize(license_keys: [], feature_name: nil, feature_id: nil, restful_client: ChefLicensing::RestfulClient::V1)
  license_keys || raise(ArgumentError, "Missing Params: `license_keys`")
  @license_keys = license_keys.is_a?(Array) ? license_keys : [license_keys]
  @feature_name = feature_name
  @feature_id = feature_id
  raise ArgumentError, "Either of `feature_id` or `feature_name` should be provided" if feature_name.nil? && feature_id.nil?

  @restful_client = restful_client.new
end

Instance Attribute Details

#license_keysObject (readonly)

Returns the value of attribute license_keys.



6
7
8
# File 'lib/chef-licensing/api/license_feature_entitlement.rb', line 6

def license_keys
  @license_keys
end

Class Method Details

.check_entitlement!(license_keys: [], feature_name: nil, feature_id: nil) ⇒ Object



9
10
11
# File 'lib/chef-licensing/api/license_feature_entitlement.rb', line 9

def check_entitlement!(license_keys: [], feature_name: nil, feature_id: nil)
  new(license_keys: license_keys, feature_name: feature_name , feature_id: feature_id).check_entitlement!
end

Instance Method Details

#check_entitlement!Object



24
25
26
27
# File 'lib/chef-licensing/api/license_feature_entitlement.rb', line 24

def check_entitlement!
  response = make_request
  response.data.entitled || raise(ChefLicensing::FeatureNotEntitled)
end