class ALD::API::Item
An item (e.g. a library or app) uploaded to an ALD server.
Public
↑ topPublic Instance Methods
Get the user who owns the item. This method might trigger a HTTP request.
Returns¶ ↑
Returns the ALD::API::User who owns the item.
Signature¶ ↑
# File lib/ALD/item.rb, line 118
Internal
↑ topPublic Class Methods
Create a new instance for given data. This method should not called by library consumers. Instead access entries via ALD::API#item or ALD::API::Collection#[].
- 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.
# 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
Ensure a Hash contains all information necessary to be passed to #new.
- data
-
the Hash to check for mandatory fields
Returns¶ ↑
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
If the item was initialized with only mandatory data, use the API to request all missing information.
Returns¶ ↑
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