Rewrite/api.py
From Botwiki
Contents |
[edit] Proposed interface for api.py module
[edit] Error
class Error(pywikibot.Error)
- Throw this exception whenever the API returns an <error> or invalid response
- (Public) Attributes:
-
code: contents of the 'error' 'code' field in the API response- If API returns an unrecognized response, set 'code' to 'Unknown'
-
info: contents of the 'error' 'info' field in the API response -
other: dict containing any other fields found in the API response
-
[edit] Request
class Request(object)
- The base class for all API request types
- Constructor:
-
def __init__(self, site=None, format="json", **args)- site: a Site object; if absent, use default Site
- format: do we want to rely on simplejson or XML as the format used internally?
- args:
formatand all other keyword args are placed in a dict to be passed to the wiki
- (Public) Attributes:
- (Public) Methods:
-
def update(self, **args)- Update request's param dict from args
-
def submit(self)- Submit request to the wiki and use simplejson to turn the response into a dict
- Handle routine comm errors at this level
[edit] Query
class Query(Request)
- Since at least 75% of all API activity is going to use action=query, it seems to make sense to have a sub-class dedicated to this action that will have some methods that know about particular query types.
- Constructor:
-
def __init__(self, site=None, format="json", **args)- Same as the Request constructor, but add
{'action': 'query'}to the params dict.
- Same as the Request constructor, but add
- (Public) Attributes:
- (Public) Methods:
BlogMarks
del.icio.us
digg
Fark
Furl
Newsvine
reddit
Segnalo
Simpy
Slashdot
smarking
Spurl
Wists
