mirror of
https://github.com/seejohnrun/haste-client.git
synced 2025-12-17 09:11:29 +00:00
Compare commits
21 Commits
rest-clien
...
v0.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22ea2e9e3c | ||
|
|
b6113d9fd3 | ||
|
|
a98f4d765e | ||
|
|
94e2d1db1c | ||
|
|
689387da3f | ||
|
|
8ca0daab3b | ||
|
|
bfa7edda96 | ||
|
|
a83c921aa5 | ||
|
|
326ac91e2a | ||
|
|
b153c49aa1 | ||
|
|
3fca7c72c8 | ||
|
|
e5a6d39422 | ||
|
|
f299892b37 | ||
|
|
425c80e318 | ||
|
|
65d221d85c | ||
|
|
b32cff6932 | ||
|
|
dd1c0178fc | ||
|
|
b7528b603b | ||
|
|
a3fbc9e681 | ||
|
|
d6b5954aac | ||
|
|
1cdb3b7746 |
9
.travis.yml
Normal file
9
.travis.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
script: "rspec spec"
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
rvm:
|
||||||
|
- 1.8.7
|
||||||
|
- 1.9.2
|
||||||
|
- 1.9.3
|
||||||
|
- 2.0.0
|
||||||
29
README.md
29
README.md
@@ -1,5 +1,7 @@
|
|||||||
# Haste Client
|
# Haste Client
|
||||||
|
|
||||||
|
[](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:
|
haste-client is a simple client for uploading data to haste-server. All you do it pipe data in STDIN:
|
||||||
|
|
||||||
`cat file | haste`
|
`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
|
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
|
## Making uploading file contents easier
|
||||||
|
|
||||||
If you supply a valid file path as argument #1 to the client, it will be uploaded:
|
If you supply a valid file path as argument #1 to the client, it will be uploaded:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
# equivelant
|
# equivalent
|
||||||
cat file | haste
|
cat file | haste
|
||||||
haste file
|
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
|
## 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:
|
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:
|
You can also use `Haste` as a library to upload hastes:
|
||||||
|
|
||||||
``` ruby
|
``` ruby
|
||||||
|
require 'haste'
|
||||||
uploader = Haste::Uploader.new
|
uploader = Haste::Uploader.new
|
||||||
uploader.upload_raw 'this is my data' # key
|
uploader.upload_raw 'this is my data' # key
|
||||||
|
uploader.upload_path '/tmp/whaaaa' # key
|
||||||
```
|
```
|
||||||
|
|
||||||
## Windows Support
|
## Windows Support
|
||||||
@@ -62,16 +67,16 @@ If you'd like an alternative on Windows that supports functionality similar to `
|
|||||||
|
|
||||||
## Lightweight Alternative
|
## 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
|
``` 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:
|
Usage:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
haste `cat index.html
|
cat file.txt | haste
|
||||||
```
|
```
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|||||||
8
Rakefile
8
Rakefile
@@ -1,6 +1,7 @@
|
|||||||
|
require 'rspec/core/rake_task'
|
||||||
require File.dirname(__FILE__) + '/lib/haste/version'
|
require File.dirname(__FILE__) + '/lib/haste/version'
|
||||||
|
|
||||||
task :build do
|
task :build => :test do
|
||||||
system "gem build haste.gemspec"
|
system "gem build haste.gemspec"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -11,3 +12,8 @@ task :release => :build do
|
|||||||
# push the gem
|
# push the gem
|
||||||
system "gem push haste-#{Haste::VERSION}.gem"
|
system "gem push haste-#{Haste::VERSION}.gem"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
RSpec::Core::RakeTask.new(:test) do |t|
|
||||||
|
t.pattern = 'spec/**/*_spec.rb'
|
||||||
|
fail_on_error = true # be explicit
|
||||||
|
end
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ spec = Gem::Specification.new do |s|
|
|||||||
s.author = 'John Crepezzi'
|
s.author = 'John Crepezzi'
|
||||||
s.add_development_dependency('rspec')
|
s.add_development_dependency('rspec')
|
||||||
s.add_dependency('json')
|
s.add_dependency('json')
|
||||||
s.add_dependency('rest-client')
|
s.add_dependency('faraday')
|
||||||
s.description = 'CLI Haste Client'
|
s.description = 'CLI Haste Client'
|
||||||
s.email = 'john.crepezzi@gmail.com'
|
s.email = 'john.crepezzi@gmail.com'
|
||||||
s.executables = 'haste'
|
s.executables = 'haste'
|
||||||
|
|||||||
@@ -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/uploader'
|
||||||
require File.dirname(__FILE__) + '/haste/exception'
|
require File.dirname(__FILE__) + '/haste/exception'
|
||||||
require File.dirname(__FILE__) + '/haste/cli'
|
require File.dirname(__FILE__) + '/haste/cli'
|
||||||
|
|||||||
@@ -10,13 +10,18 @@ module Haste
|
|||||||
# And then handle the basic usage
|
# And then handle the basic usage
|
||||||
def start
|
def start
|
||||||
# Take data in
|
# Take data in
|
||||||
key = if STDIN.tty?
|
if STDIN.tty?
|
||||||
@uploader.upload_path ARGV.first
|
key = @uploader.upload_path ARGV.first
|
||||||
else
|
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
|
end
|
||||||
# And write data out
|
# And write data out
|
||||||
url = "#{@uploader.server_url}/#{key}"
|
|
||||||
if STDOUT.tty?
|
if STDOUT.tty?
|
||||||
STDOUT.puts url
|
STDOUT.puts url
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
require 'json'
|
||||||
|
require 'faraday'
|
||||||
|
|
||||||
module Haste
|
module Haste
|
||||||
|
|
||||||
DEFAULT_URL = 'http://hastebin.com'
|
DEFAULT_URL = 'http://hastebin.com'
|
||||||
@@ -22,19 +25,31 @@ module Haste
|
|||||||
# Take in data and return a key
|
# Take in data and return a key
|
||||||
def upload_raw(data)
|
def upload_raw(data)
|
||||||
data.rstrip!
|
data.rstrip!
|
||||||
raw_data = RestClient.post "#{self.server_url}/documents", data
|
response = do_post data
|
||||||
data = JSON.parse(raw_data)
|
if response.status == 200
|
||||||
|
data = JSON.parse(response.body)
|
||||||
data['key']
|
data['key']
|
||||||
|
else
|
||||||
|
fail_with "failure uploading: #{response.body}"
|
||||||
|
end
|
||||||
rescue JSON::ParserError => e
|
rescue JSON::ParserError => e
|
||||||
fail_with "failure parsing response: #{e.message}"
|
fail_with "failure parsing response: #{e.message}"
|
||||||
rescue RestClient::Exception => e
|
|
||||||
fail_with "failure uploading: #{e.message}"
|
|
||||||
rescue Errno::ECONNREFUSED => e
|
rescue Errno::ECONNREFUSED => e
|
||||||
fail_with "failure connecting: #{e.message}"
|
fail_with "failure connecting: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
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)
|
def fail_with(msg)
|
||||||
raise Exception.new(msg)
|
raise Exception.new(msg)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Haste
|
module Haste
|
||||||
|
|
||||||
VERSION = '0.1.7'
|
VERSION = '0.2.1'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ require 'spec_helper'
|
|||||||
|
|
||||||
describe Haste::Uploader do
|
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
|
describe :upload_raw do
|
||||||
|
|
||||||
let(:data) { 'hello world' }
|
let(:data) { 'hello world' }
|
||||||
let(:url) { "#{uploader.server_url}/documents" }
|
|
||||||
let(:base) { nil }
|
let(:base) { nil }
|
||||||
let(:error_message) do
|
let(:error_message) do
|
||||||
begin
|
begin
|
||||||
@@ -23,7 +22,8 @@ describe Haste::Uploader do
|
|||||||
let(:json) { '{"key":"hello"}' }
|
let(:json) { '{"key":"hello"}' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
RestClient.should_receive(:post).with(url, data).and_return(json)
|
ostruct = OpenStruct.new(:status => 200, :body => json)
|
||||||
|
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should get the key' do
|
it 'should get the key' do
|
||||||
@@ -38,7 +38,8 @@ describe Haste::Uploader do
|
|||||||
let(:json) { '{that:not_even_json}' }
|
let(:json) { '{that:not_even_json}' }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
RestClient.should_receive(:post).with(url, data).and_return(json)
|
ostruct = OpenStruct.new(:status => 200, :body => json)
|
||||||
|
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should get an error' do
|
it 'should get an error' do
|
||||||
@@ -50,12 +51,12 @@ describe Haste::Uploader do
|
|||||||
context 'with a 404 response' do
|
context 'with a 404 response' do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
error = RestClient::ResourceNotFound.new
|
ostruct = OpenStruct.new(:status => 404, :body => 'ohno')
|
||||||
RestClient.should_receive(:post).with(url, data).and_raise(error)
|
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should get an error' do
|
it 'should get an error' do
|
||||||
error_message.should == 'failure uploading: Resource Not Found'
|
error_message.should == 'failure uploading: ohno'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -64,7 +65,7 @@ describe Haste::Uploader do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
error = Errno::ECONNREFUSED
|
error = Errno::ECONNREFUSED
|
||||||
RestClient.should_receive(:post).with(url, data).and_raise(error)
|
uploader.send(:connection).should_receive(:post).with('/documents', data).and_raise(error)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should get the key' do
|
it 'should get the key' do
|
||||||
@@ -111,7 +112,7 @@ describe Haste::Uploader do
|
|||||||
|
|
||||||
let(:data) { 'hello world' }
|
let(:data) { 'hello world' }
|
||||||
let(:path) { '/tmp/real' }
|
let(:path) { '/tmp/real' }
|
||||||
before { File.write(path, data) }
|
before { File.open(path, 'w') { |f| f.write(data) } }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
uploader.should_receive(:upload_raw).with(data) # check
|
uploader.should_receive(:upload_raw).with(data) # check
|
||||||
|
|||||||
Reference in New Issue
Block a user