wordpress-xmlrpc 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/VERSION +1 -1
- data/features/publish.feature +3 -2
- data/features/step_definitions/basic_steps.rb +2 -2
- data/lib/blog.rb +26 -0
- data/lib/post.rb +2 -1
- data/spec/blog_spec.rb +34 -3
- data/spec/support/files/post_picture.jpg +0 -0
- data/wordpress-xmlrpc.gemspec +3 -2
- metadata +5 -4
data/Gemfile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/features/publish.feature
CHANGED
@@ -6,12 +6,13 @@ Feature: Publish post
|
|
6
6
|
Given I have a blog control
|
7
7
|
And all posts and comments cleaned out
|
8
8
|
|
9
|
+
@wip
|
9
10
|
Scenario: Load wordpress home page
|
10
11
|
When I go to wordpress "home" page
|
11
12
|
Then I should see "wordpress"
|
12
13
|
When make following post:
|
13
|
-
| title | content |
|
14
|
-
| hey ho | this is my first post |
|
14
|
+
| title | content | creation_date |
|
15
|
+
| hey ho | this is my first post | 01.08.2010 |
|
15
16
|
And I go to wordpress "home" page
|
16
17
|
Then I should see "hey ho"
|
17
18
|
And I should see "this is my first post"
|
@@ -16,12 +16,12 @@ Then /^I should see "([^\"]*)"$/ do |expected_content|
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Given /^I have a blog control$/ do
|
19
|
-
@blog = Wordpress::Blog.new(:
|
19
|
+
@blog = Wordpress::Blog.new(:blog_uri => "http://localhost", :user => "admin", :password => "wordpress-xmlrpc")
|
20
20
|
end
|
21
21
|
|
22
22
|
When /^make following post:$/ do |table|
|
23
23
|
table.hashes.each do |hash|
|
24
|
-
hash['
|
24
|
+
hash['creation_date'] = Date.parse(hash.delete('creation_date')) if hash['creation_date']
|
25
25
|
post = Wordpress::Post.new(hash)
|
26
26
|
@blog.publish(post)
|
27
27
|
end
|
data/lib/blog.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'xmlrpc/client'
|
2
2
|
require 'params_check'
|
3
|
+
require 'base64'
|
4
|
+
require 'mimemagic'
|
5
|
+
require 'nokogiri'
|
3
6
|
|
4
7
|
module Wordpress
|
5
8
|
class Blog
|
@@ -31,6 +34,19 @@ module Wordpress
|
|
31
34
|
end #recent_posts
|
32
35
|
|
33
36
|
def publish(post)
|
37
|
+
doc = Nokogiri::HTML::DocumentFragment.parse(post.content)
|
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
|
+
|
34
50
|
post.id = blog_api_call("metaWeblog.newPost", post.to_struct, true).to_i
|
35
51
|
post.published = true
|
36
52
|
end #publish
|
@@ -39,6 +55,16 @@ module Wordpress
|
|
39
55
|
return api_call("metaWeblog.editPost", post.id, @user, @password, post.to_struct, post.published)
|
40
56
|
end #update_post
|
41
57
|
|
58
|
+
def upload_file(file)
|
59
|
+
struct = {
|
60
|
+
:name => File.basename(file.path),
|
61
|
+
:type => MimeMagic.by_magic(file).type,
|
62
|
+
:bits => Base64.encode64(file.read),
|
63
|
+
:overwrite => true
|
64
|
+
}
|
65
|
+
return blog_api_call("wp.uploadFile", struct)
|
66
|
+
end
|
67
|
+
|
42
68
|
private
|
43
69
|
def api_call(method_name, *args)
|
44
70
|
begin
|
data/lib/post.rb
CHANGED
data/spec/blog_spec.rb
CHANGED
@@ -58,14 +58,44 @@ describe Wordpress::Blog do
|
|
58
58
|
|
59
59
|
describe "publish" do
|
60
60
|
it "should make appropriate call to xmlrpc api" do
|
61
|
-
|
61
|
+
images = [
|
62
|
+
{
|
63
|
+
:file_path => File.expand_path("./spec/support/files/post_picture.jpg")
|
64
|
+
}
|
65
|
+
]
|
62
66
|
post = Wordpress::Post.new(
|
63
67
|
:title => "Hey ho",
|
64
|
-
:content => "Content",
|
68
|
+
:content => "Content <img src=\"http://otherhost/post_picture.jpg\">",
|
65
69
|
:excerpt => "Excerpt",
|
70
|
+
:images => images,
|
66
71
|
:publish_date => Date.parse("01.08.2010"))
|
67
72
|
|
68
|
-
|
73
|
+
|
74
|
+
required_post_struct = {
|
75
|
+
:title=>"Hey ho",
|
76
|
+
:description=>"Content <img src=\"http://localhost/post_picture.jpg\">",
|
77
|
+
:mt_excerpt=>"Excerpt"
|
78
|
+
}
|
79
|
+
@client_mock.should_receive(:call).with(
|
80
|
+
"metaWeblog.newPost",
|
81
|
+
0, "admin", "wordpress-xmlrpc",
|
82
|
+
required_post_struct, true).and_return("123")
|
83
|
+
|
84
|
+
@client_mock.should_receive(:call).with(
|
85
|
+
"wp.uploadFile",
|
86
|
+
0, "admin", "wordpress-xmlrpc",
|
87
|
+
{
|
88
|
+
:type => "image/jpeg",
|
89
|
+
:bits => "encoded file content",
|
90
|
+
:overwrite => true,
|
91
|
+
:name => "post_picture.jpg"
|
92
|
+
}).and_return({
|
93
|
+
:file => "post_picture.jpg",
|
94
|
+
:url => "http://localhost/post_picture.jpg",
|
95
|
+
:type => "image/jpeg"
|
96
|
+
})
|
97
|
+
|
98
|
+
Base64.should_receive(:encode64).and_return("encoded file content")
|
69
99
|
|
70
100
|
@blog.publish(post).should be_true
|
71
101
|
post.id.should == 123
|
@@ -108,6 +138,7 @@ describe Wordpress::Blog do
|
|
108
138
|
@blog.update_post(post).should be_true
|
109
139
|
end
|
110
140
|
end
|
141
|
+
|
111
142
|
end
|
112
143
|
end
|
113
144
|
|
Binary file
|
data/wordpress-xmlrpc.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wordpress-xmlrpc}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alexander Naumenko"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-20}
|
13
13
|
s.description = %q{Please do not fork it before directly contacint}
|
14
14
|
s.email = %q{alecnmk@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
|
|
38
38
|
"spec/post_spec.rb",
|
39
39
|
"spec/spec.opts",
|
40
40
|
"spec/spec_helper.rb",
|
41
|
+
"spec/support/files/post_picture.jpg",
|
41
42
|
"wordpress-xmlrpc.gemspec"
|
42
43
|
]
|
43
44
|
s.homepage = %q{http://github.com/alecnmk/wordpress-xmlrpc}
|
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alexander Naumenko
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-20 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- spec/post_spec.rb
|
82
82
|
- spec/spec.opts
|
83
83
|
- spec/spec_helper.rb
|
84
|
+
- spec/support/files/post_picture.jpg
|
84
85
|
- wordpress-xmlrpc.gemspec
|
85
86
|
has_rdoc: true
|
86
87
|
homepage: http://github.com/alecnmk/wordpress-xmlrpc
|