forked from holman/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcloudapp
executable file
·62 lines (53 loc) · 1.27 KB
/
cloudapp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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'
['json', 'cloudapp_api'].each do |gem|
begin
require gem
rescue LoadError
puts "You need to install #{gem}: gem install #{gem}"
exit!(1)
end
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")
if ARGV[0].nil?
puts "You need to specify a file to upload."
exit!(1)
end
urls = []
ARGV.each do |x|
CloudApp.authenticate(email,password)
puts "Attempting to upload #{x}"
url = CloudApp::Item.create(:upload, {:file => x}).url
# Say it for good measure.
puts "Uploaded #{x} to #{url}"
# Get the embed link.
url = "#{url}/#{ARGV[0].split('/').last}"
urls << url
end
# Copy it to your (Mac's) clipboard.
`echo '#{urls.join(',')}' | tr -d "\n" | pbcopy`