From 1f779f832eb9ae20a5aed8e3d86a0d820b2a08e2 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Mon, 1 Jul 2013 23:04:27 +0300 Subject: [PATCH] Refactor unnecessary parameter passing from methods within class --- diaspy/people.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/diaspy/people.py b/diaspy/people.py index 2235125..8107ab2 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -40,22 +40,20 @@ class User(): def _do_fetch(self, fetch): if fetch == 'posts': - if self['handle'] and self['guid']: self.fetchguid(self['guid']) - elif self['guid'] and not self['handle']: self.fetchguid(self['guid']) - elif self['handle'] and not self['guid']: self.fetchhandle(self['handle']) + if self['handle'] and self['guid']: self.fetchguid() + elif self['guid'] and not self['handle']: self.fetchguid() + elif self['handle'] and not self['guid']: self.fetchhandle() elif fetch == 'data' and len(self['handle']): - self.fetchprofile(self['handle']) + self.fetchprofile() - def _sephandle(self, handle): + def _sephandle(self): """Separate D* handle into pod pod and user. - :param handle: diaspora id: user@pod.example.com - :type handle: str :returns: two-tuple (pod, user) """ - if re.match('^[a-zA-Z]+[a-zA-Z0-9_-]*@[a-z0-9.]+\.[a-z]+$', handle) is None: - raise Exception('invalid handle: {0}'.format(handle)) - handle = handle.split('@') + if re.match('^[a-zA-Z]+[a-zA-Z0-9_-]*@[a-z0-9.]+\.[a-z]+$', self['handle']) is None: + raise Exception('invalid handle: {0}'.format(self['handle'])) + handle = self['handle'].split('@') pod, user = handle[1], handle[0] return (pod, user) @@ -84,26 +82,25 @@ class User(): ('avatar', 'image_urls'), ] self.data = self._finalize_data(request[0]['author'], names) - self.stream = Outer(self._connection, location='people/{0}.json'.format(self.data['guid'])) + self.stream = Outer(self._connection, location='people/{0}.json'.format(self['guid'])) - def fetchhandle(self, diaspora_id, protocol='https'): + def fetchhandle(self, protocol='https'): """Fetch user data and posts using Diaspora handle. """ - pod, user = self._sephandle(diaspora_id) + pod, user = self._sephandle() request = self._connection.session.get('{0}://{1}/u/{2}.json'.format(protocol, pod, user)) self._postproc(request) - def fetchguid(self, guid): + def fetchguid(self): """Fetch user data and posts using guid. """ - request = self._connection.get('people/{0}.json'.format(guid)) + request = self._connection.get('people/{0}.json'.format(self['guid'])) self._postproc(request) - def fetchprofile(self, diaspora_id, protocol='https'): + def fetchprofile(self, protocol='https'): """Fetch user data using Diaspora handle. """ - pod, user = self._sephandle(diaspora_id) - request = self._connection.get('people.json?q={0}'.format(diaspora_id)) + request = self._connection.get('people.json?q={0}'.format(self['handle'])) if request.status_code != 200: raise Exception('wrong error code: {0}'.format(request.status_code)) else: -- 2.25.1