Remote client for Wikidot RPC API
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib
.gitignore
LICENSE
README.md
wikidot-api.gemspec

README.md

Wikidot API Client Library for Ruby

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.

Installation

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)

Usage

Before you start using the wikidot-api library, you need an API key. Please consult the original documentation on how to get one.

Connecting

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.

Calling remote methods

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.

Getting list of methods and method descriptions

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'

Example: Listing sites

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

Example: Fetching a page

page = wikidot.page.get "site" => "YOUR_SITE_NAME_HERE", "page" => "YOUR_PAGE_NAME_HERE"
puts page["title"]
puts page["source"]

Example: Creating a new page

args = {
    "title" => "My new page",
    "source" => "Hello world from the new page",
    "page" => "page-name",
    "site" => "site-name"
}

wikidot.page.save args

TODO

The library is a work-in-progress, as is the Wikidot API itself. Use at your own risk.

See also