class Shoutcast::Api::Client
Attributes
key[RW]
Public Class Methods
new(key:)
click to toggle source
# File lib/shoutcast/api/client.rb, line 7 def initialize(key:) @key = key end
Public Instance Methods
genre_search( genre:, limit: nil, offset: nil, bitrate: nil, media_type: nil )
click to toggle source
# File lib/shoutcast/api/client.rb, line 39 def genre_search( genre:, limit: nil, offset: nil, bitrate: nil, media_type: nil ) response = RestClient.get( url( path: '/legacy/genresearch', parameters: { genre: genre, limit: build_limit_parameter(limit: limit, offset: offset), br: bitrate, mt: media_type } ) ) parse_stations(response) end
search( keyword:, limit: nil, offset: nil, bitrate: nil, media_type: nil )
click to toggle source
# File lib/shoutcast/api/client.rb, line 18 def search( keyword:, limit: nil, offset: nil, bitrate: nil, media_type: nil ) response = RestClient.get( url( path: '/legacy/stationsearch', parameters: { search: keyword, limit: build_limit_parameter(limit: limit, offset: offset), br: bitrate, mt: media_type } ) ) parse_stations(response) end
top_500()
click to toggle source
# File lib/shoutcast/api/client.rb, line 11 def top_500 response = RestClient.get( url(path: '/legacy/Top500') ) parse_stations(response) end
Private Instance Methods
build_limit_parameter(limit: nil, offset: nil)
click to toggle source
# File lib/shoutcast/api/client.rb, line 82 def build_limit_parameter(limit: nil, offset: nil) return nil if limit.nil? parameter = limit.to_s parameter += ",#{offset}" unless offset.nil? parameter end
parse_stations(response)
click to toggle source
# File lib/shoutcast/api/client.rb, line 72 def parse_stations(response) return [] if response.nil? parsed_response = Nori.new.parse(response) return [] if parsed_response['stationlist'].nil? return [] if parsed_response['stationlist']['station'].nil? Nori.new.parse(response)['stationlist']['station'].map do |attributes| Shoutcast::Api::Station.parse(attributes) end end
url(path:, parameters: {})
click to toggle source
# File lib/shoutcast/api/client.rb, line 64 def url(path:, parameters: {}) Shoutcast::Api::Url.new( path: path, key: key, parameters: parameters ).to_s end