8000 Well that's finished. · jsullivanlive/github3.py@38efe43 · GitHub
[go: up one dir, main page]

Skip to content

Commit 38efe43

Browse files
committed
Well that's finished.
1 parent 49318a9 commit 38efe43

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

github3/github.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ def follow(self, login):
223223
"""
224224
resp = False
225225
if login:
226-
url = self._build_url('user', 'following', 'login')
227-
resp = self._boolean(self._put(url), 204, 0)
226+
url = self._build_url('user', 'following', login)
227+
resp = self._boolean(self._put(url), 204, 404)
228228
return resp
229229

230230
def get_key(self, id_num):
@@ -587,11 +587,11 @@ def search_issues(self, owner, repo, state, keyword):
587587
:type keyword: str
588588
:returns: list of :class:`LegacyIssue <github3.legacy.LegacyIssue>`\ s
589589
"""
590-
url = '/'.join([self._github_url, 'legacy/issues/search', owner, repo,
591-
state, keyword])
592-
json = self._get(url)
590+
url = self._build_url('legacy', 'issues', 'search', owner, repo,
8000 591+
state, keyword)
592+
json = self._json(self._get(url), 200)
593593
issues = json.get('issues', [])
594-
return [LegacyIssue(l, self._session) for l in issues]
594+
return [LegacyIssue(l, self) for l in issues]
595595

596596
def search_repos(self, keyword, **params):
597597
"""Search all repositories by keyword.
@@ -602,10 +602,10 @@ def search_repos(self, keyword, **params):
602602
:type params: dict
603603
:returns: list of :class:`LegacyRepo <github3.legacy.LegacyRepo>`\ s
604604
"""
605-
url = self._github_url + '/legacy/repos/search/{0}'.format(keyword)
606-
json = self._get(url, params=params)
605+
url = self._build_url('legacy', 'repos', 'search', keyword)
606+
json = self._json(self._get(url, params=params), 200)
607607
repos = json.get('repositories', [])
608-
return [LegacyRepo(r, self._session) for r in repos]
608+
return [LegacyRepo(r, self) for r in repos]
609609

610610
def search_users(self, keyword):
611611
"""Search all users by keyword.
@@ -615,9 +615,9 @@ def search_users(self, keyword):
615615
:returns: list of :class:`LegacyUser <github3.legacy.LegacyUser>`\ s
616616
"""
617617
url = self._github_url + '/legacy/user/search/{0}'.format(keyword)
618-
json = self._get(url)
618+
json = self._json(self._get(url))
619619
users = json.get('users', [])
620-
return [LegacyUser(u, self._session) for u in users]
620+
return [LegacyUser(u, self) for u in users]
621621

622622
def search_email(self, email):
623623
"""Search users by email.
@@ -626,10 +626,10 @@ def search_email(self, email):
626626
:type keyword: str
627627
:returns: :class:`LegacyUser <github3.legacy.LegacyUser>`
628628
"""
629-
url = self._github_url + '/legacy/user/email/{0}'.format(email)
630-
json = self._get(url)
629+
url = self._build_url('legacy', 'user', 'email', email)
630+
json = self._json(self._get(url))
631631
u = json.get('user', {})
632-
return LegacyUser(u, self._session) if u else None
632+
return LegacyUser(u, self) if u else None
633633

634634
def unfollow(self, login):
635635
"""Make the authenticated user stop following login
@@ -640,9 +640,8 @@ def unfollow(self, login):
640640
"""
641641
resp = False
642642
if login:
643-
url = '{0}/user/following/{1}'.format(self._github_url,
644-
login)
645-
resp = self._delete(url)
643+
url = self._build_url('user', 'following', login)
644+
resp = self._boolean(self._delete(url), 204, 404)
646645
return resp
647646

648647
def update_user(self, name=None, email=None, blog=None,
@@ -669,8 +668,8 @@ def update_user(self, name=None, email=None, blog=None,
669668
"""
670669
user = self.user()
671670
if user:
672-
return user.update(name, email, blog, company, location,
673-
hireable, bio)
671+
return user.update(name, email, blog, company, location, hireable,
672+
bio)
674673
return False
675674

676675
def user(self, login=None):
@@ -682,14 +681,12 @@ def user(self, login=None):
682681
:type login: str
683682
:returns: :class:`User <github3.user.User>`
684683
"""
685-
url = [self._github_url]
686684
if login:
687-
url.extend(['users', login])
685+
url = self._build_url('users', login)
688686
else:
689-
url.append('user')
690-
url = '/'.join(url)
687+
url = self._build_url('user')
691688

692-
json = self._get(url)
689+
json = self._json(self._get(url), 200)
693690
return User(json, self._session) if json else None
694691

695692
def watch(self, login, repo):
@@ -703,8 +700,8 @@ def watch(self, login, repo):
703700
"""
704701
resp = False
705702
if login and repo:
706-
url = self._github_url + '/user/watched/' + login + '/' + repo
707-
resp = self._put(url)
703+
url = self._build_url('user', 'watched', login, repo)
704+
resp = self._boolean(self._put(url), 204, 404)
708705
return resp
709706

710707
def unwatch(self, login, repo):
@@ -718,8 +715,8 @@ def unwatch(self, login, repo):
718715
"""
719716
resp = False
720717
if login and repo:
721-
url = self._github_url + '/user/watched/' + login + '/' + repo
722-
resp = self._delete(url)
718+
url = self._build_url('user', 'watched', login, repo)
719+
resp = self._boolean(self._delete(url), 204, 404)
723720
return resp
724721

725722

@@ -738,8 +735,8 @@ def _update_(self, auth):
738735
self._note_url = auth.get('note_url', '')
739736
self._note = auth.get('note', '')
740737
self._scopes = auth.get('scopes', [])
741-
self._api = auth.get('url', '')
742738
self._id = auth.get('id', 0)
739+
self._api = self._build_url('authorizations', str(self._id))
743740
self._created = None
744741
if auth.get('created_at'):
745742
self._created = self._strptime(auth.get('created_at'))
@@ -759,7 +756,7 @@ def created_at(self):
759756

760757
def delete(self):
761758
"""delete this authorization"""
762-
return self._delete(self._api)
759+
return self._boolean(self._delete(self._api), 204, 404)
763760

764761
@property
765762
def id(self):
@@ -804,20 +801,23 @@ def update(self, scopes=[], add_scopes=[], rm_scopes=[], note='',
804801
"""
805802
success = False
806803
if scopes:
807-
json = self._get(self._api, data={'scopes': scopes})
804+
d = dumps({'scopes': scopes})
805+
json = self._json(self._get(self._api, data=d), 200)
808806
self._update_(json)
809807
success = True
810808
if add_scopes:
811-
json = self._get(self._api, data={'add_scopes': add_scopes})
809+
d = dumps({'add_scopes': add_scopes})
810+
json = self._json(self._get(self._api, data=d), 200)
812811
self._update_(json)
813812
success = True
814813
if rm_scopes:
815-
json = self._get(self._api, data={'remove_scopes': rm_scopes})
814+
d = dumps({'remove_scopes': rm_scopes})
815+
json = self._json(self._get(self._api, data=d), 200)
816816
self._update_(json)
817817
success = True
818818
if note or note_url:
819-
json = self._get(self._api, data={'note': note,
820-
'note_url': note_url})
819+
d = dumps({'note': note, 'note_url': note_url})
820+
json = self._json(self._get(self._api, data=d), 200)
821821
self._update_(json)
822822
success = True
823823
return success

0 commit comments

Comments
 (0)
0