cloudapp.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env ruby
  2. #
  3. # cloudapp
  4. # Zach Holman / @holman
  5. #
  6. # Uploads a file from the command line to CloudApp, drops it into your
  7. # clipboard (on a Mac, at least).
  8. #
  9. # Example:
  10. #
  11. # cloudapp drunk-blake.png
  12. #
  13. # This requires Aaron Russell's cloudapp_api gem:
  14. #
  15. # gem install cloudapp_api
  16. #
  17. # Requires you set your CloudApp credentials in ~/.cloudapp as a simple file of:
  18. #
  19. # email
  20. # password
  21. require 'rubygems'
  22. begin
  23. require 'cloudapp_api'
  24. rescue LoadError
  25. puts "You need to install cloudapp_api: gem install cloudapp_api"
  26. exit!(1)
  27. end
  28. config_file = "#{ENV['HOME']}/.cloudapp"
  29. unless File.exist?(config_file)
  30. puts "You need to type your email and password (one per line) into "+
  31. "`~/.cloudapp`"
  32. exit!(1)
  33. end
  34. email,password = File.read(config_file).split("\n")
  35. class HTTParty::Response
  36. # Apparently HTTPOK.ok? IS NOT OKAY WTFFFFFFFFFFUUUUUUUUUUUUUU
  37. # LETS MONKEY PATCH IT I FEEL OKAY ABOUT IT
  38. def ok? ; true end
  39. end
  40. if ARGV[0].nil?
  41. puts "You need to specify a file to upload."
  42. exit!(1)
  43. end
  44. CloudApp.authenticate(email,password)
  45. url = CloudApp::Item.create(:upload, {:file => ARGV[0]}).url
  46. # Say it for good measure.
  47. puts "Uploaded to #{url}."
  48. # Get the embed link.
  49. url = "#{url}/#{ARGV[0].split('/').last}"
  50. # Copy it to your (Mac's) clipboard.
  51. `echo '#{url}' | tr -d "\n" | pbcopy`