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

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