Class: Metalive::Shoutcast

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/metalive/shoutcast.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Shoutcast

Returns a new instance of Shoutcast.



8
9
10
11
# File 'lib/metalive/shoutcast.rb', line 8

def initialize(options = {})
  options = { :port => 8000 }.update(options)
  options.each_pair { |k,v| send("#{k}=", v) }
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/metalive/shoutcast.rb', line 6

def password
  @password
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/metalive/shoutcast.rb', line 6

def port
  @port
end

#serverObject

Returns the value of attribute server.



6
7
8
# File 'lib/metalive/shoutcast.rb', line 6

def server
  @server
end

Instance Method Details

#base_uriObject



17
18
19
# File 'lib/metalive/shoutcast.rb', line 17

def base_uri
  "http://#{server}:#{port}"
end

#headersObject



25
26
27
# File 'lib/metalive/shoutcast.rb', line 25

def headers
  { "User-Agent" => "ShoutcastDSP (Mozilla Compatible)" }
end

#pathObject



21
22
23
# File 'lib/metalive/shoutcast.rb', line 21

def path
  "/admin.cgi"
end

#query(song) ⇒ Object



13
14
15
# File 'lib/metalive/shoutcast.rb', line 13

def query(song)
  { :mode => "updinfo", :song => song, :pass => password }
end

#update(metadata) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/metalive/shoutcast.rb', line 29

def update()
  song = (Hash ===  ? [:song] : .to_s)
  self.class.get path, :base_uri => base_uri, :query => query(song), :headers => headers
  true
rescue => e
  false
end