Created
August 10, 2011 22:38
-
-
Save TooTallNate/1138474 to your computer and use it in GitHub Desktop.
A little helper Class to send MetaWeblog API requests.
This file contains hidden or 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
var xmlrpc = require('xmlrpc') | |
, parse = require('url').parse | |
, slice = Array.prototype.slice | |
function MetaWeblog (url) { | |
var parsed = parse(url) | |
, client = xmlrpc.createClient({ | |
host: parsed.hostname | |
, path: parsed.pathname | |
, port: parsed.port || 80 | |
}); | |
this.client = client; | |
} | |
module.exports = MetaWeblog; | |
MetaWeblog.prototype._request = function request (method, args) { | |
var cb = args[args.length-1] | |
, params = slice.call(args, 0, -1) | |
this.client.methodCall(method, params, cb); | |
}; | |
[ 'metaWeblog.newPost' | |
, 'metaWeblog.editPost' | |
, 'metaWeblog.getPost' | |
, 'metaWeblog.getRecentPosts' | |
, 'metaWeblog.newMediaObject' | |
//, 'metaWeblog.getCategories' // collision with wp.getCategories | |
, 'wp.getUsersBlogs' | |
, 'wp.getTags' | |
, 'wp.getAuthors' | |
, 'wp.getOptions' | |
, 'wp.setOptions' | |
, 'wp.getPostStatusList' | |
, 'wp.getPostFormats' | |
, 'wp.getComments' | |
, 'wp.getCommentCount' | |
, 'wp.getComment' | |
, 'wp.deleteComment' | |
, 'wp.editComment' | |
, 'wp.newComment' | |
, 'wp.getCommentStatusList' | |
, 'wp.getPageStatusList' | |
, 'wp.getPageTemplates' | |
, 'wp.getPage' | |
, 'wp.getPages' | |
, 'wp.getPageList' | |
, 'wp.newPage' | |
, 'wp.deletePage' | |
, 'wp.editPage' | |
, 'wp.getCategories' | |
, 'wp.newCategory' | |
, 'wp.deleteCategory' | |
, 'wp.suggestCategories' | |
, 'wp.uploadFile' | |
, 'wp.getMediaLibrary' | |
, 'wp.getMediaItem' | |
].forEach(function (m) { | |
var n = m.split('.'); | |
n = n[n.length-1]; | |
MetaWeblog.prototype[n] = function () { | |
this._request(m, arguments); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment