@@ -223,8 +223,8 @@ def follow(self, login):
223
223
"""
224
224
resp = False
225
225
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 )
228
228
return resp
229
229
230
230
def get_key (self , id_num ):
@@ -587,11 +587,11 @@ def search_issues(self, owner, repo, state, keyword):
587
587
:type keyword: str
588
588
:returns: list of :class:`LegacyIssue <github3.legacy.LegacyIssue>`\ s
589
589
"""
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 )
593
593
issues = json .get ('issues' , [])
594
- return [LegacyIssue (l , self . _session ) for l in issues ]
594
+ return [LegacyIssue (l , self ) for l in issues ]
595
595
596
596
def search_repos (self , keyword , ** params ):
597
597
"""Search all repositories by keyword.
@@ -602,10 +602,10 @@ def search_repos(self, keyword, **params):
602
602
:type params: dict
603
603
:returns: list of :class:`LegacyRepo <github3.legacy.LegacyRepo>`\ s
604
604
"""
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 )
607
607
repos = json .get ('repositories' , [])
608
- return [LegacyRepo (r , self . _session ) for r in repos ]
608
+ return [LegacyRepo (r , self ) for r in repos ]
609
609
610
610
def search_users (self , keyword ):
611
611
"""Search all users by keyword.
@@ -615,9 +615,9 @@ def search_users(self, keyword):
615
615
:returns: list of :class:`LegacyUser <github3.legacy.LegacyUser>`\ s
616
616
"""
617
617
url = self ._github_url + '/legacy/user/search/{0}' .format (keyword )
618
- json = self ._get (url )
618
+ json = self ._json ( self . _get (url ) )
619
619
users = json .get ('users' , [])
620
- return [LegacyUser (u , self . _session ) for u in users ]
620
+ return [LegacyUser (u , self ) for u in users ]
621
621
622
622
def search_email (self , email ):
623
623
"""Search users by email.
@@ -626,10 +626,10 @@ def search_email(self, email):
626
626
:type keyword: str
627
627
:returns: :class:`LegacyUser <github3.legacy.LegacyUser>`
628
628
"""
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 ) )
631
631
u = json .get ('user' , {})
632
- return LegacyUser (u , self . _session ) if u else None
632
+ return LegacyUser (u , self ) if u else None
633
633
634
634
def unfollow (self , login ):
635
635
"""Make the authenticated user stop following login
@@ -640,9 +640,8 @@ def unfollow(self, login):
640
640
"""
641
641
resp = False
642
642
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 )
646
645
return resp
647
646
648
647
def update_user (self , name = None , email = None , blog = None ,
@@ -669,8 +668,8 @@ def update_user(self, name=None, email=None, blog=None,
669
668
"""
670
669
user = self .user ()
671
670
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 )
674
673
return False
675
674
676
675
def user (self , login = None ):
@@ -682,14 +681,12 @@ def user(self, login=None):
682
681
:type login: str
683
682
:returns: :class:`User <github3.user.User>`
684
683
"""
685
- url = [self ._github_url ]
686
684
if login :
687
- url . extend ([ 'users' , login ] )
685
+ url = self . _build_url ( 'users' , login )
688
686
else :
689
- url .append ('user' )
690
- url = '/' .join (url )
687
+ url = self ._build_url ('user' )
691
688
692
- json = self ._get (url )
689
+ json = self ._json ( self . _get (url ), 200 )
693
690
return User (json , self ._session ) if json else None
694
691
695
692
def watch (self , login , repo ):
@@ -703,8 +700,8 @@ def watch(self, login, repo):
703
700
"""
704
701
resp = False
705
702
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 )
708
705
return resp
709
706
710
707
def unwatch (self , login , repo ):
@@ -718,8 +715,8 @@ def unwatch(self, login, repo):
718
715
"""
719
716
resp = False
720
717
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 )
723
720
return resp
724
721
725
722
@@ -738,8 +735,8 @@ def _update_(self, auth):
738
735
self ._note_url = auth .get ('note_url' , '' )
739
736
self ._note = auth .get ('note' , '' )
740
737
self ._scopes = auth .get ('scopes' , [])
741
- self ._api = auth .get ('url' , '' )
742
738
self ._id = auth .get ('id' , 0 )
739
+ self ._api = self ._build_url ('authorizations' , str (self ._id ))
743
740
self ._created = None
744
741
if auth .get ('created_at' ):
745
742
self ._created = self ._strptime (auth .get ('created_at' ))
@@ -759,7 +756,7 @@ def created_at(self):
759
756
760
757
def delete (self ):
761
758
"""delete this authorization"""
762
- return self ._delete (self ._api )
759
+ return self ._boolean ( self . _delete (self ._api ), 204 , 404 )
763
760
764
761
@property
765
762
def id (self ):
@@ -804,20 +801,23 @@ def update(self, scopes=[], add_scopes=[], rm_scopes=[], note='',
804
801
"""
805
802
success = False
806
803
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 )
808
806
self ._update_ (json )
809
807
success = True
810
808
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 )
812
811
self ._update_ (json )
813
812
success = True
814
813
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 )
816
816
self ._update_ (json )
817
817
success = True
818
818
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 )
821
821
self ._update_ (json )
822
822
success = True
823
823
return success
0 commit comments