Class: CUI8Tracks::Set

Inherits:
Object
  • Object
show all
Includes:
Thing
Defined in:
lib/cui8tracks/set.rb

Instance Attribute Summary collapse

Attributes included from Thing

#session

Instance Method Summary collapse

Methods included from Thing

#api, #id, #logger, #method_missing, #notify, #set

Constructor Details

#initializeSet

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

#pageObject

Returns the value of attribute page.



3
4
5
# File 'lib/cui8tracks/set.rb', line 3

def page
  @page
end

#per_pageObject

Returns the value of attribute per_page.



3
4
5
# File 'lib/cui8tracks/set.rb', line 3

def per_page
  @per_page
end

#qObject

Returns the value of attribute q.



3
4
5
# File 'lib/cui8tracks/set.rb', line 3

def q
  @q
end

#sortObject

Returns the value of attribute sort.



3
4
5
# File 'lib/cui8tracks/set.rb', line 3

def sort
  @sort
end

#tagObject

Returns the value of attribute tag.



3
4
5
# File 'lib/cui8tracks/set.rb', line 3

def tag
  @tag
end

#total_entriesObject (readonly)

Returns the value of attribute total_entries.



20
21
22
# File 'lib/cui8tracks/set.rb', line 20

def total_entries
  @total_entries
end

#userObject

Returns the value of attribute user.



3
4
5
# File 'lib/cui8tracks/set.rb', line 3

def user
  @user
end

Instance Method Details

#dataObject

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

#infoObject



11
12
13
# File 'lib/cui8tracks/set.rb', line 11

def info
  super(self.query)
end

#mixesObject



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

#pathObject



43
44
45
# File 'lib/cui8tracks/set.rb', line 43

def path
  @user ? "/users/#{@user}/mixes" : "/mixes"
end

#queryObject



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