Skip to content

Instantly share code, notes, and snippets.

@plukevdh
Created June 23, 2011 21:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plukevdh/1043721 to your computer and use it in GitHub Desktop.
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)
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
@plukevdh
Copy link
Author

include Twimlet::HoldMusic
generate_playlist

Can be used within Rails by doing
render xml: generate_playlist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment