wordpress-xmlrpc 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/features/publish.feature +3 -3
- data/features/step_definitions/basic_steps.rb +1 -0
- data/lib/blog.rb +22 -15
- data/lib/post.rb +1 -0
- data/spec/blog_spec.rb +38 -17
- data/wordpress-xmlrpc.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/features/publish.feature
CHANGED
@@ -7,12 +7,12 @@ Feature: Publish post
|
|
7
7
|
And all posts and comments cleaned out
|
8
8
|
|
9
9
|
@wip
|
10
|
-
Scenario:
|
10
|
+
Scenario: Publish post
|
11
11
|
When I go to wordpress "home" page
|
12
12
|
Then I should see "wordpress"
|
13
13
|
When make following post:
|
14
|
-
| title | content
|
15
|
-
| hey ho | this is my first post | 01.08.2010 |
|
14
|
+
| title | content | creation_date | image |
|
15
|
+
| hey ho | this is my first post <br/> <img src="post_picture.jpg"/> | 01.08.2010 | spec/support/files/post_picture.jpg |
|
16
16
|
And I go to wordpress "home" page
|
17
17
|
Then I should see "hey ho"
|
18
18
|
And I should see "this is my first post"
|
@@ -22,6 +22,7 @@ end
|
|
22
22
|
When /^make following post:$/ do |table|
|
23
23
|
table.hashes.each do |hash|
|
24
24
|
hash['creation_date'] = Date.parse(hash.delete('creation_date')) if hash['creation_date']
|
25
|
+
hash.merge!({:images => [{:file_path => File.expand_path(hash.delete('image'))}]}) if hash['image']
|
25
26
|
post = Wordpress::Post.new(hash)
|
26
27
|
@blog.publish(post)
|
27
28
|
end
|
data/lib/blog.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'xmlrpc/client'
|
2
2
|
require 'params_check'
|
3
|
-
require 'base64'
|
4
3
|
require 'mimemagic'
|
5
4
|
require 'nokogiri'
|
6
5
|
|
@@ -34,24 +33,13 @@ module Wordpress
|
|
34
33
|
end #recent_posts
|
35
34
|
|
36
35
|
def publish(post)
|
37
|
-
|
38
|
-
post.images.each do |image|
|
39
|
-
image_file = File.open(image[:file_path], "rb")
|
40
|
-
file_name = File.basename(image_file.path)
|
41
|
-
|
42
|
-
uploaded_image = upload_file(File.open(image[:file_path], "rb"))
|
43
|
-
|
44
|
-
doc.xpath("img[contains(@src, '#{file_name}')]").each do |img|
|
45
|
-
img['src'] = uploaded_image[:url]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
post.content = doc.to_html
|
49
|
-
|
36
|
+
process_post_images(post)
|
50
37
|
post.id = blog_api_call("metaWeblog.newPost", post.to_struct, true).to_i
|
51
38
|
post.published = true
|
52
39
|
end #publish
|
53
40
|
|
54
41
|
def update_post(post)
|
42
|
+
process_post_images(post)
|
55
43
|
return api_call("metaWeblog.editPost", post.id, @user, @password, post.to_struct, post.published)
|
56
44
|
end #update_post
|
57
45
|
|
@@ -59,13 +47,32 @@ module Wordpress
|
|
59
47
|
struct = {
|
60
48
|
:name => File.basename(file.path),
|
61
49
|
:type => MimeMagic.by_magic(file).type,
|
62
|
-
:bits => Base64.
|
50
|
+
:bits => XMLRPC::Base64.new(File.open(file.path, "r").read),
|
63
51
|
:overwrite => true
|
64
52
|
}
|
65
53
|
return blog_api_call("wp.uploadFile", struct)
|
66
54
|
end
|
67
55
|
|
68
56
|
private
|
57
|
+
def process_post_images(post)
|
58
|
+
doc = Nokogiri::HTML::DocumentFragment.parse(post.content)
|
59
|
+
post.images.each do |image|
|
60
|
+
|
61
|
+
raise ArgumentError, "Image not found (path: #{image[:file_path]})" unless File.exist?(image[:file_path])
|
62
|
+
|
63
|
+
image_file = File.open(image[:file_path], "rb")
|
64
|
+
file_name = File.basename(image_file.path)
|
65
|
+
|
66
|
+
uploaded_image = upload_file(File.open(image[:file_path], "rb"))
|
67
|
+
raise "Image upload failed" if uploaded_image.nil?
|
68
|
+
|
69
|
+
doc.xpath("img[contains(@src, '#{file_name}')]").each do |img|
|
70
|
+
img['src'] = uploaded_image['url']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
post.content = doc.to_html
|
74
|
+
end #process_post_images
|
75
|
+
|
69
76
|
def api_call(method_name, *args)
|
70
77
|
begin
|
71
78
|
return @client.call(method_name, *args)
|
data/lib/post.rb
CHANGED
data/spec/blog_spec.rb
CHANGED
@@ -58,11 +58,7 @@ describe Wordpress::Blog do
|
|
58
58
|
|
59
59
|
describe "publish" do
|
60
60
|
it "should make appropriate call to xmlrpc api" do
|
61
|
-
images = [
|
62
|
-
{
|
63
|
-
:file_path => File.expand_path("./spec/support/files/post_picture.jpg")
|
64
|
-
}
|
65
|
-
]
|
61
|
+
images = [{:file_path => File.expand_path("./spec/support/files/post_picture.jpg")}]
|
66
62
|
post = Wordpress::Post.new(
|
67
63
|
:title => "Hey ho",
|
68
64
|
:content => "Content <img src=\"http://otherhost/post_picture.jpg\">",
|
@@ -76,26 +72,27 @@ describe Wordpress::Blog do
|
|
76
72
|
:description=>"Content <img src=\"http://localhost/post_picture.jpg\">",
|
77
73
|
:mt_excerpt=>"Excerpt"
|
78
74
|
}
|
79
|
-
@client_mock.should_receive(:call).with(
|
80
|
-
"metaWeblog.newPost",
|
81
|
-
0, "admin", "wordpress-xmlrpc",
|
82
|
-
required_post_struct, true).and_return("123")
|
83
75
|
|
84
76
|
@client_mock.should_receive(:call).with(
|
85
77
|
"wp.uploadFile",
|
86
78
|
0, "admin", "wordpress-xmlrpc",
|
87
79
|
{
|
80
|
+
:name => "post_picture.jpg",
|
88
81
|
:type => "image/jpeg",
|
89
82
|
:bits => "encoded file content",
|
90
|
-
:overwrite => true
|
91
|
-
:name => "post_picture.jpg"
|
83
|
+
:overwrite => true
|
92
84
|
}).and_return({
|
93
|
-
|
94
|
-
|
95
|
-
|
85
|
+
'file' => "post_picture.jpg",
|
86
|
+
'url' => "http://localhost/post_picture.jpg",
|
87
|
+
'type' => "image/jpeg"
|
96
88
|
})
|
97
89
|
|
98
|
-
|
90
|
+
@client_mock.should_receive(:call).with(
|
91
|
+
"metaWeblog.newPost",
|
92
|
+
0, "admin", "wordpress-xmlrpc",
|
93
|
+
required_post_struct, true).and_return("123")
|
94
|
+
|
95
|
+
XMLRPC::Base64.should_receive(:new).and_return("encoded file content")
|
99
96
|
|
100
97
|
@blog.publish(post).should be_true
|
101
98
|
post.id.should == 123
|
@@ -133,8 +130,32 @@ describe Wordpress::Blog do
|
|
133
130
|
|
134
131
|
describe "update_post" do
|
135
132
|
it "should submit post update" do
|
136
|
-
|
137
|
-
|
133
|
+
images = [{:file_path => File.expand_path("./spec/support/files/post_picture.jpg")}]
|
134
|
+
post = Wordpress::Post.new(:id => 54, :title => "Updated post", :content => "Content <img src=\"http://otherhost/post_picture.jpg\">", :published => true, :images => images)
|
135
|
+
|
136
|
+
required_post_struct = {
|
137
|
+
:title=>"Updated post",
|
138
|
+
:description=>"Content <img src=\"http://localhost/post_picture.jpg\">",
|
139
|
+
:postid => 54
|
140
|
+
}
|
141
|
+
@client_mock.should_receive(:call).with("metaWeblog.editPost",
|
142
|
+
54, "admin", "wordpress-xmlrpc",
|
143
|
+
required_post_struct, true).and_return(true)
|
144
|
+
|
145
|
+
@client_mock.should_receive(:call).with("wp.uploadFile",
|
146
|
+
0, "admin", "wordpress-xmlrpc",
|
147
|
+
{
|
148
|
+
:name => "post_picture.jpg",
|
149
|
+
:type => "image/jpeg",
|
150
|
+
:bits => "encoded file content",
|
151
|
+
:overwrite => true
|
152
|
+
}).and_return({
|
153
|
+
'file' => "post_picture.jpg",
|
154
|
+
'url' => "http://localhost/post_picture.jpg",
|
155
|
+
'type' => "image/jpeg"
|
156
|
+
})
|
157
|
+
XMLRPC::Base64.should_receive(:new).and_return("encoded file content")
|
158
|
+
|
138
159
|
@blog.update_post(post).should be_true
|
139
160
|
end
|
140
161
|
end
|
data/wordpress-xmlrpc.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordpress-xmlrpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexander Naumenko
|