Browse code

Merge pull request #451 from matthewmccullough/cloudappplugin

Added cloudapp from @holman of @GitHub fame

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