commit 6edc98fb82901e73b1ea5ac1e12545119b2f2efa Author: John Crepezzi Date: Fri Nov 18 20:26:35 2011 -0500 Initial work diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d289004 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +*.swo +*.gem diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b13107 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Haste Client + +haste-client is a simple client for uploading data to haste. Usage is very simple, all you do it pipe data in STDIN: + +`cat file | haste` + +And once the file makes it to the server, it will print the URL to STDOUT. + +This can be really really cool in combination with `pbcopy`, like: + +`cat file | haste | pbcopy` + +after which the contents of `file` will be accessible at a URL which has been copied to your pasteboard. + +## Changing the location of your haste server + +By default, haste is expected to be running on `http://localhost:7777`, which I'm sure no one is doing. You can change this by setting the value of ENV['HASTE_SERVER'] to the URL of your haste server. You can use `alias` to make easy shortcuts if you commonly use a few hastes intermingled with each other. To do that, you'd put something like + +alias work_haste="HASTE_SERVER=http://something.com haste" + +After which you can use `work_haste` to send hastes there. + +## Author + +John Crepezzi + +## License + +(The MIT License) + +Copyright © 2011 John Crepezzi + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE diff --git a/TODO b/TODO new file mode 100644 index 0000000..8bc2809 --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +tests +remove dependencies diff --git a/bin/haste b/bin/haste new file mode 100755 index 0000000..3c8c0f7 --- /dev/null +++ b/bin/haste @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../lib/haste' + +cli = Haste::CLI.new +cli.start diff --git a/haste.gemspec b/haste.gemspec new file mode 100644 index 0000000..b1b618d --- /dev/null +++ b/haste.gemspec @@ -0,0 +1,18 @@ +require 'rubygems' +require File.dirname(__FILE__) + '/lib/haste/version' + +spec = Gem::Specification.new do |s| + s.name = 'haste' + s.author = 'John Crepezzi' + s.add_development_dependency('rspec') + s.add_dependency('restclient') + s.description = 'CLI Haste Client' + s.email = 'john.crepezzi@gmail.com' + s.executables = 'haste' + s.files = Dir['lib/**/*.rb', 'haste'] + s.platform = Gem::Platform::RUBY + s.require_paths = ['lib'] + s.summary = 'Haste Client' + s.test_files = Dir.glob('spec/*.rb') + s.version = Haste::VERSION +end diff --git a/lib/haste.rb b/lib/haste.rb new file mode 100644 index 0000000..3434f92 --- /dev/null +++ b/lib/haste.rb @@ -0,0 +1,36 @@ +require 'restclient' +require 'json' + +module Haste + + DEFAULT_URL = 'http://localhost:7777' + + class CLI + + attr_reader :input + + # Pull all of the data from STDIN + def initialize + @input = STDIN.readlines.join + @input.strip! + end + + # Upload the and output the URL we get back + def start + json = RestClient.post "#{server}/documents", input + data = JSON.parse(json) + puts "#{server}/#{data['key']}" + end + + private + + def server + return @server if @server + @server = ENV['HASTE_SERVER'] || Haste::DEFAULT_URL + @server.chop! if server.end_with?('/') + @server + end + + end + +end diff --git a/lib/haste/version.rb b/lib/haste/version.rb new file mode 100644 index 0000000..aa640e4 --- /dev/null +++ b/lib/haste/version.rb @@ -0,0 +1,5 @@ +module Haste + + VERSION = '0.0.1' + +end