#!/usr/bin/env ruby # # # CLI to imagebin.ca # # Copyright (C) 2009 dougsko # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # require 'rubygems' require 'optparse' require 'httpclient' options = { "t" => "file", "name" => "", "tags" => "", "description" => "", "adult" => "f", } opts = OptionParser.new do |opts| opts.banner = "imagebin.rb is a CLI to http://imagebin.ca Example: ./imagebin.rb -f " opts.separator "" opts.separator "Options:" opts.on("-f ", "--file ", String, "Use a file for input") do |file| options[:f] = file end opts.on("-n [name]", "--name [name]", String, "Name") do |n| options[:name] = n end opts.on("-t [tags]", "--tags [tags]", String, "Comma separated") do |tags| options[:tags] = tags end opts.on("-d [description]", "--description [description]", String, "Description") do |desc| options[:description] = desc end opts.on("-p", "--private", "Private") do |priv| options[:adult] = "priv" end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end opts.parse(ARGV) clnt = HTTPClient.new("http://imagebin.ca/upload.php") File.open(options[:f]) do |file| options[:f] = file puts clnt.post('http://imagebin.ca/upload.php', options).content.match(/http.+?\.html/) end