Class: Request::AudioStream

Inherits:
Base::Event show all
Defined in:
lib/violet/request.rb

Overview

AudioStream events are used with MP3 hyperlinks to make your rabbit play podcasts or webradio. Your rabbit has to be a tag/tag to use AudioStream events (it should be checked at higher level, this class won’t do that for you :))

see api.nabaztag.com/docs/home.html#sendurl

Examples

you can give a String argument, or an Array of String if you want to play several urls, or a Hash with a :url_list key.

AudioStream.new "http://my_streamed_url.com"                 # => #<Request::AudioStream:0x2b44fafd52e0 @args=["http://my_streamed_url.com"]>
AudioStream.new :url_list => "http://my_streamed_url.com"    # => #<Request::AudioStream:0x2b52a24acf70 @args=["http://my_streamed_url.com"]>

AudioStream.new "http://my_streamed_url.com", "http://plop.test"                 # => #<Request::AudioStream:0x2b44fafc9058 @args=["http://my_streamed_url.com", "http://plop.test"]>
AudioStream.new ["http://my_streamed_url.com", "http://plop.test"]               # => #<Request::AudioStream:0x2b44fafbdc30 @args=["http://my_streamed_url.com", "http://plop.test"]>
AudioStream.new :url_list => ["http://my_streamed_url.com", "http://plop.test"]  # => #<Request::AudioStream:0x2b52a24a28e0 @args=["http://my_streamed_url.com", "http://plop.test"]>

Instance Method Summary collapse

Methods inherited from Base::Event

#streamed?

Constructor Details

#initialize(*args) ⇒ AudioStream

take an Array of String or many Strings arguments, each String is a URL to play. Another way to create AudioStream is to give a Hash in argument, with the :url_list keys that contains an Array of Strings or a String. see examples.

Raises:

  • (ArgumentError)


264
265
266
267
268
269
270
271
272
# File 'lib/violet/request.rb', line 264

def initialize *args
  raise ArgumentError.new('no args given') if args.empty? or args.first.empty?
  if args.first.is_a?(Hash)
    args = [ args.first[:url_list] ]
    raise ArgumentError.new('empty :url_list key in Hash argument') if args.first.nil? or args.first.empty?
  end

  @url_list = args.flatten
end

Instance Method Details

#+(other) ⇒ Object

AudioStream object can be added with other AudioStream objects. When you add first to second, the new AudioStream will play all the urls in first, then all the urls in second.

Examples

one = AudioStream.new "http://www.one.com"   # => #<Request::AudioStream:0x2b2d075e0b28 @url_list=["http://www.one.com"]>
two = AudioStream.new "http://www.two.com"   # => #<Request::AudioStream:0x2b2d075db510 @url_list=["http://www.two.com"]>
onetwo = one + two   # => #<Request::AudioStream:0x2b2d075d7a78 @url_list=["http://www.one.com", "http://www.two.com"]>
twoone = two + one   # => #<Request::AudioStream:0x2b2d075cff80 @url_list=["http://www.two.com", "http://www.one.com"]>

Raises:

  • (ArgumentError)


286
287
288
289
# File 'lib/violet/request.rb', line 286

def + other
  raise ArgumentError.new("#{other.inspect} is not a Streamed Event") unless other.streamed?
  AudioStream.new(self.url_list, other.url_list)
end

#==(other) ⇒ Object

compare two AudioStream. AudioStream are equals if and only if they have the same url list.

Raises:

  • (ArgumentError)


292
293
294
295
# File 'lib/violet/request.rb', line 292

def == other
  raise ArgumentError.new("#{other.inspect} is not a Streamed Event") unless other.streamed?
  self.url_list == other.url_list
end

#to_urlObject



274
275
276
# File 'lib/violet/request.rb', line 274

def to_url
  "urlList=#{@url_list.join('|')}"
end