Class: AudioAddict::Channel
Instance Attribute Summary collapse
#properties
Instance Method Summary
collapse
#inspect
#method_missing, #respond_to_missing?
Methods included from Cache
#cache, #cache_dir, #cache_dir!, #cache_life, #cache_life!
Constructor Details
#initialize(radio, properties) ⇒ Channel
Returns a new instance of Channel.
9
10
11
|
# File 'lib/audio_addict/channel.rb', line 9
def initialize(radio, properties)
@radio, @properties = radio, properties
end
|
Instance Attribute Details
#radio ⇒ Object
Returns the value of attribute radio.
7
8
9
|
# File 'lib/audio_addict/channel.rb', line 7
def radio
@radio
end
|
Instance Method Details
#active? ⇒ Boolean
17
18
19
20
21
22
23
|
# File 'lib/audio_addict/channel.rb', line 17
def active?
return false if !properties['asset_id']
return false if name[0] == 'X' and key[0] != 'x'
return true
end
|
#current_track ⇒ Object
34
35
36
|
# File 'lib/audio_addict/channel.rb', line 34
def current_track
track_history.first
end
|
#inspectable ⇒ Object
13
14
15
|
# File 'lib/audio_addict/channel.rb', line 13
def inspectable
[:key, :name, :id]
end
|
#similar_channels ⇒ Object
38
39
40
41
42
43
|
# File 'lib/audio_addict/channel.rb', line 38
def similar_channels
similar = properties['similar_channels']
return [] unless similar
ids = similar.map { |s| s['similar_channel_id'] }
radio.search_by_id ids
end
|
#track_history ⇒ Object
25
26
27
|
# File 'lib/audio_addict/channel.rb', line 25
def track_history
@track_history ||= track_history!
end
|
#track_history! ⇒ Object
29
30
31
32
|
# File 'lib/audio_addict/channel.rb', line 29
def track_history!
response = radio.api.get "track_history/channel/#{id}"
response.map { |track| Track.new self, track }
end
|
#vote(direction = :up, track: nil) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/audio_addict/channel.rb', line 45
def vote(direction = :up, track: nil)
track ||= current_track.id
endpoint = "tracks/#{track}/vote/#{id}"
if direction == :delete
radio.api.delete endpoint
else
radio.api.post "#{endpoint}/#{direction}"
end
log_like if direction == :up and Config.like_log
end
|