1
0
mirror of https://github.com/seejohnrun/haste-client.git synced 2025-12-16 16:51:29 +00:00

28 Commits

Author SHA1 Message Date
John Crepezzi
dfb69c5e0d Fix RSpec dependencies 2017-01-30 21:56:07 -05:00
John Crepezzi
f79b70da61 Bump version 2017-01-30 21:51:41 -05:00
John Crepezzi
898884f07c default URL https 2017-01-30 21:51:03 -05:00
John Crepezzi
3ba2c53587 Added another entry to the alternates section of the README 2015-09-17 10:29:12 -04:00
John Crepezzi
94b2a4fbec Upgrade to RSpec 3 2014-11-01 10:40:23 -04:00
John Crepezzi
3a1d4045b3 Some gemspec changes 2014-11-01 10:35:37 -04:00
John Crepezzi
82ae343455 Update specs & fix Rakefile 2014-11-01 10:31:58 -04:00
John Crepezzi
22ea2e9e3c Bump version to 0.2.1 2014-11-01 10:24:07 -04:00
John Crepezzi
b6113d9fd3 Merge branch 'master' of github.com:seejohnrun/haste-client 2014-11-01 10:22:53 -04:00
John Crepezzi
a98f4d765e Remove bundler/setup 2014-11-01 10:22:40 -04:00
John Crepezzi
94e2d1db1c Bump version 2014-08-20 10:49:40 -04:00
John Crepezzi
689387da3f Merge pull request #22 from raincoats/patch-1
fixed typo
2014-08-02 14:00:49 -07:00
raincoats
8ca0daab3b fixed typo 2014-07-30 16:56:13 +10:00
John Crepezzi
bfa7edda96 Update README.md
Construct Github pull request (using in-web editor) for awesome committer.

Closes #20
2014-02-05 08:17:23 -05:00
John Crepezzi
a83c921aa5 Remove bundler/setup from lib 2013-11-16 13:36:52 -05:00
John Crepezzi
326ac91e2a 1.8.7 support
Closes #19
2013-11-16 11:06:21 -05:00
John Crepezzi
b153c49aa1 Remove support 2013-11-16 10:21:40 -05:00
John Crepezzi
3fca7c72c8 Tests working in 1.9.2 2013-11-16 10:18:12 -05:00
John Crepezzi
e5a6d39422 travis config 2013-11-16 10:13:24 -05:00
John Crepezzi
f299892b37 Add tests back to Rakefile 2013-11-16 10:12:19 -05:00
John Crepezzi
425c80e318 rake dep 2013-11-16 10:11:29 -05:00
John Crepezzi
65d221d85c Add --raw option
Closes #17
2013-11-16 10:08:16 -05:00
John Crepezzi
b32cff6932 Update README 2013-11-16 10:01:33 -05:00
John Crepezzi
dd1c0178fc README 2013-11-16 10:00:24 -05:00
John Crepezzi
b7528b603b Merge pull request #18 from seejohnrun/rest-client
Rest client
2013-11-16 06:59:16 -08:00
John Crepezzi
a3fbc9e681 Revert "Adds Basic HTTP Auth support"
This reverts commit 1cdb3b7746.
2013-11-16 09:58:26 -05:00
John Crepezzi
d6b5954aac Merge pull request #16 from brunobuccolo/basic_auth
Adds Basic HTTP Auth support
2013-11-16 06:56:48 -08:00
Bruno Buccolo
1cdb3b7746 Adds Basic HTTP Auth support 2013-11-11 17:18:50 -02:00
11 changed files with 93 additions and 51 deletions

9
.travis.yml Normal file
View File

@@ -0,0 +1,9 @@
script: "rspec spec"
branches:
only:
- master
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0

View File

@@ -1,2 +1,3 @@
source 'https://rubygems.org'
gemspec
gem 'transpec'

View File

