]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/cloudapp/cloudapp.rb
add xbindkeysrc
[dotfiles.git] / zsh / plugins / cloudapp / cloudapp.rb
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
22 require 'rubygems'
23 begin
24 require 'cloudapp_api'
25 rescue LoadError
26 puts "You need to install cloudapp_api: gem install cloudapp_api"
27 exit!(1)
28 end
29
30 config_file = "#{ENV['HOME']}/.cloudapp"
31 unless File.exist?(config_file)
32 puts "You need to type your email and password (one per line) into "+
33 "`~/.cloudapp`"
34 exit!(1)
35 end
36
37 email,password = File.read(config_file).split("\n")
38
39 class HTTParty::Response
40 # Apparently HTTPOK.ok? IS NOT OKAY WTFFFFFFFFFFUUUUUUUUUUUUUU
41 # LETS MONKEY PATCH IT I FEEL OKAY ABOUT IT
42 def ok? ; true end
43 end
44
45 if ARGV[0].nil?
46 puts "You need to specify a file to upload."
47 exit!(1)
48 end
49
50 CloudApp.authenticate(email,password)
51 url = CloudApp::Item.create(:upload, {:file => ARGV[0]}).url
52
53 # Say it for good measure.
54 puts "Uploaded to #{url}."
55
56 # Get the embed link.
57 url = "#{url}/#{ARGV[0].split('/').last}"
58
59 # Copy it to your (Mac's) clipboard.
60 `echo '#{url}' | tr -d "\n" | pbcopy`