class SoftLayer::ProductItemCategory

The goal of this class is to make it easy for scripts (and scripters) to discover what product configuration options exist that can be added to a product order.

Instances of this class are created by and discovered in the context of a ProductPackage object. There should not be a need to create instances of this class directly.

This class roughly represents entities in the SoftLayer_Product_Item_Category service.

Attributes

categoryCode[R]

The categoryCode is a primary identifier for a particular category. It is a string like 'os' or 'ram'

DEPRECATION WARNING: This attribute is deprecated in favor of #category_code and will be removed in the next major release.

category_code[R]

The categoryCode is a primary identifier for a particular category. It is a string like 'os' or 'ram'

name[R]

The name of a category is a friendly, readable string

Public Class Methods

new(softlayer_client, network_hash, is_required) click to toggle source

The ProductItemCategory class augments the base initialization by accepting a boolean variable, is_required, which (when true) indicates that this category is required for orders against the package that created it.

Calls superclass method SoftLayer::ModelBase.new
# File lib/softlayer/ProductItemCategory.rb, line 148
def initialize(softlayer_client, network_hash, is_required)
  super(softlayer_client, network_hash)
  @is_required = is_required
end

Public Instance Methods

configuration_options(force_update=false) click to toggle source

Retrieve the product item configuration information

# File lib/softlayer/ProductItemCategory.rb, line 94
sl_dynamic_attr :configuration_options do |config_opts|
  config_opts.should_update? do
    # only retrieved once per instance
    @configuration_options == nil
  end

  config_opts.to_update do
    # This method assumes that the group and price item data was sent in
    # as part of the +network_hash+ used to initialize this object (as is done)
    # by the ProductPackage class. That class, in turn, gets its information
    # from SoftLayer_Product_Package::getCategories which does some complex
    # work on the back end to ensure the prices returned are correct.
    #
    # If this object was created in any other way, the configuration
    # options might be incorrect. So Caveat Emptor.
    #
    # Options are divided into groups (for convenience in the
    # web UI), but this code collapses the groups.
    self['groups'].collect do |group|
      group['prices'].sort{|lhs,rhs| lhs['sort'] <=> rhs['sort']}.collect do |price_item|
        ProductConfigurationOption.new(price_item['item'], price_item)
      end
    end.flatten # flatten out the individual group arrays.
  end
end
default_option() click to toggle source

If the category has a single option (regardless of fees) this method will return that option. If the category has more than one option, this method will return the first that it finds with no fees associated with it.

If there are multiple options with no fees, it simply returns the first it finds

Note that the option found may NOT be the same default option that is given in the web-based ordering system.

If there are multiple options, and all of them have associated fees, then this method *will* return nil.

# File lib/softlayer/ProductItemCategory.rb, line 137
def default_option
  if configuration_options.count == 1
    configuration_options.first
  else
    configuration_options.find { |option| option.free? }
  end
end
required?() click to toggle source

Returns true if this category is required in its package

# File lib/softlayer/ProductItemCategory.rb, line 154
def required?()
  return @is_required
end
service() click to toggle source
# File lib/softlayer/ProductItemCategory.rb, line 120
def service
  softlayer_client[:SoftLayer_Product_Item_Category].object_with_id(self.id)
end