Ruby, WordPress: reading the most recent posts
Having read the WordPress docs, and done some research, it seems as if the advice on how to get the last 10 posts on a WordPress site, is to do the following:
require 'xmlrpc/client' #initialize a connection connection = XMLRPC::Client.new2('http://www.mywordpresssite.com') result = connection.call('metaWeblog.getRecentPosts', 1,'admin','123456') #or it seems that I can also call: result = connection.call('wp.getPages', 1,'admin','123456',10)
Following the connection call, I get a legitimate result:
=> #<XMLRPC::Client:0x007fdfec50cac0 @http_header_extra=nil, @http_last_response=nil, @cookie=nil, @host="www.mywordpresssite.com", @path="/RPC2", @proxy_host=nil, @proxy_port=nil, @use_ssl=false, @timeout=30, @port=80, @password=nil, @user=nil, @auth=nil, @http=#<Net::HTTP www.mywordpresssite.com:80 open=false>, @parser=nil, @create=nil>
But when I do:
result = connection.call('wp.getPages', 1,'admin','123456',10)
result = connection.call('metaWeblog.getRecentPosts', 1,'admin','123456')
SocketError: getaddrinfo: nodename nor servname provided, or not known
Actually I was having the same error message when trying to post from my Sinatra app with the xmlrpc/client.
The interesting is, when I used the same way of posting from IRB, I could successfully post to my blog.
I found out that it seems xmlrpc does not really like the protocol. I removed the
from the link and it went without a hitch. Give it a try, maybe helps.