昨天試用了mediawiki-butt後,想到是不是也有wordpress的ruby介面,搜尋了一下,還真的有,就是本文要介紹的rubypress。
https://github.com/zachfeldman/rubypress
1.安裝
gem install rubypress
2.馬上試用
require 'rubypress'
wp = Rubypress::Client.new(
host: "example.com",
username: "user",
password: "passwor"
)
wp.newPost(
content: {
post_status: "publish",
post_date: Time.now,
post_content: "This is the body",
post_title: "RubyPress is the best!",
post_name: "/rubypress-is-the-best",
post_author: 1, # 1 if there is only the admin user, otherwise the user's id
terms_names: {
category: ['Category One','Category Two','Category Three'],
post_tag: ['Tag One','Tag Two', 'Tag Three']
}
}
)
3.去wordpress看是否文章已出現。
4.又例如,取得id為425的post之標題和內容
post = wp.getPost(post_id: 425) p "標題:" + post["post_title"] p "內容:" + post["post_content"]
結果為:
標題:Wordpress之ruby介面:rubypress 內容:<!-- wp:paragraph --> <p>[rdp-wiki-embed url='http://apache:8080/mediawiki/index.php/Wordpress%E4%B9%8Bruby%E4%BB%8B%E9%9D%A2%EF%BC%9Arubypress']</p> <!-- /wp:paragraph -->
注意事項:
如果你有使用多站網路的功能,也不需使用blog_id,只要建立連結時,host設成要連結的blog網址即可。我使用blog_id,不管設的值為何,都是第一個blog,只有設host才成功。