class AudioAddict::Channel
Attributes
radio[R]
Public Class Methods
new(radio, properties)
click to toggle source
# File lib/audio_addict/channel.rb, line 9 def initialize(radio, properties) @radio, @properties = radio, properties end
Public Instance Methods
active?()
click to toggle source
# File lib/audio_addict/channel.rb, line 17 def active? # Seems like each network has a different way of marking inactive channels. # This is where we normalize it return false if !properties["asset_id"] return false if name[0] == "X" and key[0] != "x" return true end
current_track()
click to toggle source
# File lib/audio_addict/channel.rb, line 34 def current_track track_history.first end
inspectable()
click to toggle source
# File lib/audio_addict/channel.rb, line 13 def inspectable [:key, :name, :id] end
similar_channels()
click to toggle source
# 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()
click to toggle source
# File lib/audio_addict/channel.rb, line 25 def track_history @track_history ||= track_history! end
track_history!()
click to toggle source
# 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)
click to toggle source
# File lib/audio_addict/channel.rb, line 45 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 and Config.like_log end
Private Instance Methods
log_like(track = nil)
click to toggle source
# File lib/audio_addict/channel.rb, line 60 def log_like(track = nil) track ||= current_track message = "#{radio.name} :: #{name} :: #{track.artist} :: #{track.title}" file = Config.like_log File.append file, message unless File.contains? file, message end