Advertise on Site! You can Advertise on our site. Find out More

wordpress XMLRPC api integration with ruby and rails

Ruby on Rails is really OOPs based framework. I personally love this framework. I worked on this for many years. Many Ruby lovers are looking to integrate the wordpress with Ruby on Rails. I strongly suggest to integrate wordpress with ROR using XMLRPC APIs. Using following code you can easily add the wordpress into Ruby on Rails Project. Use my following steps:

Note: There are so many XMLRPC APIs provided by wordpress. I given the some simple example here.

First setup wordpress. Login to wordpress admin and enable the XMLRPC.
Go to Settings->writing and enable the XMLRPC checkbox.

Now you can fetch the wordpress posts, pages, tags etc.. using XMLRPC.

Following script is written in Ruby.

require 'xmlrpc/client'

# build a post

#Use this for reference - http://codex.wordpress.org/XML-RPC_wp , http://codex.wordpress.org/XML-RPC_WordPress_API

post = {
'post_title'       => 'Post Title',
'post_excerpt'       => 'Post excerpt',
'post_content'       => 'this is Post content'
}

# initialize the connection - Change

connection = XMLRPC::Client.new2('http://www.wordpressapi.com/wordpress3/xmlrpc.php')  #Replace your wordpress URL

# make the call to publish a new post

#result = connection.call('metaWeblog.getRecentPosts', 1,'admin','123456') // Get Recent 10 Post
#result = connection.call('wp.getPost', 1,'admin','123456',19) // Get Single Post
#result = connection.call('wp.getPage', 1,'admin','123456',1) // Get Single Page
#result = connection.call('wp.getPages', 1,'admin','123456',10) // Get Pages
#result = connection.call('wp.getPosts', 1,'admin','123456') // Get 10 Posts from wordpress
result = connection.call('wp.getPosts', 1,'admin','123456',1000) // Get 10000 Posts from wordpress
#result = connection.call('wp.newPost', 1,'admin','123456',post) //For New Creating the Post

puts result // Printresult
puts result.length // Printresult

If you are facing any issue then write to me.

  • http://digcms.com John

    Very nice information about integration in Ruby.

  • http://testocore.org/ Thanh

    I take pleasure in, cause I discovered just what I was taking a look for. You’ve ended my 4 day long hunt! God Bless you man. Have a nice day. Bye