class ALD::API::Item

An item (e.g. a library or app) uploaded to an ALD server.

Public

↑ top

Public Instance Methods

authors() click to toggle source

get author information from the item. This method might trigger a HTTP request.

Returns

Returns an Array of Hashes describing the authors.

Signature

# File lib/ALD/item.rb, line 109
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
description() click to toggle source

Get the item's description text. This method might trigger a HTTP request.

Returns

Returns a String with the item's description.

Signature

# File lib/ALD/item.rb, line 63
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
downloads() click to toggle source

Get the number of downloads for the item. This method might trigger a HTTP request.

Returns

Returns an Integer indicating how often the item was downloaded.

Signature

# File lib/ALD/item.rb, line 91
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
item() click to toggle source

Get the ID of the item.

Examples

puts item.id

Returns

Returns a String of 32 characters, containing the item's GUID.

Signature

# File lib/ALD/item.rb, line 21
                                                                                                                                                                                                                                                                                                                                                                                                                               
name() click to toggle source

Get the name of the item.

Examples

puts "Item: #{item.name}"

Returns

Returns a String containing the item name.

Signature

# File lib/ALD/item.rb, line 33
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
ratings() click to toggle source

Get the ratings the item was given. This method might trigger a HTTP request.

Returns

Returns an Array of Integers representing the ratings given to the item by users.

Signature

# File lib/ALD/item.rb, line 128
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
reviewed() click to toggle source

Get if the item has been marked as reviewed by the ALD server. This method might trigger a HTTP request.

Returns

Returns a Boolean indicating if the item was revieed or not.

Signature

# File lib/ALD/item.rb, line 82
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
summary() click to toggle source

Get the item's summary text. This method might trigger a HTTP request.

Returns

Returns a String summarizing the item's purpose and contents.

Signature

# File lib/ALD/item.rb, line 54
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
tags() click to toggle source

Get the tags the item was tagged with. This method might trigger a HTTP request.

Returns

Returns an Array of Symbols representing the tags.

Signature

# File lib/ALD/item.rb, line 100
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
uploaded() click to toggle source

Get the time the item was uploaded. This method might trigger a HTTP request.

Returns

Returns a DateTime describing the time the item was first uploaded to the ALD server.

Signature

# File lib/ALD/item.rb, line 73
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
user() click to toggle source

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
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
version() click to toggle source

Get the item version.

Examples

puts "#{item.name} v#{item.version}"

Returns

Returns a String containing the version of the item.

Signature

# File lib/ALD/item.rb, line 45
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Internal

↑ top

Public Class Methods

new(api, data, initialized = false) click to toggle source

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.

Calls superclass method 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

initialized_attributes() click to toggle source

Override of CollectionEntry#initialized_attributes to enable automatic method definition, in this case #id, #name and #version.

Returns

Returns an Array of attribute names (String)

# File lib/ALD/item.rb, line 173
def self.initialized_attributes
  %w[id name version]
end
requested_attributes() click to toggle source

Override of CollectionEntry#requested_attributes to enable automatic method definition.

Returns

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
valid_data?(data) click to toggle source

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

request() click to toggle source

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