Skip to content

Instantly share code, notes, and snippets.

@sfentress
Created June 27, 2011 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfentress/1049246 to your computer and use it in GitHub Desktop.
Save sfentress/1049246 to your computer and use it in GitHub Desktop.
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