haste 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/haste +6 -0
- data/lib/haste/version.rb +5 -0
- data/lib/haste.rb +47 -0
- metadata +70 -0
data/bin/haste
ADDED
data/lib/haste.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Haste
|
6
|
+
|
7
|
+
DEFAULT_URL = 'http://hastebin.com'
|
8
|
+
|
9
|
+
class CLI
|
10
|
+
|
11
|
+
attr_reader :input
|
12
|
+
|
13
|
+
# Pull all of the data from STDIN
|
14
|
+
def initialize
|
15
|
+
@input = STDIN.readlines.join
|
16
|
+
@input.strip!
|
17
|
+
end
|
18
|
+
|
19
|
+
# Upload the and output the URL we get back
|
20
|
+
def start
|
21
|
+
uri = URI.parse server
|
22
|
+
http = Net::HTTP.new uri.host, uri.port
|
23
|
+
response = http.post '/documents', input
|
24
|
+
if response.is_a?(Net::HTTPOK)
|
25
|
+
data = JSON.parse(response.body)
|
26
|
+
STDOUT.puts "#{server}/#{data['key']}"
|
27
|
+
else
|
28
|
+
STDERR.puts "failure uploading: #{res.status}"
|
29
|
+
end
|
30
|
+
rescue RuntimeError, JSON::ParserError => e
|
31
|
+
STDERR.puts "failure uploading: #{response.code}"
|
32
|
+
rescue Errno::ECONNREFUSED => e
|
33
|
+
STDERR.puts "failure connecting: #{e.message}"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def server
|
39
|
+
return @server if @server
|
40
|
+
@server = ENV['HASTE_SERVER'] || Haste::DEFAULT_URL
|
41
|
+
@server.chop! if server.end_with?('/')
|
42
|
+
@server
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haste
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- John Crepezzi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70245634412680 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70245634412680
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
requirement: &70245634412000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70245634412000
|
36
|
+
description: CLI Haste Client
|
37
|
+
email: john.crepezzi@gmail.com
|
38
|
+
executables:
|
39
|
+
- haste
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- lib/haste/version.rb
|
44
|
+
- lib/haste.rb
|
45
|
+
- bin/haste
|
46
|
+
homepage:
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.10
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Haste Client
|
70
|
+
test_files: []
|