cloudapp.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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`