dougsko-pastebin 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +7 -0
- data/VERSION +1 -1
- data/bin/pastebin +15 -40
- data/lib/pastebin.rb +88 -0
- data/pastebin.gemspec +7 -3
- data/spec/pastebin_spec.rb +19 -2
- metadata +3 -2
data/Rakefile
CHANGED
@@ -23,18 +23,21 @@ require 'spec/rake/spectask'
|
|
23
23
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
24
|
spec.libs << 'lib' << 'spec'
|
25
25
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
spec.spec_opts = ['--color']
|
26
27
|
end
|
27
28
|
|
28
29
|
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
30
|
spec.libs << 'lib' << 'spec'
|
30
31
|
spec.pattern = 'spec/**/*_spec.rb'
|
31
32
|
spec.rcov = true
|
33
|
+
spec.spec_opts = ['--color']
|
32
34
|
end
|
33
35
|
|
34
36
|
|
35
37
|
task :default => :spec
|
36
38
|
|
37
39
|
require 'rake/rdoctask'
|
40
|
+
require 'darkfish-rdoc'
|
38
41
|
Rake::RDocTask.new do |rdoc|
|
39
42
|
if File.exist?('VERSION.yml')
|
40
43
|
config = YAML.load(File.read('VERSION.yml'))
|
@@ -47,5 +50,9 @@ Rake::RDocTask.new do |rdoc|
|
|
47
50
|
rdoc.title = "pastebin #{version}"
|
48
51
|
rdoc.rdoc_files.include('README*')
|
49
52
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
rdoc.options += [
|
54
|
+
'-N',
|
55
|
+
'-f', 'darkfish',
|
56
|
+
]
|
50
57
|
end
|
51
58
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/bin/pastebin
CHANGED
@@ -8,11 +8,8 @@
|
|
8
8
|
# Requires the httpclient
|
9
9
|
|
10
10
|
require 'rubygems'
|
11
|
-
require 'yaml'
|
12
11
|
require 'optparse'
|
13
|
-
require '
|
14
|
-
|
15
|
-
CONFIG="#{ENV['HOME']}/.paster.yaml"
|
12
|
+
require 'pastebin'
|
16
13
|
|
17
14
|
# set up all the options stuff
|
18
15
|
options = {"type" => "1"}
|
@@ -40,7 +37,16 @@ opts = OptionParser.new do |opts|
|
|
40
37
|
options["description"] = d
|
41
38
|
end
|
42
39
|
|
43
|
-
opts.on("-
|
40
|
+
opts.on("-c", "--config <file>", String,
|
41
|
+
"Specify a config file. Default is ~/.paster.yaml") do |c|
|
42
|
+
options["config"] = c
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("-r", "--raw <link>", String, "Return raw text from a paste link") do |r|
|
46
|
+
options["raw"] = r
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on("-t", "--tags <tags>", String, "Tags for your paste") do |t|
|
44
50
|
options["tags"] = t
|
45
51
|
end
|
46
52
|
|
@@ -119,41 +125,10 @@ end
|
|
119
125
|
# parse options
|
120
126
|
opts.parse(ARGV)
|
121
127
|
|
122
|
-
|
123
|
-
if
|
124
|
-
|
128
|
+
pbin = Pastebin.new(options)
|
129
|
+
if options["raw"]
|
130
|
+
puts pbin.get_raw(options["raw"])
|
125
131
|
else
|
126
|
-
|
127
|
-
puts "Please enter your API key. You'll only have to do this once."
|
128
|
-
print "You can get a key here: http://pastebin.ca/apikey.php \n "
|
129
|
-
config['key'] = gets.chomp
|
130
|
-
options["api"] = config['key']
|
131
|
-
open(CONFIG, 'w'){ |f| YAML.dump(config, f) }
|
132
|
-
puts "Thank you. Please run the script again. Run #{$0} --help to see all the options."
|
133
|
-
exit
|
132
|
+
puts pbin.paste
|
134
133
|
end
|
135
134
|
|
136
|
-
# content
|
137
|
-
if options.has_key?("content")
|
138
|
-
if options["content"] == "-"
|
139
|
-
options["content"] = $stdin.read
|
140
|
-
else
|
141
|
-
File.open(options["content"]) do |file|
|
142
|
-
options["content"] = file.read
|
143
|
-
end
|
144
|
-
end
|
145
|
-
else
|
146
|
-
puts opts
|
147
|
-
end
|
148
|
-
|
149
|
-
clnt = HTTPClient.new("http://pastebin.ca/quiet-paste.php")
|
150
|
-
clnt.post("http://pastebin.ca/quiet-paste.php", options).content[/(\w+):([\w\s]+)/]
|
151
|
-
success_fail = $1
|
152
|
-
code_reason = $2
|
153
|
-
if success_fail == "SUCCESS"
|
154
|
-
puts "http://pastebin.ca/" + code_reason
|
155
|
-
elsif success_fail == "FAIL"
|
156
|
-
puts "#{$0} Error: #{$2}"
|
157
|
-
else
|
158
|
-
puts "#{$0} Error: Unknown Error"
|
159
|
-
end
|
data/lib/pastebin.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Class to work with http://pastebin.ca
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'yaml'
|
8
|
+
require 'hpricot'
|
9
|
+
require 'httpclient'
|
10
|
+
|
11
|
+
class Pastebin
|
12
|
+
# This method takes a hash containing the variables in the POST
|
13
|
+
# request and an optional config file. Only either "content" or
|
14
|
+
# "raw" is required.
|
15
|
+
# pbin = Pastbin.new({ "content" => "file_path",
|
16
|
+
# "name" => "",
|
17
|
+
# "decription" => "",
|
18
|
+
# "tags" => "",
|
19
|
+
# "exipry" => "",
|
20
|
+
# "type" => "",
|
21
|
+
# "config" => "config file",
|
22
|
+
# "raw" => "pastebin link",
|
23
|
+
# })
|
24
|
+
#
|
25
|
+
def initialize(options)
|
26
|
+
@options = options
|
27
|
+
#@options.delete("raw")
|
28
|
+
if @options.has_key?("config")
|
29
|
+
@config = options["config"]
|
30
|
+
@options.delete("config")
|
31
|
+
else
|
32
|
+
@config = "#{ENV['HOME']}/.paster.yaml"
|
33
|
+
end
|
34
|
+
@options["type"] = "1"
|
35
|
+
if File.exists? @config
|
36
|
+
config = YAML.load(File.open(@config))
|
37
|
+
else
|
38
|
+
config = {}
|
39
|
+
puts "Please enter your API key. You'll only have to do this once."
|
40
|
+
print "You can get a key here: http://pastebin.ca/apikey.php \n "
|
41
|
+
config['key'] = gets.chomp
|
42
|
+
@options["api"] = config['key']
|
43
|
+
open(@config, 'w'){ |f| YAML.dump(config, f) }
|
44
|
+
puts "Thank you. Please run the script again. Run #{$0} --help to see all the options."
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# This POSTs the paste and returns the link
|
50
|
+
#
|
51
|
+
# pbin.paste #=> "http://pastebin.ca/xxxxxxx"
|
52
|
+
#
|
53
|
+
def paste
|
54
|
+
if @options.has_key?("content")
|
55
|
+
if @options["content"] == "-"
|
56
|
+
@options["content"] = $stdin.read
|
57
|
+
else
|
58
|
+
File.open(@options["content"]) do |file|
|
59
|
+
@options["content"] = file.read
|
60
|
+
end
|
61
|
+
end
|
62
|
+
else
|
63
|
+
puts "You must specify a file or '-' for STDIN"
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
clnt = HTTPClient.new
|
67
|
+
clnt.post("http://pastebin.ca/quiet-paste.php", @options).content[/(\w+):([\w\s]+)/]
|
68
|
+
success_fail = $1
|
69
|
+
code_reason = $2
|
70
|
+
if success_fail == "SUCCESS"
|
71
|
+
"http://pastebin.ca/" + code_reason
|
72
|
+
elsif success_fail == "FAIL"
|
73
|
+
"#{$0} Error: #{$2}"
|
74
|
+
else
|
75
|
+
"#{$0} Error: Unknown Error"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# This method takes a link from a previous paste and returns the raw
|
80
|
+
# text.
|
81
|
+
#
|
82
|
+
# pbin.get_raw("http://pastebin.ca/xxxxxxx") #=> "some text"
|
83
|
+
#
|
84
|
+
def get_raw(link)
|
85
|
+
clnt = HTTPClient.new(:agent_name => 'ruby httpclient')
|
86
|
+
clnt.get_content("http://pastebin.ca/raw/#{link[/\d+/]}")
|
87
|
+
end
|
88
|
+
end
|
data/pastebin.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{pastebin}
|
5
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["dougsko"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-09-11}
|
10
13
|
s.default_executable = %q{pastebin}
|
11
14
|
s.description = %q{Command line interface to http://pastebin.ca}
|
12
15
|
s.email = %q{dougtko@gmail.com}
|
@@ -23,6 +26,7 @@ Gem::Specification.new do |s|
|
|
23
26
|
"Rakefile",
|
24
27
|
"VERSION",
|
25
28
|
"bin/pastebin",
|
29
|
+
"lib/pastebin.rb",
|
26
30
|
"pastebin.gemspec",
|
27
31
|
"spec/pastebin_spec.rb",
|
28
32
|
"spec/spec_helper.rb"
|
@@ -30,7 +34,7 @@ Gem::Specification.new do |s|
|
|
30
34
|
s.homepage = %q{http://github.com/dougsko/pastebin}
|
31
35
|
s.rdoc_options = ["--charset=UTF-8"]
|
32
36
|
s.require_paths = ["/bin"]
|
33
|
-
s.rubygems_version = %q{1.3.
|
37
|
+
s.rubygems_version = %q{1.3.5}
|
34
38
|
s.summary = %q{Command line interface to http://pastebin.ca}
|
35
39
|
s.test_files = [
|
36
40
|
"spec/pastebin_spec.rb",
|
data/spec/pastebin_spec.rb
CHANGED
@@ -1,7 +1,24 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "Pastebin" do
|
4
|
-
|
5
|
-
|
4
|
+
before do
|
5
|
+
`echo "hello world" > /tmp/hw.txt`
|
6
|
+
options = {"content" => "/tmp/hw.txt", "expiry" => "5 minutes"}
|
7
|
+
@pbin = Pastebin.new(options)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "tests that @pbin is indeed a Pastebin object" do
|
11
|
+
@pbin.class.to_s.should == "Pastebin"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should paste some text and return a link" do
|
15
|
+
@paste = @pbin.paste
|
16
|
+
@paste.should match(/http:.*\/\d+/)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return raw text from a paste link" do
|
20
|
+
@paste = @pbin.paste
|
21
|
+
text = @pbin.get_raw(@paste)
|
22
|
+
text.should match(/hello world/)
|
6
23
|
end
|
7
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dougsko-pastebin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dougsko
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-11 00:00:00 -07:00
|
13
13
|
default_executable: pastebin
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
41
|
- bin/pastebin
|
42
|
+
- lib/pastebin.rb
|
42
43
|
- pastebin.gemspec
|
43
44
|
- spec/pastebin_spec.rb
|
44
45
|
- spec/spec_helper.rb
|