Wikidot-api is a simple client library for Wikidot Remote API. The library provides a simple wrapper around Ruby's XMLRPC library and handles authentication, reconnection and provides an easy way to access remote methods.
Wikidot-api is available as a gem. Installation is as simple as
gem install wikidot-api
(or run with sudo if your ruby installation requires it, i.e. sudo gem install wikidot-api)
Before you start using the wikidot-api library, you need an API key. Please consult the original documentation on how to get one.
require "rubygems"
require "wikidot_api"
api_key = "YOUR_API_KEY_HERE"
wikidot = WikidotAPI::Client.new "wikidot-api", api_key
First argument to the #new method is name of the application using the API. E.g. if you are creating an application called "Best Wikidot API Client", please use its name in the constructor.
At this point the wikidot object should contain all methods described in the API documentation. The WikidotAPI::Client implements method_missing method so that every (non-defined) method you call is checked agains remote service. This way the library does not need to be updated if RPC methods change, but still provides convenient solution to query the remote service.
Using the RPC methods you can get list of implemented methods and their descriptions.
puts wikidot.system.listMethods
at this moment this prints: system.listMethods system.methodHelp system.methodSignature system.multicall site.pages site.categories page.get page.files page.save user.valid user.sites
To print help about any particular method, try this:
puts wikidot.system.methodHelp 'page.save'
The example below uses the remote method user.sites that takes one parameter (user) and returns a list of sites that this user owns. The method can be called directly on the wikidot object.
sites = wikidot.user.sites "user" => "YOUR_USER_NAME_HERE"
sites.each do |site|
puts "#{site["title"]}, http://#{site["name"]}.wikidot.com"
end
page = wikidot.page.get "site" => "YOUR_SITE_NAME_HERE", "page" => "YOUR_PAGE_NAME_HERE"
puts page["title"]
puts page["source"]
args = {
"title" => "My new page",
"source" => "Hello world from the new page",
"page" => "page-name",
"site" => "site-name"
}
wikidot.page.save args
The library is a work-in-progress, as is the Wikidot API itself. Use at your own risk.
- Wikidot.com at http://www.wikidot.com
- API documentation at http://www.wikidot.com/doc:api
- list of available methods at http://www.wikidot.com/doc:api-methods