diff --git a/bin/gistr b/bin/gistr index 5a0dcd9..c46cadf 100755 --- a/bin/gistr +++ b/bin/gistr @@ -23,6 +23,10 @@ op = OptionParser.new do |o| o.on "-b", "--blog=BLOG", "Tumblr blog" do |blog| opts.blog = blog end + + o.on "-r", "--private=1", "Private post?" do |private| + opts.private = private + end end gist_id = *op.parse!(ARGV) @@ -32,7 +36,7 @@ unless gist_id exit(1) end -g = Gistr.new(gist_id) +g = Gistr.new(gist_id, { :private => opts.private }) g.post opts.email, opts.password, opts.title, opts.blog diff --git a/lib/gistr.rb b/lib/gistr.rb index 54162d7..66a3bc8 100644 --- a/lib/gistr.rb +++ b/lib/gistr.rb @@ -1,9 +1,9 @@ require 'open-uri' -require 'hpricot' class Gistr - def initialize(gist_id) + def initialize(gist_id, options = {}) @gist_id = gist_id + @post_private = options[:private] || 1 end def post(email, password, title, blog) @@ -14,29 +14,18 @@ def gist_code return @gist_code if @gist_code # Use the secret .pibb format - code = open("http://gist.github.com/#{@gist_id}.pibb").read + code = open("https://gist.github.com/#{@gist_id}.pibb").read - # Remove the
 tag
-    #
-    # Tumblr wrap lines at of HTML at times and having the additional
-    # whitespace in a 
 is very undesirable.
-    h = Hpricot(code)
-
-    h.search('pre').each do |pre|
-      pre.swap(pre.inner_html) if pre.inner_html.length > 0
-    end
-
-    @gist_code = h.to_html
+    @gist_code = code
   end
 
   private
   def post_to_tumblr(email, password, title, blog, body)
-    post_private = 1
     Net::HTTP.start("www.tumblr.com") do |http|
       req = Net::HTTP::Post.new("/api/write")
       req.set_form_data :email => email, :password => password,
         :title => title, :body => body, :format => 'html',
-        :private => post_private, :group => blog
+        :private => @post_private, :group => blog
 
       http.request(req)
     end