summaryrefslogtreecommitdiff
path: root/plugins/cloudapp/cloudapp.rb
diff options
context:
space:
mode:
authorRobby Russell <robby@planetargon.com>2011-07-15 08:25:32 -0700
committerRobby Russell <robby@planetargon.com>2011-07-15 08:25:32 -0700
commit9f099ddb83b67302dc5ad4688e4a2cbe9802efae (patch)
tree17ed529092d282fcb983e7824071c816f718072e /plugins/cloudapp/cloudapp.rb
parent858ee947f38d60a14d4f4c93694851511ef9eee0 (diff)
parente43eec99f94c00a6a9d2b30f9c449aff5ab0dfe5 (diff)
downloadzsh-9f099ddb83b67302dc5ad4688e4a2cbe9802efae.tar.gz
zsh-9f099ddb83b67302dc5ad4688e4a2cbe9802efae.tar.bz2
zsh-9f099ddb83b67302dc5ad4688e4a2cbe9802efae.zip
Merge pull request #451 from matthewmccullough/cloudappplugin
Added cloudapp from @holman of @GitHub fame
Diffstat (limited to 'plugins/cloudapp/cloudapp.rb')
-rwxr-xr-xplugins/cloudapp/cloudapp.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/plugins/cloudapp/cloudapp.rb b/plugins/cloudapp/cloudapp.rb
new file mode 100755
index 000000000..a11cfdb32
--- /dev/null
+++ b/plugins/cloudapp/cloudapp.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+#
+# cloudapp
+# Zach Holman / @holman
+#
+# Uploads a file from the command line to CloudApp, drops it into your
+# clipboard (on a Mac, at least).
+#
+# Example:
+#
+# cloudapp drunk-blake.png
+#
+# This requires Aaron Russell's cloudapp_api gem:
+#
+# gem install cloudapp_api
+#
+# Requires you set your CloudApp credentials in ~/.cloudapp as a simple file of:
+#
+# email
+# password
+
+require 'rubygems'
+begin
+ require 'cloudapp_api'
+rescue LoadError
+ puts "You need to install cloudapp_api: gem install cloudapp_api"
+ exit!(1)
+end
+
+config_file = "#{ENV['HOME']}/.cloudapp"
+unless File.exist?(config_file)
+ puts "You need to type your email and password (one per line) into "+
+ "`~/.cloudapp`"
+ exit!(1)
+end
+
+email,password = File.read(config_file).split("\n")
+
+class HTTParty::Response
+ # Apparently HTTPOK.ok? IS NOT OKAY WTFFFFFFFFFFUUUUUUUUUUUUUU
+ # LETS MONKEY PATCH IT I FEEL OKAY ABOUT IT
+ def ok? ; true end
+end
+
+if ARGV[0].nil?
+ puts "You need to specify a file to upload."
+ exit!(1)
+end
+
+CloudApp.authenticate(email,password)
+url = CloudApp::Item.create(:upload, {:file => ARGV[0]}).url
+
+# Say it for good measure.
+puts "Uploaded to #{url}."
+
+# Get the embed link.
+url = "#{url}/#{ARGV[0].split('/').last}"
+
+# Copy it to your (Mac's) clipboard.
+`echo '#{url}' | tr -d "\n" | pbcopy`