Class: ChefLicensing::Api::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
20
# File 'lib/chef-licensing/api/client.rb', line 17

def initialize(opts = {})
  @license_keys = opts[:license_keys] || raise(ArgumentError, "Missing Params: `license_keys`")
  @restful_client = opts[:restful_client] ? opts[:restful_client].new : ChefLicensing::RestfulClient::V1.new
end

Instance Attribute Details

#entitlement_idObject (readonly)

Returns the value of attribute entitlement_id.



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

def entitlement_id
  @entitlement_id
end

#license_keysObject (readonly)

Returns the value of attribute license_keys.



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

def license_keys
  @license_keys
end

Class Method Details

.info(opts = {}) ⇒ Object



12
13
14
# File 'lib/chef-licensing/api/client.rb', line 12

def info(opts = {})
  new(opts).info
end

Instance Method Details

#infoObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chef-licensing/api/client.rb', line 22

def info
  response = restful_client.client(license_keys: license_keys.join(","), entitlement_id: ChefLicensing::Config.chef_entitlement_id)
  if response.data
    ChefLicensing::License.new(
      data: response.data,
      api_parser: ChefLicensing::Api::Parser::Client
    )
  else
    raise(ChefLicensing::ClientError, response.message)
  end
end