pastebin 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ # Command line interface to http://pastebin.ca
2
+ # Copyright (C) 2009 dougsko
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = pastebin
2
+
3
+ pastebin is a CLI to http://pastebin.ca
4
+ Usage: pastebin [options]
5
+ Examples: pastebin -f foo.rb -t ruby -e '1 d'
6
+ cat foo.pl | pastebin -f - -t perl
7
+
8
+ Options:
9
+ -f, --file <file> Use a file for input, use "-" for STDIN
10
+ -n, --name <name> Assign a name/title to your paste
11
+ -d, --desc <description> Give your paste a description
12
+ -c, --config <file> Specify a config file. Default is ~/.paster.yaml
13
+ -r, --raw <link> Return raw text from a paste link
14
+ -t, --tags <tags> Tags for your paste
15
+ -e, --expire <time> These can be abbriviated, as long as they are unambigous. Defaults to '1 month'
16
+ never, 5 minutes, 10 minutes, 15 minutes, 30 minutes, 45 minutes, 1 hour, 2 hours, 4 hours, 8 hours, 12 hours, 1 day, 2 days, 3 days, 1 week, 2 weeks, 3 weeks, 1 month, 2 months, 3 months, 4 months, 5 months, 6 months, 1 year
17
+ -l, --language <syntax> Syntax types can be abbriviated, as long as they are unambigous. Defaults to 'raw'
18
+ action, ada, apache configuration, assembly (nasm), asterisk configuration, bash, c, c#, c++, css, delphi, html 4.0 strict, java, lisp, lua, microprocessor asm, mirc , objective c, pascal, perl, php, pl/i, python, raw, ruby, scheme, sql statement, visual basic, visual basic .net, xml document
19
+ -h, --help Show this message
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2009 dougsko. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "pastebin"
8
+ gem.summary = %Q{Command line interface to http://pastebin.ca}
9
+ gem.email = "dougtko@gmail.com"
10
+ gem.homepage = "http://github.com/dougsko/pastebin"
11
+ gem.authors = ["dougsko"]
12
+ gem.description = 'Command line interface to http://pastebin.ca'
13
+ gem.add_dependency 'httpclient'
14
+ gem.require_paths = ['/bin', '/lib']
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ spec.spec_opts = ['--color']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ spec.spec_opts = ['--color']
34
+ end
35
+
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ require 'darkfish-rdoc'
41
+ Rake::RDocTask.new do |rdoc|
42
+ if File.exist?('VERSION.yml')
43
+ config = YAML.load(File.read('VERSION.yml'))
44
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
45
+ else
46
+ version = ""
47
+ end
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "pastebin #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ rdoc.options += [
54
+ '-N',
55
+ '-f', 'darkfish',
56
+ ]
57
+ end
58
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
data/bin/pastebin ADDED
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # pastebin is a command line interface to pastebin.ca
4
+ # It can read from a file or from STDIN
5
+ #
6
+ # Copyright (C) 2007 Doug Prostko
7
+ #
8
+ # Requires the httpclient
9
+
10
+ require 'rubygems'
11
+ require 'optparse'
12
+ require 'pastebin'
13
+
14
+ # set up all the options stuff
15
+ options = {"type" => "1"}
16
+ opts = OptionParser.new do |opts|
17
+ opts.banner = "pastebin is a CLI to http://pastebin.ca
18
+ Usage: pastebin [options]
19
+ Examples: pastebin -f foo.rb -t ruby -e '1 d'
20
+ cat foo.pl | pastebin -f - -t perl"
21
+
22
+ opts.separator ""
23
+ opts.separator "Options:"
24
+
25
+ opts.on("-f <file>", "--file <file>", String,
26
+ "Use a file for input, use \"-\" for STDIN") do |f|
27
+ options["content"] = f
28
+ end
29
+
30
+ opts.on("-n", "--name <name>", String,
31
+ "Assign a name/title to your paste") do |n|
32
+ options["name"] = n
33
+ end
34
+
35
+ opts.on("-d", "--desc <description>", Array,
36
+ "Give your paste a description") do |d|
37
+ options["description"] = d
38
+ end
39
+
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|
50
+ options["tags"] = t
51
+ end
52
+
53
+ expire_array = [ "never",
54
+ "5 minutes",
55
+ "10 minutes",
56
+ "15 minutes",
57
+ "30 minutes",
58
+ "45 minutes",
59
+ "1 hour",
60
+ "2 hours",
61
+ "4 hours",
62
+ "8 hours",
63
+ "12 hours",
64
+ "1 day",
65
+ "2 days",
66
+ "3 days",
67
+ "1 week",
68
+ "2 weeks",
69
+ "3 weeks",
70
+ "1 month",
71
+ "2 months",
72
+ "3 months",
73
+ "4 months",
74
+ "5 months",
75
+ "6 months",
76
+ "1 year"
77
+ ]
78
+ expire_list = expire_array.join(", ")
79
+ opts.on("-e", "--expire <time>", expire_array, "These can be abbriviated, as long as they are unambigous. Defaults to '1 month'", "#{expire_list}" ) do |e|
80
+ options["expiry"] = e
81
+ end
82
+
83
+ syntax_hash = { "action" => "18",
84
+ "ada" => "19",
85
+ "apache configuration" => "20",
86
+ "assembly (nasm)" => "21",
87
+ "asterisk configuration" => "2",
88
+ "bash" => "23",
89
+ "c" => "3",
90
+ "c#" => "9",
91
+ "c++" => "4",
92
+ "css" => "24",
93
+ "delphi" => "25",
94
+ "html 4.0 strict" => "26",
95
+ "java" => "7",
96
+ "java" => "27",
97
+ "lisp" => "28",
98
+ "lua" => "29",
99
+ "microprocessor asm" => "30",
100
+ "objective c" => "31",
101
+ "php" => "5", "pl/i" => "14",
102
+ "pascal" => "12",
103
+ "perl" => "6",
104
+ "python" => "11",
105
+ "raw" => "1",
106
+ "ruby" => "10",
107
+ "sql statement" => "16",
108
+ "scheme" => "17",
109
+ "visual basic .net" => "32",
110
+ "visual basic" => "8",
111
+ "xml document" => "15",
112
+ "mirc " => "13"
113
+ }
114
+ code_list = syntax_hash.keys.sort.join(", ")
115
+ opts.on("-l", "--language <syntax>", syntax_hash, "Syntax types can be abbriviated, as long as they are unambigous. Defaults to 'raw'", " #{code_list}") do |encoding|
116
+ options["type"] = encoding
117
+ end
118
+
119
+ opts.on_tail("-h", "--help", "Show this message") do
120
+ puts opts
121
+ exit
122
+ end
123
+ end
124
+
125
+ # parse options
126
+ opts.parse(ARGV)
127
+
128
+ pbin = Pastebin.new(options)
129
+ if options["raw"]
130
+ puts pbin.get_raw(options["raw"])
131
+ else
132
+ puts pbin.paste
133
+ end
134
+
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 ADDED
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{pastebin}
8
+ s.version = "0.1.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["dougsko"]
12
+ s.date = %q{2009-09-11}
13
+ s.default_executable = %q{pastebin}
14
+ s.description = %q{Command line interface to http://pastebin.ca}
15
+ s.email = %q{dougtko@gmail.com}
16
+ s.executables = ["pastebin"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/pastebin",
29
+ "lib/pastebin.rb",
30
+ "pastebin.gemspec",
31
+ "spec/pastebin_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/dougsko/pastebin}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["/bin", "/lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Command line interface to http://pastebin.ca}
39
+ s.test_files = [
40
+ "spec/pastebin_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<httpclient>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<httpclient>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<httpclient>, [">= 0"])
55
+ end
56
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Pastebin" do
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/)
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'pastebin'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pastebin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - dougsko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-11 00:00:00 -04:00
13
+ default_executable: pastebin
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httpclient
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Command line interface to http://pastebin.ca
26
+ email: dougtko@gmail.com
27
+ executables:
28
+ - pastebin
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - bin/pastebin
42
+ - lib/pastebin.rb
43
+ - pastebin.gemspec
44
+ - spec/pastebin_spec.rb
45
+ - spec/spec_helper.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/dougsko/pastebin
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - /bin
55
+ - /lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Command line interface to http://pastebin.ca
75
+ test_files:
76
+ - spec/pastebin_spec.rb
77
+ - spec/spec_helper.rb