Class: Vra::CatalogItem
- Inherits:
-
CatalogBase
- Object
- CatalogBase
- Vra::CatalogItem
- 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
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
Attributes inherited from CatalogBase
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
- #entitle!(opts = {}) ⇒ Object
- #fetch_catalog_item ⇒ Object
- #icon_id ⇒ Object
-
#initialize(client, opts = {}) ⇒ CatalogItem
constructor
A new instance of CatalogItem.
- #name ⇒ Object
- #source ⇒ Object
- #source_id ⇒ Object
- #source_name ⇒ Object
- #type ⇒ Object
- #versions ⇒ Object
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_id ⇒ Object (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
#description ⇒ Object
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_item ⇒ Object
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_id ⇒ Object
72 73 74 |
# File 'lib/vra/catalog_item.rb', line 72 def icon_id data["iconId"] end |
#name ⇒ Object
48 49 50 |
# File 'lib/vra/catalog_item.rb', line 48 def name data["name"] end |
#source ⇒ Object
64 65 66 |
# File 'lib/vra/catalog_item.rb', line 64 def source @source ||= Vra::CatalogSource.new(client, id: source_id) end |
#source_id ⇒ Object
56 57 58 |
# File 'lib/vra/catalog_item.rb', line 56 def source_id data["sourceId"] end |
#source_name ⇒ Object
60 61 62 |
# File 'lib/vra/catalog_item.rb', line 60 def source_name data["sourceName"] end |
#type ⇒ Object
68 69 70 |
# File 'lib/vra/catalog_item.rb', line 68 def type @type ||= Vra::CatalogType.new(client, data: data["type"]) end |
#versions ⇒ Object
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 |