Class: PastrIt
- Inherits:
-
Object
- Object
- PastrIt
- Defined in:
- lib/pastr_it.rb
Constant Summary collapse
- VERSION =
'1.0.2'
- REALM =
'Pastr Registered User'
- PastrHome =
"http://pastr.it"
- PastrNew =
"%s/%s" % [PastrHome, :new]
- PastrEdit =
"%s/%s" % [PastrHome, :edit]
- PastrNote =
"%s/%s" % [PastrHome, :annotate]
Instance Attribute Summary collapse
-
#annotate_id ⇒ Object
Returns the value of attribute annotate_id.
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#language ⇒ Object
Returns the value of attribute language.
-
#network ⇒ Object
Returns the value of attribute network.
-
#no_body ⇒ Object
Returns the value of attribute no_body.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pastr_id ⇒ Object
Returns the value of attribute pastr_id.
-
#title ⇒ Object
Returns the value of attribute title.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #annotate_it ⇒ Object
- #edit_it ⇒ Object
-
#initialize(args = nil) ⇒ PastrIt
constructor
A new instance of PastrIt.
- #parse_args ⇒ Object
- #pastr_it ⇒ Object
Constructor Details
#initialize(args = nil) ⇒ PastrIt
Returns a new instance of PastrIt.
10 11 12 13 14 |
# File 'lib/pastr_it.rb', line 10 def initialize(args = nil) @network, @username = "Freenode", ENV["USER"] @args = args || ARGV parse_args end |
Instance Attribute Details
#annotate_id ⇒ Object
Returns the value of attribute annotate_id.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def annotate_id @annotate_id end |
#channel ⇒ Object
Returns the value of attribute channel.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def channel @channel end |
#filename ⇒ Object
Returns the value of attribute filename.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def filename @filename end |
#language ⇒ Object
Returns the value of attribute language.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def language @language end |
#network ⇒ Object
Returns the value of attribute network.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def network @network end |
#no_body ⇒ Object
Returns the value of attribute no_body.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def no_body @no_body end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def password @password end |
#pastr_id ⇒ Object
Returns the value of attribute pastr_id.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def pastr_id @pastr_id end |
#title ⇒ Object
Returns the value of attribute title.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def title @title end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/pastr_it.rb', line 9 def username @username end |
Class Method Details
Instance Method Details
#annotate_it ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/pastr_it.rb', line 78 def annotate_it aid = "annotation_#{@annotate_id}" form = {"#{aid}[paste_body]" => paste_body} form["#{aid}[title]"] = title if title form["language"] = language if language puts http_request(:form => form, :url => "%s/%s" % [PastrNote, @annotate_id]).content end |
#edit_it ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pastr_it.rb', line 86 def edit_it pid = "pastr_#{@pastr_id}" form = {} form["#{pid}[network]"] = network if network form["#{pid}[channel]"] = channel.sub(/^_/,"#") if channel form["#{pid}[title]"] = title if title form["language"] = language if language form["#{pid}[paste_body]"] = paste_body unless no_body puts http_request(:form => form, :url => "%s/%s" % [PastrEdit, @pastr_id]).content end |
#parse_args ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pastr_it.rb', line 28 def parse_args return @opts if @opts @opts = OptionParser.new @opts. = "\nUsage: pastr-it [options] FILE" @opts.separator "--- Common Pastr Options" @opts.separator " To paste from STDIN (instead of a file), leave off FILE, and you'll need to auth with a ~/.netrc" @opts.on("-u", "--username USERNAME", "Your username (Default: #{@username})") { |foo| @username = foo } @opts.on("-c", "--channel CHANNEL", "IRC Channel for this Pastr (Default: same as username)") { |foo| @channel = foo } @opts.separator "\tWhen using your username as the channel argument, the paste will be private" @opts.on("-n", "--network NETWORK", "IRC Network for this Pastr (Default: #{network})") { |foo| @network = foo } @opts.on("-l", "--language LANGUAGE", "Language to use for syntax highlighting") { |foo| @language = foo } @opts.on("-t", "--title TITLE", "Title of this paste (Default: Filename or 'Pastr by #{username}')") { |foo| @title = foo } @opts.separator "--- Editing" @opts.on("-e", "--edit PASTR_ID", "ID Of paste to edit (instead of making a new paste)") { |foo| @pastr_id = foo } @opts.on("-N", "--no-body", "Just edit metadata (channel, language, etc), not the paste body") { |foo| @no_body = true } @opts.separator "--- Annotate" @opts.on("-a", "--annotate PASTR_ID", "ID Of paste to annotate (incompatible with -e/--edit. -n/--network, and -c/--channel ignored.)") { |foo| @annotate_id = foo } @opts.separator "--- Informational" @opts.on("-L", "--list", "List supported languages") { |foo| @list_langs = true } @opts.on("-v", "--version", "Print pastr version") { |foo| @version_only = true } @opts.on_tail("-h", "--help", "Show this message") do puts @opts exit end @opts.parse!(@args) if @list_langs puts http_request(:url => "http://pastr.it/languages", :auth => false).content exit elsif @version_only puts "pastr-it for http://pastr.it - Version: #{PastrIt::VERSION}" exit end @filename = ARGV.shift if ARGV.size == 1 and File.file?(ARGV.first) unless @paste_id @title ||= File.basename(@filename) if @filename @channel ||= @username end if @filename.nil? and STDIN.isatty $stderr.puts "No Input on STDIN and no filename given, what am I supposed to paste?" puts @opts exit 1 end unless @pastr_id and @no_body end |
#pastr_it ⇒ Object
97 98 99 100 101 102 |
# File 'lib/pastr_it.rb', line 97 def pastr_it form = {'network' => network, 'channel' => channel.sub(/^_/,"#"), 'paste_body' => paste_body} form["title"] = title if title form["language"] = language if language puts http_request(:form => form).content end |