Skip to content

Commit

Permalink
[#69] Add docstring for Site.api()
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Nov 7, 2014
1 parent 40b1309 commit f32efc1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion mwclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,23 @@ def __repr__(self):
return "<Site object '%s%s'>" % (self.host, self.path)

def api(self, action, *args, **kwargs):
""" An API call. Handles errors and returns dict object. """
"""
Perform a generic API call and handle errors. All arguments will be passed on.
Example:
To get coordinates from the GeoData MediaWiki extension at English Wikipedia:
>>> site = Site('en.wikipedia.org')
>>> result = site.api('query', prop='coordinates', titles='Oslo|Copenhagen')
>>> for page in result['query']['pages'].values():
... if 'coordinates' in page:
... print page['title'], page['coordinates'][0]['lat'], page['coordinates'][0]['lon']
Oslo 59.95 10.75
Copenhagen 55.6761 12.5683
Returns:
The raw response from the API call, as a dictionary.
"""
kwargs.update(args)
if action == 'query':
if 'meta' in kwargs:
Expand Down

0 comments on commit f32efc1

Please sign in to comment.