mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
AuthenticatedUser.add_following and .remove_following
This commit is contained in:
@@ -44,5 +44,8 @@ dumpRepository( g.get_user( "nvie" ).get_repos()[ 0 ] )
|
||||
# u.edit( bio = u.bio + "(Edited by PyGithub)" )
|
||||
# print "Bio after:", u.bio
|
||||
|
||||
# g.get_user().remove_following( g.get_user( "Lyloa" ) )
|
||||
# g.get_user().add_following( g.get_user( "Lyloa" ) )
|
||||
|
||||
# o = g.get_organization( "BeaverSoftware" )
|
||||
# o.edit( location = "Paris, France" )
|
||||
|
||||
+2
-2
@@ -408,8 +408,8 @@
|
||||
/user/following/:user
|
||||
=====================
|
||||
- GET: `` (TODO)
|
||||
- PUT: `` (TODO)
|
||||
- DELETE: `` (TODO)
|
||||
- PUT: `AuthenticatedUser.add_following( user )`
|
||||
- DELETE: `AuthenticatedUser.remove_following( user )`
|
||||
|
||||
/user/keys
|
||||
==========
|
||||
|
||||
+15
-2
@@ -18,18 +18,31 @@ class Github:
|
||||
return self.__verb
|
||||
|
||||
def _dataRequest( self, verb, url, data = None ):
|
||||
return json.load( self.__rawRequest( verb, url, json.dumps( data ) ) )
|
||||
|
||||
def _statusRequest( self, verb, url, data = None ):
|
||||
try:
|
||||
print verb, url, data
|
||||
self.__rawRequest( verb, url, json.dumps( data ) )
|
||||
print "Got HTTP status 200"
|
||||
return 200
|
||||
except urllib2.HTTPError as e:
|
||||
print "Got HTTP status", e.code
|
||||
return e.code
|
||||
|
||||
def __rawRequest( self, verb, url, data ):
|
||||
assert( verb in [ "HEAD", "GET", "POST", "PATCH", "PUT", "DELETE" ] )
|
||||
|
||||
# print verb, url, data
|
||||
|
||||
req = Github._Request( verb, "https://api.github.com" + url, json.dumps( data ) )
|
||||
req = Github._Request( verb, "https://api.github.com" + url, data )
|
||||
b64_userpass = base64.b64encode( '%s:%s' % ( self.__login, self.__password ) )
|
||||
b64_userpass = b64_userpass.replace( '\n', '' )
|
||||
req.add_header(
|
||||
"Authorization", "Basic %s" % b64_userpass
|
||||
)
|
||||
|
||||
return json.load( urllib2.urlopen( req ) )
|
||||
return urllib2.urlopen( req )
|
||||
|
||||
def get_user( self, login = None ):
|
||||
if login is None:
|
||||
|
||||
@@ -33,7 +33,6 @@ class TestCaseWithGithubTestObject( unittest.TestCase ):
|
||||
|
||||
def expectDelete( self, url ):
|
||||
return self.g.expect._statusRequest( "DELETE", url )
|
||||
return self.g.expect._dataRequest( "DELETE", url )
|
||||
|
||||
class GithubObjectWithOnlySimpleScalarAttributes( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
|
||||
@@ -85,7 +85,7 @@ class ExtendedListAttribute:
|
||||
|
||||
def __call__( self, toBeAdded ):
|
||||
assert( isinstance( toBeAdded, self.__type ) )
|
||||
self.__obj._github._dataRequest( "PUT", self.__obj._baseUrl + "/" + self.__attributeName + "/" + toBeAdded._identity )
|
||||
self.__obj._github._statusRequest( "PUT", self.__obj._baseUrl + "/" + self.__attributeName + "/" + toBeAdded._identity )
|
||||
|
||||
class AddDefinition:
|
||||
def __init__( self, attributeName, addName, type ):
|
||||
|
||||
@@ -3,6 +3,7 @@ from GithubObject import *
|
||||
AuthenticatedUser = GithubObject(
|
||||
"AuthenticatedUser",
|
||||
BaseUrl( lambda obj: "/user" ),
|
||||
Identity( lambda obj: obj.login ),
|
||||
SimpleScalarAttributes(
|
||||
"login", "id", "avatar_url", "gravatar_id", "url", "name", "company",
|
||||
"blog", "location", "email", "hireable", "bio", "public_repos",
|
||||
@@ -16,6 +17,7 @@ AuthenticatedUser = GithubObject(
|
||||
NamedUser = GithubObject(
|
||||
"NamedUser",
|
||||
BaseUrl( lambda obj: "/users/" + obj.login ),
|
||||
Identity( lambda obj: obj.login ),
|
||||
SimpleScalarAttributes(
|
||||
"login", "id", "avatar_url", "gravatar_id", "url", "name", "company",
|
||||
"blog", "location", "email", "hireable", "bio", "public_repos",
|
||||
@@ -29,12 +31,13 @@ NamedUser = GithubObject(
|
||||
AuthenticatedUser._addAttributePolicy( ExtendedListAttribute( "followers", NamedUser ) )
|
||||
NamedUser._addAttributePolicy( ExtendedListAttribute( "followers", NamedUser ) )
|
||||
|
||||
AuthenticatedUser._addAttributePolicy( ExtendedListAttribute( "following", NamedUser ) )
|
||||
AuthenticatedUser._addAttributePolicy( ExtendedListAttribute( "following", NamedUser, True, True ) )
|
||||
NamedUser._addAttributePolicy( ExtendedListAttribute( "following", NamedUser ) )
|
||||
|
||||
Organization = GithubObject(
|
||||
"Organization",
|
||||
BaseUrl( lambda obj: "/orgs/" + obj.login ),
|
||||
Identity( lambda obj: obj.login ),
|
||||
SimpleScalarAttributes(
|
||||
"login", "id", "url", "avatar_url", "name", "company", "blog",
|
||||
"location", "email", "public_repos", "public_gists", "followers",
|
||||
@@ -54,6 +57,7 @@ NamedUser._addAttributePolicy( ExtendedListAttribute( "orgs", Organization ) )
|
||||
Repository = GithubObject(
|
||||
"Repository",
|
||||
BaseUrl( lambda obj: "/repos/" + obj.owner.login + "/" + obj.name ),
|
||||
Identity( lambda obj: obj.owner.login + "/" + obj.name ),
|
||||
SimpleScalarAttributes(
|
||||
"url", "html_url", "clone_url", "git_url", "ssh_url", "svn_url",
|
||||
"name", "description", "homepage", "language", "private",
|
||||
|
||||
Reference in New Issue
Block a user