Skip to content

Commit

Permalink
Only initialize the GitHubApi if we are about to use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcburke committed Jul 27, 2015
1 parent 27dff2b commit dac2502
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions github_users/github_users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ class GitHubUser(GitHubObject):
objects = models.Manager()
follow_relations = FollowManager()

def __init__(self, *args, **kwargs):
super(GitHubUser, self).__init__(*args, **kwargs)
self.api = GitHubUserApi()

def __unicode__(self):
return self.login

def _init_gh_api(self):
if not hasattr(self, 'api'):
self.api = GitHubUserApi()

def populate_from_github(self, save=True, force=False):
etag = False if force else self.e_tag
self._init_gh_api()
api_resp = self.api.get_user(self.login, etag)
now = datetime.datetime.now(tz=pytz.UTC)
if api_resp['status'] == requests.codes.ok:
Expand Down Expand Up @@ -123,6 +124,7 @@ def populate_followers(self, force=False):
return

etag = False if force else self.followers_etag
self._init_gh_api()
api_resp = self.api.get_user_followers(self.login, etag)
if api_resp['status'] == requests.codes.ok:
follower_data = api_resp['json']
Expand Down Expand Up @@ -153,6 +155,7 @@ def populate_following(self, force=False):
return

etag = False if force else self.following_etag
self._init_gh_api()
api_resp = self.api.get_user_following(self.login, etag)
if api_resp['status'] == requests.codes.ok:
following_data = api_resp['json']
Expand Down

0 comments on commit dac2502

Please sign in to comment.