Class: Little::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/little/asset.rb

Overview

add, delete and retrieve likes by user or assets

Class Method Summary collapse

Class Method Details

.count_by_type(type) ⇒ Object

gets the number of assets for a type



70
71
72
# File 'lib/little/asset.rb', line 70

def self.count_by_type(type)
  Little.get(:assets, {:type => type}, nil, 'count')
end

.delete(asset, type) ⇒ Object

deletes the asset from the system, irrevocably purging assets and tags



75
76
77
# File 'lib/little/asset.rb', line 75

def self.delete(asset, type)
  Little.delete(:assets, {:asset => asset, :type => type, :verify => 'kludge'}, [:asset, :type, :verify])
end

.for_asset(asset, type, page, records, vote = nil, rated_only = nil) ⇒ Object

gets all the users who like an asset



50
51
52
# File 'lib/little/asset.rb', line 50

def self.for_asset(asset, type, page, records, vote = nil, rated_only = nil)
  Little.get(:assets, {:asset => asset, :type => type, :page => page, :records => records, :vote => vote, :rate => rated_only})
end

.for_asset_count(asset, type, vote = nil, rated_only = nil) ⇒ Object

gets the number of users who like an asset



55
56
57
# File 'lib/little/asset.rb', line 55

def self.for_asset_count(asset, type, vote = nil, rated_only = nil)
  Little.get(:assets, {:asset => asset, :type => type, :count => true, :vote => vote, :rate => rated_only})
end

.for_user(user, page, records, vote = nil, rated_only = nil) ⇒ Object

gets all the user’s assets params [bool] vote true or false to get assets voted for or against, or nil to get all params [bool] rated_only true or false to get assets the user rated, or nil to get all



40
41
42
# File 'lib/little/asset.rb', line 40

def self.for_user(user, page, records, vote = nil, rated_only = nil)
  Little.get(:assets, {:user => user, :page => page, :records => records, :vote => vote, :rate => rated_only})
end

.for_user_count(user, vote = nil, rated_only = nil) ⇒ Object

gets the number of assets the user likes



45
46
47
# File 'lib/little/asset.rb', line 45

def self.for_user_count(user, vote = nil, rated_only = nil)
  Little.get(:assets, {:user => user, :count => true, :vote => vote, :rate => rated_only})
end

.highest_rated(type, page, records) ⇒ Object

gets the assets liked by type, ordered by number of likes (desc)



60
61
62
# File 'lib/little/asset.rb', line 60

def self.highest_rated(type, page, records)
  Little.get(:assets, {:type => type, :page => page, :records => records}, nil, 'by_rate')
end

.most_votes(type, page, records) ⇒ Object

gets the assets liked by type, ordered by number of likes (desc)



65
66
67
# File 'lib/little/asset.rb', line 65

def self.most_votes(type, page, records)
  Little.get(:assets, {:type => type, :page => page, :records => records}, nil, 'by_vote')
end

.rate(user, asset, type, rating) ⇒ Object

rates an asset params [int] rating the rating

Parameters:

  • user (String)

    the user who likes the asset

  • asset (String)

    the asset being liked

  • type (int)

    the type of asset



23
24
25
# File 'lib/little/asset.rb', line 23

def self.rate(user, asset, type, rating)
  Little.post(:assets, {:user => user, :asset => asset, :type => type, :rate => rating}, [:user, :asset, :type], 'rate')
end

.sign_rate(user, asset, type) ⇒ Object

generates a signature for rating an asset (useful when using the javascript library)



28
29
30
# File 'lib/little/asset.rb', line 28

def self.sign_rate(user, asset, type)
  Little.sign(:assets, {:user => user, :asset => asset, :type => type})
end

.sign_vote(user, asset, type) ⇒ Object

generates a signature for voting on an asset (useful when using the javascript library)



14
15
16
# File 'lib/little/asset.rb', line 14

def self.sign_vote(user, asset, type)
  Little.sign(:assets, {:user => user, :asset => asset, :type => type})
end

.user_asset(user, asset, type) ⇒ Object

does the user like the asset



33
34
35
# File 'lib/little/asset.rb', line 33

def self.user_asset(user, asset, type)
  Little.get(:assets, {:user => user, :asset => asset, :type => type})
end

.vote(user, asset, type, up_or_down) ⇒ Object

votes for an asset params [symbol] up_or_down either :up or :down

Parameters:

  • user (String)

    the user who likes the asset

  • asset (String)

    the asset being liked

  • type (int)

    the type of asset



9
10
11
# File 'lib/little/asset.rb', line 9

def self.vote(user, asset, type, up_or_down)
  Little.post(:assets, {:user => user, :asset => asset, :type => type, :vote => up_or_down == :up}, [:user, :asset, :type], 'vote')
end