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/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



87
88
89
# File 'lib/vra/catalog_item.rb', line 87

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

.fetch_latest_version(client, id) ⇒ Object



91
92
93
# File 'lib/vra/catalog_item.rb', line 91

def fetch_latest_version(client, id)
  new(client, data: { "id" => id }).versions&.first
end

Instance Method Details

#descriptionObject



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

def description
  data["description"]
end

#entitle!(opts = {}) ⇒ Object



82
83
84
# File 'lib/vra/catalog_item.rb', line 82

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/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

#versionsObject



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

def versions
  client
    .http_get_paginated_array!("/catalog/api/items/#{id}/versions")
    .map { |v| v["id"] }
end