Created
December 12, 2011 17:04
-
-
Save lleger/1468204 to your computer and use it in GitHub Desktop.
Ruby XMLRPC (Wordpress) Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'xmlrpc/client' | |
require 'pp' | |
class XMLRPC::Client | |
def set_debug | |
@http.set_debug_output($stderr); | |
end | |
end | |
module XMLRPCWorkAround | |
def do_rpc(request, async=false) | |
data = super | |
data.force_encoding("UTF-8") | |
data | |
end | |
end | |
connection = XMLRPC::Client.new('WEBSITE.com', '/xmlrpc.php') | |
# connection.set_debug | |
connection.extend(XMLRPCWorkAround) | |
begin | |
result = connection.call('blogger.getRecentPosts', 0, 0, 'ADMIN', 'PASSWORD', 10) | |
rescue XMLRPC::FaultException => e | |
puts e.faultString | |
end | |
pp result.first["dateCreated"].to_s | |
pp result.first["content"].match(/<title>(.*)<\/title>/)[1] | |
pp result.first["content"].match(/<category>(.*)<\/category>/)[1] | |
pp result.first["content"].gsub(/<title>(.*)<\/title>/, "").gsub(/<category>(.*)<\/category>/, "") | |
begin | |
result = connection.call('mt.getPostCategories', result.first["postid"], 'ADMIN', 'PASSWORD') | |
rescue XMLRPC::FaultException => e | |
puts e.faultString | |
end | |
pp result.first["categoryName"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment