Class: Vra::CatalogItem

Inherits:
CatalogBase show all
Defined in:
lib/vra/catalog_item.rb

Overview

Class that represents the Catalog Item

Constant Summary collapse

INDEX_URL =
'/catalog/api/admin/items'

Instance Attribute Summary collapse

Attributes inherited from CatalogBase

#id

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, opts = {}) ⇒ CatalogItem

Returns a new instance of CatalogItem.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vra/catalog_item.rb', line 30

def initialize(client, opts = {})
  super
  @project_id = opts[:project_id]
  validate!

  if @data.nil?
    fetch_catalog_item
  else
    @id = @data['id']
  end
end

Instance Attribute Details

#project_idObject (readonly)

Returns the value of attribute project_id.



28
29
30
# File 'lib/vra/catalog_item.rb', line 28

def project_id
  @project_id
end

Class Method Details

.entitle!(client, id) ⇒ Object



80
81
82
# File 'lib/vra/catalog_item.rb', line 80

def self.entitle!(client, id)
  new(client, id: id).entitle!
end

Instance Method Details

#descriptionObject



52
53
54
# File 'lib/vra/catalog_item.rb', line 52

def description
  data['description']
end

#entitle!(opts = {}) ⇒ Object



76
77
78
# File 'lib/vra/catalog_item.rb', line 76

def entitle!(opts = {})
  super(opts.merge(type: 'CatalogItemIdentifier'))
end

#fetch_catalog_itemObject



42
43
44
45
46
# File 'lib/vra/catalog_item.rb', line 42

def fetch_catalog_item
  @data = client.get_parsed("/catalog/api/admin/items/#{id}")
rescue Vra::Exception::HTTPNotFound
  raise Vra::Exception::NotFound, "catalog ID #{id} does not exist"
end

#icon_idObject



72
73
74
# File 'lib/vra/catalog_item.rb', line 72

def icon_id
  data['iconId']
end

#nameObject



48
49
50
# File 'lib/vra/catalog_item.rb', line 48

def name
  data['name']
end

#sourceObject



64
65
66
# File 'lib/vra/catalog_item.rb', line 64

def source
  @source ||= Vra::CatalogSource.new(client, id: source_id)
end

#source_idObject



56
57
58
# File 'lib/vra/catalog_item.rb', line 56

def source_id
  data['sourceId']
end

#source_nameObject



60
61
62
# File 'lib/vra/catalog_item.rb', line 60

def source_name
  data['sourceName']
end

#typeObject



68
69
70
# File 'lib/vra/catalog_item.rb', line 68

def type
  @type ||= Vra::CatalogType.new(client, data: data['type'])
end