First the code:
class Api():
def __init__(self, baseurl='http://localhost:8080/api'):
self.base_url = baseurl
def _makerequest(self, arguments):
data = urllib.urlencode(arguments)
req = urllib2.Request(self.base_url, data)
response = urllib2.urlopen(req)
return response
def getId(self, **kwargs):
arguments = kwargs
arguments['Type'] = 'getId'
return self._makerequest(arguments)
def getKey(self, **kwargs):
arguments = kwargs
arguments['Type'] = 'getKey'
return self._makerequest(arguments)
As you can see every function eventually calls _makerequest(). I've written it this way to have different functions (and code completion suggests) them but to minimize code reuse.
What I'm wondering is if one could somehow only have one function but call that function with different names. For example I would call getId() and getKey() but it would trigger the same function inside the class.
Any suggestions how to simplify this ?
_makerequest().