Class: CUI8Tracks::Set
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#q ⇒ Object
Returns the value of attribute q.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#total_entries ⇒ Object
readonly
Returns the value of attribute total_entries.
-
#user ⇒ Object
Returns the value of attribute user.
Attributes included from Thing
Instance Method Summary collapse
-
#data ⇒ Object
to access session.set.play_token.
- #each_mix(&block) ⇒ Object
- #info ⇒ Object
-
#initialize ⇒ Set
constructor
A new instance of Set.
- #mixes ⇒ Object
- #path ⇒ Object
- #query ⇒ Object
Methods included from Thing
#api, #id, #logger, #method_missing, #notify, #set
Constructor Details
#initialize ⇒ Set
Returns a new instance of Set.
4 5 6 7 8 9 |
# File 'lib/cui8tracks/set.rb', line 4 def initialize # default config @per_page = 1 @page = 1 @sort = 'hot' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CUI8Tracks::Thing
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
3 4 5 |
# File 'lib/cui8tracks/set.rb', line 3 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
3 4 5 |
# File 'lib/cui8tracks/set.rb', line 3 def per_page @per_page end |
#q ⇒ Object
Returns the value of attribute q.
3 4 5 |
# File 'lib/cui8tracks/set.rb', line 3 def q @q end |
#sort ⇒ Object
Returns the value of attribute sort.
3 4 5 |
# File 'lib/cui8tracks/set.rb', line 3 def sort @sort end |
#tag ⇒ Object
Returns the value of attribute tag.
3 4 5 |
# File 'lib/cui8tracks/set.rb', line 3 def tag @tag end |
#total_entries ⇒ Object (readonly)
Returns the value of attribute total_entries.
20 21 22 |
# File 'lib/cui8tracks/set.rb', line 20 def total_entries @total_entries end |
#user ⇒ Object
Returns the value of attribute user.
3 4 5 |
# File 'lib/cui8tracks/set.rb', line 3 def user @user end |
Instance Method Details
#data ⇒ Object
to access session.set.play_token
16 17 18 |
# File 'lib/cui8tracks/set.rb', line 16 def data @data ||= api.get('/sets/new') end |
#each_mix(&block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cui8tracks/set.rb', line 31 def each_mix(&block) loop { current_mixes = mixes return if current_mixes.empty? current_mixes.each{ |mix| yield mix } @page += 1 } end |
#info ⇒ Object
11 12 13 |
# File 'lib/cui8tracks/set.rb', line 11 def info super(self.query) end |
#mixes ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/cui8tracks/set.rb', line 21 def mixes got = api.get(path, query) @total_entries = got['total_entries'] got['mixes'].map{|mix_data| mix = CUI8Tracks::Mix.new(mix_data) mix.session = self.session mix } end |
#path ⇒ Object
43 44 45 |
# File 'lib/cui8tracks/set.rb', line 43 def path @user ? "/users/#{@user}/mixes" : "/mixes" end |
#query ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cui8tracks/set.rb', line 47 def query { :q => @q, :tag => @tag, :sort => @sort, :page => @page, :per_page => @per_page }.each_pair.inject({}){|a, pair| key, value = *pair a.update({key => value}) if value a } end |