fossbin 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/fossbin +10 -0
- data/lib/haste/cli.rb +36 -0
- data/lib/haste/exception.rb +4 -0
- data/lib/haste/uploader.rb +59 -0
- data/lib/haste/version.rb +5 -0
- data/lib/haste.rb +6 -0
- data/spec/spec_helper.rb +2 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ea4cbf7724bd248c8dfda8bf7b8eb048d26b717
|
4
|
+
data.tar.gz: 7d5cba65c0379f8cc9a4b130459bdea2e6044a03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b2091e12742e2c4065b371ce826038d56cb08e8a199da2f3d03e7b774e029d902df18d6b6c87a92ce8afe9f8642dba48aeeee605c7bcd27b5fda9f82bf359d5
|
7
|
+
data.tar.gz: 4db7c0854bf27b618f78ce6632ab3d0a33abc487e80ca6afcb4199d0c4d24c4a1329a1f37343678fb35d9beb07afb33abfcab6af7ca24d989f77b423a4af668a
|
data/bin/fossbin
ADDED
data/lib/haste/cli.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Haste
|
2
|
+
|
3
|
+
class CLI
|
4
|
+
|
5
|
+
# Create a new uploader
|
6
|
+
def initialize
|
7
|
+
@uploader = Uploader.new ENV['HASTE_SERVER']
|
8
|
+
end
|
9
|
+
|
10
|
+
# And then handle the basic usage
|
11
|
+
def start
|
12
|
+
# Take data in
|
13
|
+
if STDIN.tty?
|
14
|
+
key = @uploader.upload_path ARGV.first
|
15
|
+
else
|
16
|
+
key = @uploader.upload_raw STDIN.readlines.join
|
17
|
+
end
|
18
|
+
# Put together a URL
|
19
|
+
if ARGV.include?('--raw')
|
20
|
+
url = "#{@uploader.server_url}/raw/#{key}"
|
21
|
+
else
|
22
|
+
url = "#{@uploader.server_url}/#{key}"
|
23
|
+
end
|
24
|
+
# And write data out
|
25
|
+
if STDOUT.tty?
|
26
|
+
STDOUT.puts url
|
27
|
+
else
|
28
|
+
STDOUT.print url
|
29
|
+
end
|
30
|
+
rescue Exception => e
|
31
|
+
abort e.message
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
module Haste
|
5
|
+
|
6
|
+
DEFAULT_URL = 'http://hastebin.com'
|
7
|
+
|
8
|
+
class Uploader
|
9
|
+
|
10
|
+
attr_reader :server_url
|
11
|
+
|
12
|
+
def initialize(server_url = nil)
|
13
|
+
@server_url = server_url || Haste::DEFAULT_URL
|
14
|
+
@server_url = @server_url.dup
|
15
|
+
@server_url = @server_url.chop if @server_url.end_with?('/')
|
16
|
+
end
|
17
|
+
|
18
|
+
# Take in a path and return a key
|
19
|
+
def upload_path(path)
|
20
|
+
fail_with 'No input file given' unless path
|
21
|
+
fail_with "#{path}: No such path" unless File.exists?(path)
|
22
|
+
upload_raw open(path).read
|
23
|
+
end
|
24
|
+
|
25
|
+
# Take in data and return a key
|
26
|
+
def upload_raw(data)
|
27
|
+
data.rstrip!
|
28
|
+
response = do_post data
|
29
|
+
if response.status == 200
|
30
|
+
data = JSON.parse(response.body)
|
31
|
+
data['key']
|
32
|
+
else
|
33
|
+
fail_with "failure uploading: #{response.body}"
|
34
|
+
end
|
35
|
+
rescue JSON::ParserError => e
|
36
|
+
fail_with "failure parsing response: #{e.message}"
|
37
|
+
rescue Errno::ECONNREFUSED => e
|
38
|
+
fail_with "failure connecting: #{e.message}"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def do_post(data)
|
44
|
+
connection.post('/documents', data)
|
45
|
+
end
|
46
|
+
|
47
|
+
def connection
|
48
|
+
@connection ||= Faraday.new(:url => server_url) do |c|
|
49
|
+
c.adapter Faraday.default_adapter
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def fail_with(msg)
|
54
|
+
raise Exception.new(msg)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/lib/haste.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fossbin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Crepezzi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: CLI fossbin Client
|
56
|
+
email: obetcc@gmail.com
|
57
|
+
executables:
|
58
|
+
- fossbin
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/haste.rb
|
63
|
+
- lib/haste/version.rb
|
64
|
+
- lib/haste/exception.rb
|
65
|
+
- lib/haste/cli.rb
|
66
|
+
- lib/haste/uploader.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- bin/fossbin
|
69
|
+
homepage:
|
70
|
+
licenses: []
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.0.13
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Haste Client
|
92
|
+
test_files:
|
93
|
+
- spec/spec_helper.rb
|