Class: ChefLicensing::Api::Parser::Client
- Inherits:
-
Object
- Object
- ChefLicensing::Api::Parser::Client
- Defined in:
- lib/chef-licensing/api/parser/client.rb
Instance Attribute Summary collapse
-
#client_data ⇒ Object
readonly
Uses response from /client API This parser formats the response which will enable creation of license data object.
-
#data ⇒ Object
readonly
Uses response from /client API This parser formats the response which will enable creation of license data object.
Instance Method Summary collapse
-
#initialize(data) ⇒ Client
constructor
A new instance of Client.
- #parse_asset_entitlements ⇒ Object
-
#parse_expiration_date ⇒ Object
Parse expiration details.
-
#parse_feature_entitlements ⇒ Object
Parse entitlements.
- #parse_id ⇒ Object
- #parse_license_expiration_status ⇒ Object
- #parse_license_type ⇒ Object
-
#parse_limits ⇒ Object
Parse usage details.
- #parse_software_entitlements ⇒ Object
- #parse_status ⇒ Object
Constructor Details
#initialize(data) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 |
# File 'lib/chef-licensing/api/parser/client.rb', line 12 def initialize(data) # API call response @data = data @client_data = data.client || OpenStruct.new({}) end |
Instance Attribute Details
#client_data ⇒ Object (readonly)
Uses response from /client API This parser formats the response which will enable creation of license data object.
10 11 12 |
# File 'lib/chef-licensing/api/parser/client.rb', line 10 def client_data @client_data end |
#data ⇒ Object (readonly)
Uses response from /client API This parser formats the response which will enable creation of license data object.
10 11 12 |
# File 'lib/chef-licensing/api/parser/client.rb', line 10 def data @data end |
Instance Method Details
#parse_asset_entitlements ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/chef-licensing/api/parser/client.rb', line 85 def parse_asset_entitlements assets = [] assets_data = data.assets || [] assets_data.each do |asset| asset_info = { "id" => asset.id, "name" => asset.name, } assets << asset_info end assets end |
#parse_expiration_date ⇒ Object
Parse expiration details
32 33 34 |
# File 'lib/chef-licensing/api/parser/client.rb', line 32 def parse_expiration_date client_data.changesOn end |
#parse_feature_entitlements ⇒ Object
Parse entitlements
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chef-licensing/api/parser/client.rb', line 56 def parse_feature_entitlements features = [] features_data = data.features || [] features_data.each do |feature| feature_info = { "id" => feature.id, "name" => feature.name, } features << feature_info end features end |
#parse_id ⇒ Object
18 19 20 |
# File 'lib/chef-licensing/api/parser/client.rb', line 18 def parse_id nil end |
#parse_license_expiration_status ⇒ Object
36 37 38 |
# File 'lib/chef-licensing/api/parser/client.rb', line 36 def parse_license_expiration_status client_data.changesTo end |
#parse_license_type ⇒ Object
22 23 24 |
# File 'lib/chef-licensing/api/parser/client.rb', line 22 def parse_license_type client_data.license end |
#parse_limits ⇒ Object
Parse usage details
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chef-licensing/api/parser/client.rb', line 41 def parse_limits if data.client.nil? || data.client.empty? [] else [{ "usage_status" => client_data.usage, "usage_limit" => client_data.limit, "usage_measure" => client_data.measure, "used" => client_data.used, }] end end |
#parse_software_entitlements ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chef-licensing/api/parser/client.rb', line 69 def parse_software_entitlements if data.entitlement.nil? || data.entitlement.empty? [] else require "date" entitlement_status = (data.entitlement.end >= Date.today.to_s) ? "Active" : "Expired" # sending status based on end date [{ "id" => data.entitlement.id, "name" => data.entitlement.name, "entitled" => data.entitlement.entitled, "status" => entitlement_status, }] end end |
#parse_status ⇒ Object
26 27 28 |
# File 'lib/chef-licensing/api/parser/client.rb', line 26 def parse_status client_data.status end |