Skip to content

gist changes #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/gistr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

21 changes: 5 additions & 16 deletions lib/gistr.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 <pre> tag
#
# Tumblr wrap lines at of HTML at times and having the additional
# whitespace in a <pre> 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
Expand Down