mirror of
https://github.com/seejohnrun/haste-client.git
synced 2025-12-16 16:51:29 +00:00
Compare commits
16 Commits
v0.2.1
...
update-lig
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a4953dc93 | ||
|
|
32c4523e1c | ||
|
|
c307e8c904 | ||
|
|
1037d899b9 | ||
|
|
b5aa8fbacc | ||
|
|
1f3318adeb | ||
|
|
4c0e5f311d | ||
|
|
dab2d08f42 | ||
|
|
dfb69c5e0d | ||
|
|
f79b70da61 | ||
|
|
898884f07c | ||
|
|
3ba2c53587 | ||
|
|
0ea5e5c61c | ||
|
|
94b2a4fbec | ||
|
|
3a1d4045b3 | ||
|
|
82ae343455 |
@@ -4,6 +4,6 @@ branches:
|
|||||||
- master
|
- master
|
||||||
rvm:
|
rvm:
|
||||||
- 1.8.7
|
- 1.8.7
|
||||||
- 1.9.2
|
|
||||||
- 1.9.3
|
- 1.9.3
|
||||||
- 2.0.0
|
- 2.0.0
|
||||||
|
- 2.4.0
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -10,7 +10,7 @@ And once the output makes it to the server, it will print the URL to STDOUT.
|
|||||||
|
|
||||||
This can be really really cool in combination with `pbcopy`, like:
|
This can be really really cool in combination with `pbcopy`, like:
|
||||||
|
|
||||||
* mac osx: `cat file | haste | pbcopy`
|
* mac osx: `cat file | haste | pbcopy`
|
||||||
* linux: `cat file | haste | xsel`
|
* linux: `cat file | haste | xsel`
|
||||||
|
|
||||||
after which the contents of `file` will be accessible at a URL which has been copied to your pasteboard.
|
after which the contents of `file` will be accessible at a URL which has been copied to your pasteboard.
|
||||||
@@ -42,10 +42,10 @@ 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 `https://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:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
alias work_haste="HASTE_SERVER=http://something.com haste"
|
alias work_haste="HASTE_SERVER=https://something.com haste"
|
||||||
```
|
```
|
||||||
|
|
||||||
After which you can use `work_haste` to send hastes to that server instead.
|
After which you can use `work_haste` to send hastes to that server instead.
|
||||||
@@ -70,7 +70,7 @@ If you'd like an alternative on Windows that supports functionality similar to `
|
|||||||
Han Boetes and @nickthename have 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() { a=$(cat); curl -X POST -s -d "$a" http://hastebin.com/documents | awk -F '"' '{print "http://hastebin.com/"$4}'; }
|
haste() { curl -X POST -s -d "$(cat $1)" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}'; }
|
||||||
```
|
```
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@@ -78,6 +78,14 @@ Usage:
|
|||||||
``` bash
|
``` bash
|
||||||
cat file.txt | haste
|
cat file.txt | haste
|
||||||
```
|
```
|
||||||
|
or:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
haste file.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
And a more expansive BASH option by @diethnis can be found at:
|
||||||
|
https://github.com/diethnis/standalones/blob/master/hastebin.sh
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
|
||||||
|
|||||||
9
Rakefile
9
Rakefile
@@ -1,7 +1,9 @@
|
|||||||
require 'rspec/core/rake_task'
|
require 'rspec/core/rake_task'
|
||||||
require File.dirname(__FILE__) + '/lib/haste/version'
|
require File.dirname(__FILE__) + '/lib/haste/version'
|
||||||
|
|
||||||
task :build => :test do
|
RSpec::Core::RakeTask.new(:spec)
|
||||||
|
|
||||||
|
task :build => :spec do
|
||||||
system "gem build haste.gemspec"
|
system "gem build haste.gemspec"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -12,8 +14,3 @@ 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
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require File.dirname(__FILE__) + '/lib/haste/version'
|
require File.dirname(__FILE__) + '/lib/haste/version'
|
||||||
|
|
||||||
spec = Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = 'haste'
|
s.name = 'haste'
|
||||||
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('faraday')
|
s.add_dependency('faraday', '~> 0.9')
|
||||||
s.description = 'CLI Haste Client'
|
s.description = 'CLI Haste Client'
|
||||||
|
s.license = 'MIT License'
|
||||||
|
s.homepage = 'https://github.com/seejohnrun/haste-client'
|
||||||
s.email = 'john.crepezzi@gmail.com'
|
s.email = 'john.crepezzi@gmail.com'
|
||||||
s.executables = 'haste'
|
s.executables = 'haste'
|
||||||
s.files = Dir['lib/**/*.rb', 'haste']
|
s.files = Dir['lib/**/*.rb', 'haste']
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
require 'json'
|
require 'json'
|
||||||
require 'faraday'
|
require 'faraday'
|
||||||
|
require 'uri'
|
||||||
|
|
||||||
module Haste
|
module Haste
|
||||||
|
|
||||||
DEFAULT_URL = 'http://hastebin.com'
|
DEFAULT_URL = 'https://hastebin.com'
|
||||||
|
|
||||||
class Uploader
|
class Uploader
|
||||||
|
|
||||||
@@ -40,8 +41,13 @@ module Haste
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def post_path
|
||||||
|
parsed_uri = URI.parse(server_url)
|
||||||
|
"#{parsed_uri.path}/documents"
|
||||||
|
end
|
||||||
|
|
||||||
def do_post(data)
|
def do_post(data)
|
||||||
connection.post('/documents', data)
|
connection.post(post_path, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def connection
|
def connection
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Haste
|
module Haste
|
||||||
|
|
||||||
VERSION = '0.2.1'
|
VERSION = '0.2.3'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ describe Haste::Uploader do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
ostruct = OpenStruct.new(:status => 200, :body => json)
|
ostruct = OpenStruct.new(:status => 200, :body => json)
|
||||||
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_return(ostruct)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should get the key' do
|
it 'should get the key' do
|
||||||
error_message.should be_nil # no error
|
expect(error_message).to be_nil # no error
|
||||||
@key.should == 'hello'
|
expect(@key).to eq('hello')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -39,11 +39,11 @@ describe Haste::Uploader do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
ostruct = OpenStruct.new(:status => 200, :body => json)
|
ostruct = OpenStruct.new(:status => 200, :body => json)
|
||||||
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
expect(uploader.send(:connection)).to 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 start_with 'failure parsing response: '
|
expect(error_message).to start_with('failure parsing response: ')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -52,11 +52,11 @@ describe Haste::Uploader do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
ostruct = OpenStruct.new(:status => 404, :body => 'ohno')
|
ostruct = OpenStruct.new(:status => 404, :body => 'ohno')
|
||||||
uploader.send(:connection).should_receive(:post).with('/documents', data).and_return(ostruct)
|
expect(uploader.send(:connection)).to 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: ohno'
|
expect(error_message).to eq('failure uploading: ohno')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -65,11 +65,11 @@ describe Haste::Uploader do
|
|||||||
|
|
||||||
before do
|
before do
|
||||||
error = Errno::ECONNREFUSED
|
error = Errno::ECONNREFUSED
|
||||||
uploader.send(:connection).should_receive(:post).with('/documents', data).and_raise(error)
|
expect(uploader.send(:connection)).to receive(:post).with('/documents', data).and_raise(error)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should get the key' do
|
it 'should get the key' do
|
||||||
error_message.should == 'failure connecting: Connection refused'
|
expect(error_message).to eq('failure connecting: Connection refused')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -93,7 +93,7 @@ describe Haste::Uploader do
|
|||||||
let(:path) { nil }
|
let(:path) { nil }
|
||||||
|
|
||||||
it 'should have an error' do
|
it 'should have an error' do
|
||||||
error_message.should == 'No input file given'
|
expect(error_message).to eq('No input file given')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -103,7 +103,7 @@ describe Haste::Uploader do
|
|||||||
let(:path) { '/tmp/why-do-you-have-a-file-called-john' }
|
let(:path) { '/tmp/why-do-you-have-a-file-called-john' }
|
||||||
|
|
||||||
it 'should have an error' do
|
it 'should have an error' do
|
||||||
error_message.should == "#{path}: No such path"
|
expect(error_message).to eq("#{path}: No such path")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -115,11 +115,47 @@ describe Haste::Uploader do
|
|||||||
before { File.open(path, 'w') { |f| f.write(data) } }
|
before { File.open(path, 'w') { |f| f.write(data) } }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
uploader.should_receive(:upload_raw).with(data) # check
|
expect(uploader).to receive(:upload_raw).with(data) # check
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not receive an error' do
|
it 'should not receive an error' do
|
||||||
error_message.should be_nil
|
expect(error_message).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe :post_path do
|
||||||
|
|
||||||
|
let(:post_path) { uploader.send(:post_path) }
|
||||||
|
|
||||||
|
context "when the server URL doesn't have a path" do
|
||||||
|
|
||||||
|
let(:base) { 'http://example.com/' }
|
||||||
|
|
||||||
|
it 'should return /documents' do
|
||||||
|
expect(post_path).to eq('/documents')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the server URL has a path" do
|
||||||
|
|
||||||
|
let(:base) { 'http://example.com/friend' }
|
||||||
|
|
||||||
|
it 'should return /documents' do
|
||||||
|
expect(post_path).to eq('/friend/documents')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when the server URL has a path that ends with slash" do
|
||||||
|
|
||||||
|
let(:base) { 'http://example.com/friend/' }
|
||||||
|
|
||||||
|
it 'should return /documents appended to the path without a duplicate slash' do
|
||||||
|
expect(post_path).to eq('/friend/documents')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -135,7 +171,7 @@ describe Haste::Uploader do
|
|||||||
let(:base) { nil }
|
let(:base) { nil }
|
||||||
|
|
||||||
it 'should use the default url' do
|
it 'should use the default url' do
|
||||||
server_url.should == Haste::DEFAULT_URL
|
expect(server_url).to eq(Haste::DEFAULT_URL)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -148,11 +184,11 @@ describe Haste::Uploader do
|
|||||||
let(:base) { @string }
|
let(:base) { @string }
|
||||||
|
|
||||||
it 'should remove the slash' do
|
it 'should remove the slash' do
|
||||||
server_url.should == @string.chop
|
expect(server_url).to eq(@string.chop)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not modify the original' do
|
it 'should not modify the original' do
|
||||||
@string.should == 'hello/'
|
expect(@string).to eq('hello/')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -162,7 +198,7 @@ describe Haste::Uploader do
|
|||||||
let(:base) { 'hello' }
|
let(:base) { 'hello' }
|
||||||
|
|
||||||
it 'should not chop the url' do
|
it 'should not chop the url' do
|
||||||
server_url.should == base
|
expect(server_url).to eq(base)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
|
require 'ostruct'
|
||||||
|
|
||||||
require File.dirname(__FILE__) + '/../lib/haste'
|
require File.dirname(__FILE__) + '/../lib/haste'
|
||||||
|
|||||||
Reference in New Issue
Block a user