class ALD::API::Item
Public: An item (e.g. a library or app) uploaded to an ALD
server.
Public Class Methods
Internal: Create a new instance for given data. This method should not called by library consumers. Instead access entries via API#item
or ItemCollection#[]
.
api - the ALD::API
instance this item belongs to data - a Hash containing data concerning the item:
id - the GUID of the item name - the name of the item version - the semver version of the item The above fields are mandatory. However, the hash may contain a lot more data about the item.
initialized - a Boolean indicating if data only contains the mandatory
fields or *all* data on the item.
ALD::API::CollectionEntry::new
# File lib/ALD/item.rb, line 141 def initialize(api, data, initialized = false) raise ArgumentError unless Item.valid_data?(data) super(api, data, initialized) end
Private Class Methods
Internal: Override of CollectionEntry#initialized_attributes to enable automatic method definition, in this case id, name and version.
Returns an Array of attribute names (String)
# File lib/ALD/item.rb, line 173 def self.initialized_attributes %w[id name version] end
Internal: Override of CollectionEntry#requested_attributes to enable automatic method definition.
Returns an Array of attribute names (String)
# File lib/ALD/item.rb, line 181 def self.requested_attributes %w[summary description uploaded reviewed downloads tags authors user ratings] end
Internal: Ensure a Hash contains all information necessary to be passed to new.
data - the Hash to check for mandatory fields
Returns true if the Hash is valid, false otherwise.
# File lib/ALD/item.rb, line 165 def self.valid_data?(data) data.is_a?(Hash) && initialized_attributes.all? { |k| data.key?(k) } end
Private Instance Methods
Internal: If the item was initialized with only mandatory data, use the API
to request all missing information.
Returns nothing.
# File lib/ALD/item.rb, line 152 def request @data = @api.request("/items/#{id}") @data['uploaded'] = DateTime.parse(@data['uploaded']) @data['tags'].map!(&:to_sym) @data['user'] = @api.user(@data['user']) end