Skip to content

Commit

Permalink
now using new api
Browse files Browse the repository at this point in the history
  • Loading branch information
dougsko committed Aug 10, 2012
1 parent 83d5b17 commit 2889ba9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
8 changes: 4 additions & 4 deletions Gemfile
Expand Up @@ -7,8 +7,8 @@ source "http://rubygems.org"
# Include everything needed to run rake, tests, features, etc.

group :development do
gem "rspec", "~> 2.1.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.1"
gem "rcov", ">= 0"
gem "rspec"
gem "bundler"
gem "jeweler"
gem "rcov"
end
30 changes: 15 additions & 15 deletions Gemfile.lock
@@ -1,28 +1,28 @@
GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.2)
diff-lcs (1.1.3)
git (1.2.5)
jeweler (1.5.1)
bundler (~> 1.0.0)
jeweler (1.6.4)
bundler (~> 1.0)
git (>= 1.2.5)
rake
rake (0.8.7)
rcov (0.9.9)
rspec (2.1.0)
rspec-core (~> 2.1.0)
rspec-expectations (~> 2.1.0)
rspec-mocks (~> 2.1.0)
rspec-core (2.1.0)
rspec-expectations (2.1.0)
rake (0.9.2.2)
rcov (0.9.11)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
rspec-mocks (2.7.0)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.1)
bundler
jeweler
rcov
rspec (~> 2.1.0)
rspec
13 changes: 6 additions & 7 deletions bin/pastebin
Expand Up @@ -6,7 +6,6 @@
# Copyright (C) 2010 Doug Prostko
#

require 'rubygems'
require 'optparse'
require 'pastebin'

Expand All @@ -23,17 +22,17 @@ opts = OptionParser.new do |opts|

opts.on("-f <file>", "--file <file>", String,
"Use a file for input, use \"-\" for STDIN") do |f|
options["paste_code"] = f
options["api_paste_code"] = f
end

opts.on("-n", "--name <name>", String,
"Assign a name/title to your paste") do |n|
options["paste_name"] = n
options["api_paste_name"] = n
end

opts.on("-s", "--subdomain <subdomain>", String,
"Paste to a specific subdomain") do |s|
options["paste_subdomain"] = s
options["api_paste_subdomain"] = s
end

opts.on("-r", "--raw <link>", String,
Expand All @@ -50,7 +49,7 @@ opts = OptionParser.new do |opts|
]
expire_list = expire_array.join(", ")
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|
options["paste_expire_date"] = e
options["api_paste_expire_date"] = e
end

syntax_array = [ 'perl',
Expand All @@ -69,11 +68,11 @@ opts = OptionParser.new do |opts|

code_list = syntax_array.join(", ")
opts.on("-l", "--language <syntax>", syntax_array, "Syntax types can be abbriviated, as long as they are unambigous. There are many more supported languages than what is listed here. Defaults to 'text'", " #{code_list}") do |encoding|
options["paste_format"] = encoding
options["api_paste_format"] = encoding
end

opts.on("-p", "--private", "Make paste private.") do
options["paste_private"] = "1"
options["api_paste_private"] = "1"
end

opts.on_tail("-h", "--help", "Show this message") do
Expand Down
16 changes: 10 additions & 6 deletions lib/pastebin.rb
Expand Up @@ -9,30 +9,34 @@
class Pastebin
include REXML

DEVKEY = "01fe34146583c731f3725fd8dde3992c"

# The only option required is 'paste_code', which holds your string.
#
def initialize(options)
@options = options
@options["api_dev_key"] = DEVKEY
end

# This POSTs the paste and returns the link
#
# pbin.paste #=> "http://pastebin.com/xxxxxxx"
#
def paste
if @options.has_key?("paste_code")
if @options["paste_code"] == "-"
@options["paste_code"] = $stdin.read
if @options.has_key?("api_paste_code")
if @options["api_paste_code"] == "-"
@options["api_paste_code"] = $stdin.read
else
File.open(@options["paste_code"]) do |file|
@options["paste_code"] = file.read
File.open(@options["api_paste_code"]) do |file|
@options["api_paste_code"] = file.read
end
end
#else
# puts "You must specify a file or '-' for STDIN"
# exit
end
Net::HTTP.post_form(URI.parse('http://pastebin.com/api_public.php'),
@options["api_option"] = "paste"
Net::HTTP.post_form(URI.parse('http://pastebin.com/api/api_post.php'),
@options).body
end

Expand Down

0 comments on commit 2889ba9

Please sign in to comment.