Class: WikidotAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wikidot_api/client.rb

Overview

Wikidot API client class to handle XML-RPC api as described at www.wikidot.com/doc:api

Instance Method Summary collapse

Constructor Details

#initialize(app, key, opts = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
# File 'lib/wikidot_api/client.rb', line 6

def initialize app, key, opts={}
  @app, @key = app, key
  @host = opts[:host] || "www.wikidot.com"
  @proto = opts[:proto] || "https"
  @port = opts[:port] || false
  @query_options = opts[:query_options] || false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



30
31
32
# File 'lib/wikidot_api/client.rb', line 30

def method_missing method
  proxy method.to_s
end

Instance Method Details

#call(method, *args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wikidot_api/client.rb', line 14

def call method, *args
  try_count = 0
  begin
    server.call_async method, *args
  rescue IOError => e
    @server = nil
    try_count += 1
    raise if try_count == 3
    retry
  end
end

#proxy(prefix = nil, *args) ⇒ Object



26
27
28
# File 'lib/wikidot_api/client.rb', line 26

def proxy(prefix=nil, *args)
  XMLRPC::Client::Proxy.new(self, prefix, args, :call)
end