Created
June 23, 2011 21:49
-
-
Save plukevdh/1043721 to your computer and use it in GitHub Desktop.
Replicating functionality of the hold music "twimlet" from Twilio (http://labs.twilio.com/twimlets/holdmusic)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
require 'twilio' | |
module Twimlet | |
module HoldMusic | |
include HTTParty | |
AWS_URL = "s3.amazonaws.com" | |
def generate_playlist(bukkit='com.twilio.music.classical', options={}) | |
@bucket = "http://#{bukkit}.#{AWS_URL}" | |
@options = options | |
get_response | |
end | |
private | |
def get_response | |
Twilio::TwiML.build do |res| | |
parse_bukkit.each do |obj| | |
next unless obj =~ /(\.mp3|\.wav|\.ul)$/ | |
res.play "#{@bucket}/#{obj}" | |
res.say @options[:message] if @options[:message] | |
end | |
res.redirect(@options[:redirect] || "/") | |
end | |
end | |
def parse_bukkit | |
listing = Twimlet::HoldMusic.get @bucket | |
listing.parsed_response['ListBucketResult']['Contents'].map {|c| c['Key']} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can be used within Rails by doing
render xml: generate_playlist