Class: Icecast::Server

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/icecast/server.rb

Defined Under Namespace

Classes: NullCache, Status, StreamStatus

Constant Summary collapse

@@cache =
default_cache

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Server

Returns a new instance of Server.



10
11
12
13
14
# File 'lib/icecast/server.rb', line 10

def initialize(attributes = {})
  attributes.each do |k,v|
    send "#{k}=", v
  end
end

Instance Attribute Details

#admin_passwordObject

Returns the value of attribute admin_password.



8
9
10
# File 'lib/icecast/server.rb', line 8

def admin_password
  @admin_password
end

#hostObject

Returns the value of attribute host.



8
9
10
# File 'lib/icecast/server.rb', line 8

def host
  @host
end

#portObject

Returns the value of attribute port.



8
9
10
# File 'lib/icecast/server.rb', line 8

def port
  @port
end

Class Method Details

.default_cacheObject



32
33
34
# File 'lib/icecast/server.rb', line 32

def self.default_cache
  defined?(Rails) ? Rails.cache : NullCache.new
end

Instance Method Details

#authentificationObject



20
21
22
# File 'lib/icecast/server.rb', line 20

def authentification
  { :username => 'admin', :password => admin_password }
end

#statusObject



46
47
48
# File 'lib/icecast/server.rb', line 46

def status
  Status.new xml_status
end

#url_for(path) ⇒ Object



16
17
18
# File 'lib/icecast/server.rb', line 16

def url_for(path)
  "http://#{host}:8000/#{path}"
end

#xml_statusObject



39
40
41
42
43
44
# File 'lib/icecast/server.rb', line 39

def xml_status
  cache.fetch("Icecast::Status::#{host}_#{port}", :expires_in => 60, :race_condition_ttl => 5) do
    Icecast.logger.info "Retrieve Icecast status from #{host}"
    self.class.get url_for("admin/stats"), :basic_auth => authentification
  end
end