@@ -1,5 +1,7 @@
# Haste Client
[![Build Status](https://secure.travis-ci.org/seejohnrun/haste-client.png)](http://travis-ci.org/seejohnrun/haste-client)
haste-client is a simple client for uploading data to haste-server. All you do it pipe data in STDIN:
`cat file | haste`
@@ -19,24 +21,25 @@ after which the contents of `file` will be accessible at a URL which has been co
gem install haste
```
## Support
Please consider paying what you think haste-client is worth:
<a href="https://www.stripeme.com/pay/1r2f">
<img alt="Pay" src="https://www.stripeme.com/pay.jpg" />
</a>
## Making uploading file contents easier
If you supply a valid file path as argument #1 to the client, it will be uploaded:
``` bash
# equivelant
# equivalent
cat file | haste
haste file
```
## You can get the raw version
Want the raw URL returned instead? (a plain-text version)?
``` bash
cat file | haste --raw # or
haste file --raw
```
## Changing the location of your haste server
By default, haste will point at `http://hastebin.com`. You can change this by setting the value of `ENV['HASTE_SERVER']` to the URL of your haste server. You can also 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 this into ~.bash_profile:
@@ -52,8 +55,10 @@ After which you can use `work_haste` to send hastes to that server instead.
You can also use `Haste` as a library to upload hastes:
``` ruby
require 'haste'
uploader = Haste::Uploader.new
uploader.upload_raw 'this is my data' # key
uploader.upload_path '/tmp/whaaaa' # key
```
## Windows Support
@@ -62,18 +67,21 @@ If you'd like an alternative on Windows that supports functionality similar to `
## Lightweight Alternative
Han Boetes has contributed a simple shell-script alternative for those not interested in installing a RubyGem:
Han Boetes and @nickthename have contributed a simple shell-script alternative for those not interested in installing a RubyGem:
``` bash
haste(){ ( echo "% $@"; eval "$@" ) | curl -F "$@=<-" http://hastebin.com/documents|awk -F '"' '{print "http://hastebin.com/"$4}'}
haste() { a=$(cat); curl -X POST -s -d "$a" http://hastebin.com/documents | awk -F '"' '{print "http://hastebin.com/"$4}'; }
```
Usage:
``` bash
haste `cat index.html
cat file.txt | haste
```
And a more expansive BASH option by @diethnis can be found at:
https://github.com/diethnis/standalones/blob/master/hastebin.sh
## Author
John Crepezzi <john.crepezzi@gmail.com>

View File

@@ -1,6 +1,9 @@
require 'rspec/core/rake_task'
require File.dirname(__FILE__) + '/lib/haste/version'
task :build do
RSpec::Core::RakeTask.new(:spec)
task :build => :spec do
system "gem build haste.gemspec"
end

View File

@@ -1,13 +1,15 @@
require 'rubygems'
require File.dirname(__FILE__) + '/lib/haste/version'
spec = Gem::Specification.new do |s|
Gem::Specification.new do |s|
s.name = 'haste'
s.author = 'John Crepezzi'
s.add_development_dependency('rspec')
s.add_dependency('json')
s.add_dependency('rest-client')
s.add_dependency('faraday', '~> 0.9')
s.description = 'CLI Haste Client'
s.license = 'MIT License'
s.homepage = 'https://github.com/seejohnrun/haste-client'
s.email = 'john.crepezzi@gmail.com'
s.executables = 'haste'
s.files = Dir['lib/**/*.rb', 'haste']

View File

@@ -1,7 +1,3 @@
require 'bundler/setup'
require 'json'
require 'uri'
require 'rest-client'
require File.dirname(__FILE__) + '/haste/uploader'
require File.dirname(__FILE__) + '/haste/exception'
require File.dirname(__FILE__) + '/haste/cli'

View File

@@ -10,13 +10,18 @@ module Haste
# And then handle the basic usage
def start
# Take data in
key = if STDIN.tty?
@uploader.upload_path ARGV.first
if STDIN.tty?
key = @uploader.upload_path ARGV.first
else
@uploader.upload_raw STDIN.readlines.join
key = @uploader.upload_raw STDIN.readlines.join
end
# Put together a URL
if ARGV.include?('--raw')
url = "#{@uploader.server_url}/raw/#{key}"
else
url = "#{@uploader.server_url}/#{key}"
end
# And write data out
url = "#{@uploader.server_url}/#{key}"
if STDOUT.tty?
STDOUT.puts url
else

View File

@@ -1,6 +1,9 @@
require 'json'
require 'faraday'
module Haste
DEFAULT_URL = 'http://hastebin.com'
DEFAULT_URL = 'https://hastebin.com'
class Uploader
@@ -22,19 +25,31 @@ module Haste
# Take in data and return a key
def upload_raw(data)
data.rstrip!
raw_data = RestClient.post "#{self.server_url}/documents", data
data = JSON.parse(raw_data)
data['key']
response = do_post data
if response.status == 200
data = JSON.parse(response.body)
data['key']
else
fail_with "failure uploading: #{response.body}"
end
rescue JSON::ParserError => e
fail_with "failure parsing response: #{e.message}"
rescue RestClient::Exception => e
fail_with "failure uploading: #{e.message}"
rescue Errno::ECONNREFUSED => e
fail_with "failure connecting: #{e.message}"
end
private
def do_post(data)
connection.post('/documents', data)
end
def connection
@connection ||= Faraday.new(:url => server_url) do |c|
c.adapter Faraday.default_adapter
end
end
def fail_with(msg)
raise Exception.new(msg)
end

View File

@@ -1,5 +1,5 @@
module Haste
VERSION = '0.1.7'
VERSION = '0.2.2'
end

View File

@@ -2,12 +2,11 @@ require 'spec_helper'
describe Haste::Uploader do
let(:uploader) { base.nil? ? Haste::Uploader.new : Haste::Uploader.new(base) }
let(:uploader) { Haste::Uploader.new(base) }
describe :upload_raw do
let(:data) { 'hello world' }
let(:url) { "#{uploader.server_url}/documents" }
let(:base) { nil }
let(:error_message) do
begin
@@ -23,12 +22,13 @@ describe Haste::Uploader do
let(:json) { '{"key":"hello"}' }
before do
RestClient.should_receive(:post).with(url, data).and_return(json)
ostruct = OpenStruct.new(:status => 200, :body => json)
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_return(ostruct)
end
it 'should get the key' do
error_message.should be_nil # no error
@key.should == 'hello'
expect(error_message).to be_nil # no error
expect(@key).to eq('hello')
end
end
@@ -38,11 +38,12 @@ describe Haste::Uploader do
let(:json) { '{that:not_even_json}' }
before do
RestClient.should_receive(:post).with(url, data).and_return(json)
ostruct = OpenStruct.new(:status => 200, :body => json)
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_return(ostruct)
end
it 'should get an error' do
error_message.should start_with 'failure parsing response: '
expect(error_message).to start_with('failure parsing response: ')
end
end
@@ -50,12 +51,12 @@ describe Haste::Uploader do
context 'with a 404 response' do
before do
error = RestClient::ResourceNotFound.new
RestClient.should_receive(:post).with(url, data).and_raise(error)
ostruct = OpenStruct.new(:status => 404, :body => 'ohno')
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_return(ostruct)
end
it 'should get an error' do
error_message.should == 'failure uploading: Resource Not Found'
expect(error_message).to eq('failure uploading: ohno')
end
end
@@ -64,11 +65,11 @@ describe Haste::Uploader do
before do
error = Errno::ECONNREFUSED
RestClient.should_receive(:post).with(url, data).and_raise(error)
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_raise(error)
end
it 'should get the key' do
error_message.should == 'failure connecting: Connection refused'
expect(error_message).to eq('failure connecting: Connection refused')
end
end
@@ -92,7 +93,7 @@ describe Haste::Uploader do
let(:path) { nil }
it 'should have an error' do
error_message.should == 'No input file given'
expect(error_message).to eq('No input file given')
end
end
@@ -102,7 +103,7 @@ describe Haste::Uploader do
let(:path) { '/tmp/why-do-you-have-a-file-called-john' }
it 'should have an error' do
error_message.should == "#{path}: No such path"
expect(error_message).to eq("#{path}: No such path")
end
end
@@ -111,14 +112,14 @@ describe Haste::Uploader do
let(:data) { 'hello world' }
let(:path) { '/tmp/real' }
before { File.write(path, data) }
before { File.open(path, 'w') { |f| f.write(data) } }
before do
uploader.should_receive(:upload_raw).with(data) # check
expect(uploader).to receive(:upload_raw).with(data) # check
end
it 'should not receive an error' do
error_message.should be_nil
expect(error_message).to be_nil
end
end
@@ -134,7 +135,7 @@ describe Haste::Uploader do
let(:base) { nil }
it 'should use the default url' do
server_url.should == Haste::DEFAULT_URL
expect(server_url).to eq(Haste::DEFAULT_URL)
end
end
@@ -147,11 +148,11 @@ describe Haste::Uploader do
let(:base) { @string }
it 'should remove the slash' do
server_url.should == @string.chop
expect(server_url).to eq(@string.chop)
end
it 'should not modify the original' do
@string.should == 'hello/'
expect(@string).to eq('hello/')
end
end
@@ -161,7 +162,7 @@ describe Haste::Uploader do
let(:base) { 'hello' }
it 'should not chop the url' do
server_url.should == base
expect(server_url).to eq(base)
end
end

View File

@@ -1 +1,3 @@
require 'ostruct'
require File.dirname(__FILE__) + '/../lib/haste'