Created
December 22, 2009 14:43
-
-
Save cloudvoxcode/261781 to your computer and use it in GitHub Desktop.
Cloudvox sound uploader - see help.cloudvox.com
This file contains 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
#!/usr/bin/env ruby -w | |
require 'net/http' | |
require 'net/https' | |
begin | |
require 'net/http/post/multipart' | |
rescue LoadError | |
puts "This requires multipart-post." | |
puts " $ sudo gem install multipart-post" | |
exit(1) | |
end | |
subdomain, username, password, file, filename = *ARGV | |
if file.nil? | |
puts "Usage: #{File.basename($0)} <subdomain> <username> <password> <file> [filename]" | |
puts "Example: #{File.basename($0)} mycvhostname sergey@gmail.com mycvpassword ~/path/to/file.mp3" | |
exit(1) | |
end | |
filename ||= File.basename(file) | |
url = URI.parse("https://#{subdomain}.cloudvox.com/s/upload/sounds/#{filename}") | |
req = Net::HTTP::Post::Multipart.new(url.path, | |
{ 'sound' => UploadIO.new(file, 'application/octet-stream') }, | |
{ 'Accept' => 'application/json' }) | |
req.basic_auth(username, password) | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = url.port == 443 | |
res = http.start do |http| | |
http.request(req) | |
end | |
puts res.body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment