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
12
|
# File 'lib/audio_addict/channel.rb', line 9
def initialize(radio, properties)
@radio = radio
@properties = 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
18
19
20
21
22
23
24
25
|
# File 'lib/audio_addict/channel.rb', line 18
def active?
return false unless properties['asset_id']
return false if (name[0] == 'X') && (key[0] != 'x')
true
end
|
#current_track ⇒ Object
36
37
38
|
# File 'lib/audio_addict/channel.rb', line 36
def current_track
track_history.first
end
|
#inspectable ⇒ Object
14
15
16
|
# File 'lib/audio_addict/channel.rb', line 14
def inspectable
%i[key name id]
end
|
#similar_channels ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/audio_addict/channel.rb', line 40
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
27
28
29
|
# File 'lib/audio_addict/channel.rb', line 27
def track_history
@track_history ||= track_history!
end
|
#track_history! ⇒ Object
31
32
33
34
|
# File 'lib/audio_addict/channel.rb', line 31
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
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/audio_addict/channel.rb', line 48
def vote(direction = :up, track: nil)
track ||= current_track
endpoint = "tracks/#{track.id}/vote/#{id}"
if direction == :delete
radio.api.delete endpoint
else
radio.api.post "#{endpoint}/#{direction}"
end
log_like track if (direction == :up) && Config.like_log
end
|