shoutcast_status 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,8 @@ require "open-uri"
2
2
  require "johnson"
3
3
 
4
4
  class ShoutcastStatus
5
- DEFAULT_INFO_URL = "http://%s/cast/js.php/%s/streaminfo"
5
+ DEFAULT_ENDPOINT = "http://%s/cast/"
6
+ DEFAULT_INFO_PATH = "js.php/%s/streaminfo"
6
7
 
7
8
  DUMMY_CALLBACK = <<-END
8
9
  function cc_streaminfo_get_callback(details){
@@ -12,12 +13,15 @@ class ShoutcastStatus
12
13
 
13
14
  # Create a ShoutcastStatus instance for a given station.
14
15
  # If one parameter is given, it is taken as the url to the now playing JSONP
15
- # callback. If two parameters are given, they are interpreted as the station
16
- # host and station name; the information URL will be inferred from this.
16
+ # callback or the playlist. If two parameters are given, they are interpreted
17
+ # as the station host and station name; the information URL will be inferred
18
+ # from this.
17
19
  #
18
20
  def initialize(url_or_host, station=nil)
19
21
  if station
20
- @info_url = DEFAULT_INFO_URL % [url_or_host, station]
22
+ @info_url = (DEFAULT_ENDPOINT % url_or_host) + (DEFAULT_INFO_PATH % station)
23
+ elsif m = url_or_host.match(%r{^(.*?/)tunein.php/([^/]+)/playlist.pls$})
24
+ @info_url = m[1] + (DEFAULT_INFO_PATH % m[2])
21
25
  else
22
26
  @info_url = url_or_host
23
27
  end
@@ -15,6 +15,15 @@ class ShoutcastStatusTest < Test::Unit::TestCase
15
15
  sc.stream_info
16
16
  end
17
17
 
18
+ def test_should_convert_tunein_url_to_status_url
19
+ io = StringIO.new("cc_streaminfo_get_callback({});")
20
+ sc = ShoutcastStatus.new("http://example.com/arbitrary/location/tunein.php/punkrock/playlist.pls")
21
+ sc.expects(:open).
22
+ with("http://example.com/arbitrary/location/js.php/punkrock/streaminfo").
23
+ yields(io)
24
+ sc.stream_info
25
+ end
26
+
18
27
  def test_should_use_url_as_supplied
19
28
  io = StringIO.new("cc_streaminfo_get_callback({});")
20
29
  sc = ShoutcastStatus.new("http://example.com/some/path")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoutcast_status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-07-09 00:00:00 +01:00
12
+ date: 2010-07-19 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency