wikidot-api 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.md +77 -0
- data/lib/wikidot_api.rb +11 -0
- data/lib/wikidot_api/client.rb +42 -0
- data/lib/wikidot_api/version.rb +3 -0
- metadata +74 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Michał Frąckowiak
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
Wikidot API Client Library for Ruby
|
2
|
+
===================================
|
3
|
+
|
4
|
+
Wikidot-api is a simple client library for [Wikidot Remote API](http://www.wikidot.com/doc:api).
|
5
|
+
The library provides a simple wrapper around Ruby's [XMLRPC library](http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/xmlrpc/rdoc/index.html) and handles authentication, reconnection and provides an easy way to access remote methods.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
|
10
|
+
Wikidot-api is available as a gem. Installation is as simple as
|
11
|
+
|
12
|
+
gem install wikidot-api
|
13
|
+
|
14
|
+
(or run with <tt>sudo</tt> if your ruby installation requires it, i.e. <tt>sudo gem install wikidot-api</tt>)
|
15
|
+
|
16
|
+
Usage
|
17
|
+
-----
|
18
|
+
|
19
|
+
Before you start using the wikidot-api library, you need an API key. Please consult the original [documentation](http://www.wikidot.com/doc:api) on how to get one.
|
20
|
+
|
21
|
+
### Connecting
|
22
|
+
|
23
|
+
require "rubygems"
|
24
|
+
require "wikidot_api"
|
25
|
+
|
26
|
+
api_key = "YOUR_API_KEY_HERE"
|
27
|
+
user_name = "YOUR_USER_NAME_HERE"
|
28
|
+
|
29
|
+
wikidot = WikidotAPI::Client.new 'wikidot-api', api_key
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
### Calling remote methods
|
34
|
+
|
35
|
+
At this point the <tt>wikidot</tt> object should contain all methods described in the API documentation.
|
36
|
+
The <tt>WikidotAPI::Client</tt> implements <tt>method_missing</tt> method so that every (non-defined) method you call
|
37
|
+
is checked agains remote service. This way the library does not need to be updated if RPC methods change, but still provides
|
38
|
+
convenient solution to query the remote service.
|
39
|
+
|
40
|
+
#### Example: Listing sites
|
41
|
+
|
42
|
+
The example below uses the remote method <tt>user.sites</tt> that takes one parameter (<tt>user</tt>) and returns a list of sites that this user owns. The method can be called directly on the <tt>wikidot</tt> object.
|
43
|
+
|
44
|
+
sites = wikidot.user.sites 'user' => user_name
|
45
|
+
sites.each do |site|
|
46
|
+
puts "#{site["title"]}, http://#{site["name"]}.wikidot.com"
|
47
|
+
end
|
48
|
+
|
49
|
+
#### Example: Fetching a page
|
50
|
+
|
51
|
+
page = wikidot.page.get 'site' => site, 'page' => page
|
52
|
+
puts page['title']
|
53
|
+
puts page['source']
|
54
|
+
|
55
|
+
#### Example: Creating a new page
|
56
|
+
|
57
|
+
args = {
|
58
|
+
"title" => "My new page",
|
59
|
+
"source" => "Hello world from the new page",
|
60
|
+
"page" => "page-name",
|
61
|
+
"site" => "site-name"
|
62
|
+
}
|
63
|
+
|
64
|
+
wikidot.page.save args
|
65
|
+
|
66
|
+
TODO
|
67
|
+
----
|
68
|
+
|
69
|
+
The library is a work-in-progress, as is the Wikidot API itself. Use at your own risk.
|
70
|
+
|
71
|
+
|
72
|
+
See also
|
73
|
+
--------
|
74
|
+
|
75
|
+
- Wikidot.com at [http://www.wikidot.com](http://www.wikidot.com)
|
76
|
+
- API documentation at [http://www.wikidot.com/doc:api](http://www.wikidot.com/doc:api)
|
77
|
+
- list of available methods at [http://www.wikidot.com/doc:api-methods](http://www.wikidot.com/doc:api-methods)
|
data/lib/wikidot_api.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "xmlrpc/client"
|
3
|
+
|
4
|
+
# Enable NIL extension to handle <nil/> values
|
5
|
+
XMLRPC::Config::ENABLE_NIL_CREATE = true
|
6
|
+
XMLRPC::Config::ENABLE_NIL_PARSER = true
|
7
|
+
|
8
|
+
$: << File.dirname(__FILE__)
|
9
|
+
|
10
|
+
require "wikidot_api/version"
|
11
|
+
require "wikidot_api/client"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module WikidotAPI
|
2
|
+
|
3
|
+
# Wikidot API client class to handle XML-RPC api as described at
|
4
|
+
# http://www.wikidot.com/doc:api
|
5
|
+
class Client
|
6
|
+
def initialize app, key, opts={}
|
7
|
+
@app, @key = app, key
|
8
|
+
@domain = opts[:domain] || "www.wikidot.com"
|
9
|
+
@proto = opts[:proto] || "https"
|
10
|
+
end
|
11
|
+
|
12
|
+
def call method, *args
|
13
|
+
try_count = 0
|
14
|
+
begin
|
15
|
+
server.call method, *args
|
16
|
+
rescue EOFError => e
|
17
|
+
@server = nil
|
18
|
+
try_count += 1
|
19
|
+
raise if try_count == 3
|
20
|
+
retry
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def proxy(prefix=nil, *args)
|
25
|
+
XMLRPC::Client::Proxy.new(self, prefix, args, :call)
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing method
|
29
|
+
proxy method.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def server
|
33
|
+
@server ||= XMLRPC::Client.new2 endpoint_uri
|
34
|
+
end
|
35
|
+
|
36
|
+
def endpoint_uri
|
37
|
+
"#{@proto}://#{@app}:#{@key}@#{@domain}/xml-rpc-api.php"
|
38
|
+
end
|
39
|
+
|
40
|
+
private :server, :endpoint_uri
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wikidot-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Micha\xC5\x82 Fr\xC4\x85ckowiak"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-22 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: |
|
23
|
+
Simple Ruby client library for Wikidot RPC API
|
24
|
+
|
25
|
+
email: michalf@wikidot.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- LICENSE
|
32
|
+
- README.md
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- LICENSE
|
36
|
+
- lib/wikidot_api/client.rb
|
37
|
+
- lib/wikidot_api/version.rb
|
38
|
+
- lib/wikidot_api.rb
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/michalf/wikidot-api
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Simple Ruby client library for Wikidot RPC API
|
73
|
+
test_files: []
|
74
|
+
|