Browse Source

WebAPI: added version specific method endpoints

pull/1/merge
Rossen Georgiev 10 years ago
parent
commit
1c9235c1e9
  1. 9
      README.rst
  2. 2
      steam/__init__.py
  3. 20
      steam/webapi.py

9
README.rst

@ -20,20 +20,25 @@ What interfaces are availability depends on the ``key``.
>>> api.call('ISteamUser.ResolveVanityURL', vanityurl="valve", url_type=2) >>> api.call('ISteamUser.ResolveVanityURL', vanityurl="valve", url_type=2)
{u'response': {u'steamid': u'103582791429521412', u'success': 1}} {u'response': {u'steamid': u'103582791429521412', u'success': 1}}
# call a specific version of the method
>>> api.ISteamUser.ResolveVanityURL_v1(vanityurl="valve", url_type=2)
>>> api.call('ISteamUser.ResolveVanityURL_v1', vanityurl="valve", url_type=2)
It's not necessary to provide the key when calling any interface method. It's not necessary to provide the key when calling any interface method.
``key``, ``format``, ``raw`` parameters can be specified on ``WebAPI`` to affect ``key``, ``format``, ``raw`` parameters can be specified on ``WebAPI`` to affect
all method calls, or when calling a specific method. all method calls, or when calling a specific method.
Some methods have parameters which need to be a ``list``. Some methods have parameters which need to be a ``list``.
Trying to call nonexistent method will raise an ``AttributeError``.
Supported formats by web api are: ``json`` (default), ``vdf``, ``xml`` Supported formats by web api are: ``json`` (default), ``vdf``, ``xml``
The response will be deserialized using the appropriet module unless ``raw`` is The response will be deserialized using the appropriate module unless ``raw`` is
``True``. ``True``.
.. code:: python .. code:: python
>>> print api.ISteamUser.ResolveVanityURL.doc() # method doc >>> print api.ISteamUser.ResolveVanityURL.doc() # method doc
""" """
ResolveVanityURL (version: 1) ResolveVanityURL (v0001)
Parameters: Parameters:
key string required key string required

2
steam/__init__.py

@ -1,4 +1,4 @@
__version__ = "0.3" __version__ = "0.4"
__author__ = "Rossen Georgiev" __author__ = "Rossen Georgiev"
from .steamid import SteamID from .steamid import SteamID

20
steam/webapi.py

@ -139,7 +139,14 @@ class WebAPIInterface(object):
for method in interface_dict['methods']: for method in interface_dict['methods']:
obj = WebAPIMethod(method, parent=self) obj = WebAPIMethod(method, parent=self)
self.methods.append(obj) self.methods.append(obj)
setattr(self, obj.name, obj)
# map the method name as attribute including version
setattr(self, "%s_v%d" % (obj.name, obj.version), obj)
# without version, but th refernce of latest version
current_obj = getattr(self, obj.name, None)
if current_obj is None or current_obj.version < obj.version:
setattr(self, obj.name, obj)
def __repr__(self): def __repr__(self):
return "<%s %s with %s methods>" % ( return "<%s %s with %s methods>" % (
@ -182,10 +189,13 @@ class WebAPIMethod(object):
self._dict['parameters'][param['name']] = param self._dict['parameters'][param['name']] = param
def __repr__(self): def __repr__(self):
return "<%s %s for %s>" % ( return "<%s %s>" % (
self.__class__.__name__, self.__class__.__name__,
repr(self.name), repr("%s.%s_v%d" % (
repr(self._parent.name), self._parent.name,
self.name,
self.version,
)),
) )
def __call__(self, **kwargs): def __call__(self, **kwargs):
@ -260,7 +270,7 @@ class WebAPIMethod(object):
return self._parent.https return self._parent.https
def doc(self): def doc(self):
doc = "%(name)s (version: %(version)s)\n" % self._dict doc = "%(name)s (v%(version)04d)\n" % self._dict
if 'description' in self._dict: if 'description' in self._dict:
doc += "\n %(description)s\n" % self._dict doc += "\n %(description)s\n" % self._dict

Loading…
Cancel
Save