pastie-api 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pastie +34 -14
- data/lib/pastie-api/history.rb +51 -0
- data/lib/pastie-api/pastie.rb +1 -1
- metadata +6 -5
data/bin/pastie
CHANGED
@@ -3,24 +3,44 @@
|
|
3
3
|
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
4
|
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
5
|
|
6
|
+
require 'optparse'
|
6
7
|
require 'pastie-api'
|
7
8
|
require 'pastie-api/console'
|
9
|
+
require 'pastie-api/history'
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
history = Pastie::History.new
|
12
|
+
options = {:private => true}
|
13
|
+
|
14
|
+
optparse = OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: pastie [options] file1 file2 ... fileN"
|
16
|
+
opts.on('-i', '--info', 'Display this information.') { puts opts ; exit }
|
17
|
+
opts.on('-p', '--public', 'Paste files as public.') { options[:private] = false }
|
18
|
+
opts.on('-h', '--history', 'Show pastes history.') { history.print ; exit }
|
19
|
+
opts.on('-c', '--clear', 'Clear your pastes history.') { history.flush ; history.save ; exit }
|
20
|
+
end
|
21
|
+
|
22
|
+
begin
|
23
|
+
optparse.parse!
|
24
|
+
unless ARGV.empty?
|
25
|
+
ARGV.each do |f|
|
26
|
+
path = File.expand_path(f)
|
27
|
+
if File.exists?(path)
|
28
|
+
p = Pastie.create(File.read(path), options[:private])
|
29
|
+
unless p.nil?
|
30
|
+
history.add(p.link)
|
31
|
+
puts p.link.green
|
32
|
+
else
|
33
|
+
puts "Error: Cant create paste at this moment.".red
|
34
|
+
end
|
35
|
+
history.save
|
16
36
|
else
|
17
|
-
puts "Error:
|
37
|
+
puts "Error: \"#{path}\" does not exist!".red
|
18
38
|
end
|
19
|
-
else
|
20
|
-
puts "Error: \"#{path}\" does not exist!".red
|
21
39
|
end
|
40
|
+
else
|
41
|
+
puts optparse
|
22
42
|
end
|
23
|
-
|
24
|
-
puts
|
25
|
-
|
26
|
-
|
43
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
44
|
+
puts optparse
|
45
|
+
exit
|
46
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Pastie
|
2
|
+
class History
|
3
|
+
attr_reader :path
|
4
|
+
attr_accessor :links
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@path = "#{RUBY_PLATFORM =~ /mswin32|mingw32/ ? ENV['USERPROFILE'] : ENV['HOME']}/.pastie"
|
8
|
+
@links = []
|
9
|
+
self.load
|
10
|
+
end
|
11
|
+
|
12
|
+
# Load history
|
13
|
+
def load
|
14
|
+
if File.exists?(@path) && File.readable?(@path)
|
15
|
+
File.open(@path).readlines("\r\n").each do |l|
|
16
|
+
@links << l.strip
|
17
|
+
end
|
18
|
+
else
|
19
|
+
if File.writable?(File.dirname(@path))
|
20
|
+
File.open(@path, 'w').close
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Add new paste to the history
|
26
|
+
def add(url)
|
27
|
+
@links << url
|
28
|
+
end
|
29
|
+
|
30
|
+
# Flush history
|
31
|
+
def flush
|
32
|
+
@links = []
|
33
|
+
end
|
34
|
+
|
35
|
+
# Save history
|
36
|
+
def save
|
37
|
+
File.open(@path, 'w') { |f| f.write(@links.join("\r\n")) }
|
38
|
+
end
|
39
|
+
|
40
|
+
# Print all existing pastes
|
41
|
+
def print
|
42
|
+
puts "====== Pastes History ======".green
|
43
|
+
unless @links.empty?
|
44
|
+
@links.each_with_index { |l, i| puts "#{i+1}. #{l}" }
|
45
|
+
else
|
46
|
+
puts "your history is empty..."
|
47
|
+
end
|
48
|
+
puts "============================".green
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/pastie-api/pastie.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pastie-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dan Sosedoff
|
@@ -19,7 +19,7 @@ date: 2010-10-17 00:00:00 -05:00
|
|
19
19
|
default_executable: pastie
|
20
20
|
dependencies: []
|
21
21
|
|
22
|
-
description:
|
22
|
+
description: Simple API and shell access to Pastie.org
|
23
23
|
email: dan.sosedoff@gmail.com
|
24
24
|
executables:
|
25
25
|
- pastie
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/pastie-api/request.rb
|
35
35
|
- lib/pastie-api/paste.rb
|
36
36
|
- lib/pastie-api/console.rb
|
37
|
+
- lib/pastie-api/history.rb
|
37
38
|
has_rdoc: true
|
38
39
|
homepage: http://github.com/sosedoff/pastie
|
39
40
|
licenses: []
|
@@ -67,6 +68,6 @@ rubyforge_project:
|
|
67
68
|
rubygems_version: 1.3.7
|
68
69
|
signing_key:
|
69
70
|
specification_version: 3
|
70
|
-
summary: Pastie.org
|
71
|
+
summary: Simple Pastie.org API
|
71
72
|
test_files: []
|
72
73
|
|