Created
June 27, 2011 16:41
-
-
Save sfentress/1049246 to your computer and use it in GitHub Desktop.
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 'builder' | |
def get_user_id(user_name) | |
# create_xml ("username_exists", user_name) | |
end | |
def create_blog_post(post_title, post_content, user_id) | |
var data = { | |
"post_title" => post_title, | |
"post_content" => post_content, | |
"post_status" => "publish", | |
"post_author" = user_id | |
} | |
return create_xml("wp_insert_post", data) | |
end | |
# data can either be a hash or a single value | |
def create_xml(method_name, data) | |
xml = Builder::XmlMarkup.new(:target => $stdout, :indent => 1) | |
xml.instruct! | |
xml.methodCall { | |
xml.methodName "extapi.callWpMethod" | |
xml.params { | |
xml.param { | |
xml.value { | |
xml.string "rpc-admin" | |
} | |
} | |
xml.param { | |
xml.value { | |
xml.string "password" | |
} | |
} | |
xml.param { | |
xml.value { | |
xml.string method_name | |
} | |
} | |
xml.param { | |
if (data.is_a? Hash) { | |
xml.value { | |
xml.array { | |
xml.data { | |
xml.value { | |
xml.struct { | |
data.each do |key, value| { | |
xml.member { | |
xml.name key | |
xml.value { | |
xml.string value | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
else { | |
xml.value data | |
} | |
} | |
} | |
} | |
return xml | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment