Skip to content

Instantly share code, notes, and snippets.

@RoxasShadow
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save RoxasShadow/9708419 to your computer and use it in GitHub Desktop.

Select an option

Save RoxasShadow/9708419 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'optparse'
options = {}
OptionParser.new do |o|
o.on '-l', '--language LANG', 'Set a language' do |lang|
options[:lang] = lang
end
o.on '-k', '--key KEY', 'Set a secret key' do |key|
options[:key] = key
end
o.on '-f', '--file FILE', 'Paste the given file' do |file|
abort 'File not found' unless File.exist? file
options[:text] = File.read file
end
end.parse!
options[:text] ||= ARGV.join
abort 'Paste cannot be blank' if options[:text].strip.empty?
Net::HTTP.start('pasteling.giovannicapuano.net') { |http|
puts http.post('/api/new', URI.encode_www_form(options)).body
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment