class AudioAddict::Radio
Constants
- DOMAINS
- NETWORKS
Attributes
network[R]
Public Class Methods
networks(search = nil)
click to toggle source
# File lib/audio_addict/radio.rb, line 26 def self.networks(search = nil) if search result = NETWORKS.select { |k, v| "#{k} #{v}".downcase.include? search.downcase } result.any? ? result : NETWORKS else NETWORKS end end
new(network)
click to toggle source
# File lib/audio_addict/radio.rb, line 39 def initialize(network) @network = network end
valid_network?(network)
click to toggle source
# File lib/audio_addict/radio.rb, line 35 def self.valid_network?(network) NETWORKS.keys.include? network.to_sym end
Public Instance Methods
[](channel_key)
click to toggle source
# File lib/audio_addict/radio.rb, line 75 def [](channel_key) channels[channel_key] end
api()
click to toggle source
# File lib/audio_addict/radio.rb, line 83 def api @api ||= API.new network end
channels()
click to toggle source
# File lib/audio_addict/radio.rb, line 60 def channels @channels ||= channels! end
domain()
click to toggle source
# File lib/audio_addict/radio.rb, line 51 def domain DOMAINS[network.to_sym] end
inspectable()
click to toggle source
# File lib/audio_addict/radio.rb, line 43 def inspectable [:network] end
name()
click to toggle source
# File lib/audio_addict/radio.rb, line 47 def name NETWORKS[network.to_sym] end
search(query)
click to toggle source
# File lib/audio_addict/radio.rb, line 64 def search(query) channels.select do |key, channel| "#{key} #{channel.name.downcase}".include? query.downcase end end
search_by_id(ids)
click to toggle source
# File lib/audio_addict/radio.rb, line 70 def search_by_id(ids) ids = [ids] unless ids.is_a? Array channels.select { |_key, channel| ids.include? channel.id } end
url_template()
click to toggle source
# File lib/audio_addict/radio.rb, line 55 def url_template channel_path = network == "zenradio" ? "zr%{channel_key}_aac" : "%{channel_key}" "http://prem2.#{domain}:80/#{channel_path}?%{listen_key}" end
valid_channel?(channel)
click to toggle source
# File lib/audio_addict/radio.rb, line 79 def valid_channel?(channel) channels.keys.include? channel end
Private Instance Methods
channels!()
click to toggle source
# File lib/audio_addict/radio.rb, line 89 def channels! response = cache.get "#{network}/channels" do api.get "channels" end result = {} response.map do |channel| key = channel["key"] candidate = Channel.new self, channel result[key] = candidate if candidate.active? end result.sort_by { |key, channel| channel.name }.to_h end