gistr 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/gistr +38 -0
- data/lib/gistr.rb +44 -0
- metadata +75 -0
data/bin/gistr
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/gistr')
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
require 'ostruct'
|
7
|
+
|
8
|
+
opts = OpenStruct.new
|
9
|
+
|
10
|
+
op = OptionParser.new do |o|
|
11
|
+
o.on "-e", "--email=EMAIL", "Tumblr email address" do |email|
|
12
|
+
opts.email = email
|
13
|
+
end
|
14
|
+
|
15
|
+
o.on "-p", "--password=PASSWORD", "Tumblr password" do |password|
|
16
|
+
opts.password = password
|
17
|
+
end
|
18
|
+
|
19
|
+
o.on "-t", "--title=TITLE", "Tumblr post title" do |title|
|
20
|
+
opts.title = title
|
21
|
+
end
|
22
|
+
|
23
|
+
o.on "-b", "--blog=BLOG", "Tumblr blog" do |blog|
|
24
|
+
opts.blog = blog
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
gist_id = *op.parse!(ARGV)
|
29
|
+
|
30
|
+
unless gist_id
|
31
|
+
puts op
|
32
|
+
exit(1)
|
33
|
+
end
|
34
|
+
|
35
|
+
g = Gistr.new(gist_id)
|
36
|
+
|
37
|
+
g.post opts.email, opts.password, opts.title, opts.blog
|
38
|
+
|
data/lib/gistr.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'hpricot'
|
3
|
+
|
4
|
+
class Gistr
|
5
|
+
def initialize(gist_id)
|
6
|
+
@gist_id = gist_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def post(email, password, title, blog)
|
10
|
+
post_to_tumblr(email, password, title, blog, gist_code)
|
11
|
+
end
|
12
|
+
|
13
|
+
def gist_code
|
14
|
+
return @gist_code if @gist_code
|
15
|
+
|
16
|
+
# Use the secret .pibb format
|
17
|
+
code = open("http://gist.github.com/#{@gist_id}.pibb").read
|
18
|
+
|
19
|
+
# Remove the <pre> tag
|
20
|
+
#
|
21
|
+
# Tumblr wrap lines at of HTML at times and having the additional
|
22
|
+
# whitespace in a <pre> is very undesirable.
|
23
|
+
h = Hpricot(code)
|
24
|
+
|
25
|
+
h.search('pre').each do |pre|
|
26
|
+
pre.swap(pre.inner_html)
|
27
|
+
end
|
28
|
+
|
29
|
+
@gist_code = h.to_html
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def post_to_tumblr(email, password, title, blog, body)
|
34
|
+
post_private = 1
|
35
|
+
Net::HTTP.start("www.tumblr.com") do |http|
|
36
|
+
req = Net::HTTP::Post.new("/api/write")
|
37
|
+
req.set_form_data :email => email, :password => password,
|
38
|
+
:title => title, :body => body, :format => 'html',
|
39
|
+
:private => post_private, :group => blog
|
40
|
+
|
41
|
+
http.request(req)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gistr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Lindvall
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-30 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: activesupport
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: eric@5stops.com
|
37
|
+
executables:
|
38
|
+
- gistr
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- bin/gistr
|
45
|
+
- lib/gistr.rb
|
46
|
+
has_rdoc: true
|
47
|
+
homepage:
|
48
|
+
licenses: []
|
49
|
+
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.3.5
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Command line utility to post gists to a tumble log.
|
74
|
+
test_files: []
|
75
|
+
|