wp2tumblr 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/bin/wp2tumblr +43 -17
- data/lib/wp2tumblr.rb +1 -0
- data/lib/wp2tumblr/config.rb +22 -0
- data/lib/wp2tumblr/tumblr_client.rb +1 -0
- data/lib/wp2tumblr/version.rb +1 -1
- data/lib/wp2tumblr/wordpress.rb +3 -3
- data/spec/wp2tumblr/wordpress_format.xml +1 -1
- data/spec/wp2tumblr_spec.rb +17 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa3cb0fc81507ba8122d6dfdfe7092fda46be2b5
|
4
|
+
data.tar.gz: dc2c48808a149bd84ca16020207fb833c2a96650
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88090ceaa17c302081022e2ed2b538f087a1558393fbf34548f7077ef3ce52cc13ac8894a8dd5654e22c4f5a79df5a6f115a1ec545a9de527a9125fe7266be76
|
7
|
+
data.tar.gz: e352f6afa69a041df9645b52da2f492ca9d6a5a54e5c2a7f6a8aba6928e4e0e29a29826550ca16b7184610b5e82cdee15b0049fc180a292f168fc792d8421556
|
data/bin/wp2tumblr
CHANGED
@@ -6,11 +6,14 @@ require "yaml"
|
|
6
6
|
require "optparse"
|
7
7
|
|
8
8
|
options = {}
|
9
|
+
site = "http://www.tumblr.com"
|
10
|
+
|
9
11
|
opt_parser = OptionParser.new do |opt|
|
10
12
|
opt.banner = "Usage: wp2tumblr COMMAND [OPTIONS]"
|
11
13
|
opt.separator ""
|
12
14
|
opt.separator "Commands"
|
13
15
|
opt.separator " text: upload posts as type 'text'"
|
16
|
+
opt.separator " config: configure your Tumblr API credentials"
|
14
17
|
opt.separator ""
|
15
18
|
opt.separator "Options"
|
16
19
|
|
@@ -25,28 +28,52 @@ end
|
|
25
28
|
|
26
29
|
opt_parser.parse!
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
puts opt_parser unless ARGV[0]
|
32
|
+
|
33
|
+
tumblr_config_path = File.join ENV['HOME'], '.wp2tumblr'
|
34
|
+
|
35
|
+
if ARGV[0] === "config"
|
36
|
+
api_config = {}
|
37
|
+
puts "Register an application at: #{site}/oauth/apps"
|
38
|
+
|
39
|
+
print "OAuth Consumer key: "
|
40
|
+
api_config[:consumer_key] = $stdin.gets.chomp
|
41
|
+
|
42
|
+
print "OAuth Consumer secret: "
|
43
|
+
api_config[:consumer_secret] = $stdin.gets.chomp
|
44
|
+
|
45
|
+
consumer = OAuth::Consumer.new(api_config[:consumer_key], api_config[:consumer_secret], :site => site)
|
46
|
+
request_token = consumer.get_request_token :exclude_callback => true
|
47
|
+
|
48
|
+
puts request_token.authorize_url
|
34
49
|
|
35
|
-
|
50
|
+
puts "After you have received your oauth_verifier, paste it below."
|
51
|
+
puts "OAuth Verifier: "
|
52
|
+
api_config[:verifier] = $stdin.gets.chomp
|
53
|
+
|
54
|
+
access_token = request_token.get_access_token :oauth_verifier => api_config[:verifier]
|
55
|
+
api_config[:oauth_token] = access_token.token
|
56
|
+
api_config[:oauth_token_secret] = access_token.secret
|
57
|
+
|
58
|
+
Wp2tumblr::Config.save_api_credentials(api_config, ".wp2tumblr")
|
59
|
+
|
60
|
+
puts "Credentials saved, run 'wp2tumblr COMMAND [OPTIONS]' again"
|
61
|
+
end
|
36
62
|
|
37
63
|
if File.exists?(tumblr_config_path)
|
38
64
|
|
39
65
|
config = YAML.load_file tumblr_config_path
|
40
66
|
client = Wp2tumblr::TumblrClient.new(config["consumer_key"], config["consumer_secret"], config["oauth_token"], config["oauth_token_secret"])
|
41
|
-
file = File.open(options[:file]) if File.exists?(options[:file])
|
67
|
+
file = File.open(options[:file]) if options[:file] and File.exists?(options[:file])
|
42
68
|
|
43
|
-
if client.connect
|
44
|
-
puts "Successfully authenticated with Tumblr!"
|
45
|
-
else
|
46
|
-
puts "There was an error authenticating with Tumblr. Please check #{tumblr_config_path} and make sure your credentials are correct."
|
47
|
-
end
|
48
|
-
|
49
69
|
if ARGV[0] === "text"
|
70
|
+
if client.connect
|
71
|
+
puts "Successfully authenticated with Tumblr!"
|
72
|
+
puts "Posting text posts with the options: #{options.inspect}"
|
73
|
+
else
|
74
|
+
puts "There was an error authenticating with Tumblr. Please check #{tumblr_config_path} and make sure your credentials are correct."
|
75
|
+
end
|
76
|
+
|
50
77
|
if file
|
51
78
|
posts = Wp2tumblr::Wordpress.parse_xml(file, :posts)
|
52
79
|
client.text_posts(options[:blog_name], posts)
|
@@ -57,7 +84,6 @@ if File.exists?(tumblr_config_path)
|
|
57
84
|
|
58
85
|
else
|
59
86
|
puts ""
|
60
|
-
puts "You need to configure your Tumblr
|
61
|
-
puts "
|
62
|
-
puts "run 'tumblr' then try again"
|
87
|
+
puts "You need to configure your Tumblr API credentials."
|
88
|
+
puts "run 'wp2tumblr config'"
|
63
89
|
end
|
data/lib/wp2tumblr.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Wp2tumblr
|
2
|
+
module Config
|
3
|
+
|
4
|
+
VALID_OPTIONS_KEYS = [
|
5
|
+
:consumer_key,
|
6
|
+
:consumer_secret,
|
7
|
+
:oauth_token,
|
8
|
+
:oauth_token_secret
|
9
|
+
]
|
10
|
+
|
11
|
+
def self.save_api_credentials(credentials, file_name)
|
12
|
+
File.open(File.join(ENV['HOME'], file_name), "w") do |f|
|
13
|
+
configuration = {}
|
14
|
+
VALID_OPTIONS_KEYS.each do |key|
|
15
|
+
configuration[key.to_s] = credentials[key]
|
16
|
+
end
|
17
|
+
f.write YAML.dump configuration
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/wp2tumblr/version.rb
CHANGED
data/lib/wp2tumblr/wordpress.rb
CHANGED
@@ -20,7 +20,7 @@ module Wp2tumblr
|
|
20
20
|
items = get_file_contents(file)
|
21
21
|
@posts = []
|
22
22
|
items.to_enum.with_index(0) do |item, i|
|
23
|
-
@posts[i] = {title: item.at_xpath("title").text, content: parse_images(item.at_xpath("content:encoded")
|
23
|
+
@posts[i] = {title: item.at_xpath("title").text, content: parse_images(item.at_xpath("content:encoded")), created_at: item.at_xpath("pubDate").text}
|
24
24
|
end
|
25
25
|
@posts
|
26
26
|
end
|
@@ -88,7 +88,7 @@ module Wp2tumblr
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def self.parse_images(post_content)
|
91
|
-
html =
|
91
|
+
html = post_content
|
92
92
|
html.css("img").each do |image|
|
93
93
|
begin
|
94
94
|
encoded_image = Base64.encode64(open(image['src']) {|io| io.read})
|
@@ -97,7 +97,7 @@ module Wp2tumblr
|
|
97
97
|
next
|
98
98
|
end
|
99
99
|
file_extension = image['src'][/\.[^.]*$/].split('.')[1]
|
100
|
-
image['src'] = "data:image/#{file_extension};base64,#{encoded_image}"
|
100
|
+
image['src'] = "data:image/#{file_extension};base64,#{encoded_image}" if encoded_image
|
101
101
|
end
|
102
102
|
html
|
103
103
|
end
|
@@ -113,7 +113,7 @@
|
|
113
113
|
<dc:creator>testuser</dc:creator>
|
114
114
|
<guid isPermaLink="false">http://testblog.com/?p=3199</guid>
|
115
115
|
<description></description>
|
116
|
-
<content:encoded><![CDATA[test content <div class="center"><img src="http://
|
116
|
+
<content:encoded><![CDATA[test content <div class="center"><img src="http://placekitten.com.s3.amazonaws.com/homepage-samples/200/287.jpg" alt=""/></div>]]></content:encoded>
|
117
117
|
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
|
118
118
|
<wp:post_id>3199</wp:post_id>
|
119
119
|
<wp:post_date>2013-03-01 07:59:29</wp:post_date>
|
data/spec/wp2tumblr_spec.rb
CHANGED
@@ -53,7 +53,7 @@ describe Wp2tumblr::Wordpress do
|
|
53
53
|
describe ".parse_images" do
|
54
54
|
it "Encodes images as base64" do
|
55
55
|
posts = Wp2tumblr::Wordpress.parse_xml(file, :posts)
|
56
|
-
post = posts[0][:content]
|
56
|
+
post = Nokogiri::HTML(posts[0][:content].text)
|
57
57
|
Wp2tumblr::Wordpress.parse_images(post).to_s.should include('base64')
|
58
58
|
end
|
59
59
|
end
|
@@ -82,7 +82,22 @@ describe Wp2tumblr::TumblrClient do
|
|
82
82
|
it "should post text posts to the Tumblr api" do
|
83
83
|
posts = Wp2tumblr::Wordpress.parse_xml(file, :posts)
|
84
84
|
client.connect
|
85
|
-
client.text_posts(config["tumblr_blog_name"]
|
85
|
+
client.text_posts(config["tumblr_blog_name"], posts)
|
86
86
|
end
|
87
87
|
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe Wp2tumblr::Config do
|
91
|
+
it "saves API credentials to a YAML file." do
|
92
|
+
api_config = {
|
93
|
+
:consumer_key => "CONSUMER_KEY",
|
94
|
+
:consumer_secret => "CONSUMER_SECRET",
|
95
|
+
:oauth_token => "OAUTH_TOKEN",
|
96
|
+
:oauth_token_secret => "OAUTH_TOKEN_SECRET"
|
97
|
+
}
|
98
|
+
|
99
|
+
Wp2tumblr::Config.save_api_credentials(api_config, ".wp2tumblr_spec")
|
100
|
+
config = YAML.load_file File.join ENV['HOME'], '.wp2tumblr_spec'
|
101
|
+
config["consumer_key"].should eq("CONSUMER_KEY");
|
102
|
+
end
|
88
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wp2tumblr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jonlunsford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- Rakefile
|
139
139
|
- bin/wp2tumblr
|
140
140
|
- lib/wp2tumblr.rb
|
141
|
+
- lib/wp2tumblr/config.rb
|
141
142
|
- lib/wp2tumblr/tumblr_client.rb
|
142
143
|
- lib/wp2tumblr/version.rb
|
143
144
|
- lib/wp2tumblr/wordpress.rb
|
@@ -165,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
166
|
version: '0'
|
166
167
|
requirements: []
|
167
168
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
169
|
+
rubygems_version: 2.1.5
|
169
170
|
signing_key:
|
170
171
|
specification_version: 4
|
171
172
|
summary: This gem utilizes the Tumblr api to create posts from a wordpress post XML
|