mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Added a method for getting a user by their id (#1691)
* Added a method for getting a user by their id * Added get_user_by_id to MainClass stubs Fixes #1615
This commit is contained in:
@@ -275,6 +275,20 @@ class Github(object):
|
||||
self.__requester, headers, data, completed=True
|
||||
)
|
||||
|
||||
def get_user_by_id(self, user_id):
|
||||
"""
|
||||
:calls: `GET /user/:id <http://developer.github.com/v3/users>`_
|
||||
:param user_id: int
|
||||
:rtype: :class:`github.NamedUser.NamedUser`
|
||||
"""
|
||||
assert isinstance(user_id, int), user_id
|
||||
headers, data = self.__requester.requestJsonAndCheck(
|
||||
"GET", "/user/" + str(user_id)
|
||||
)
|
||||
return github.NamedUser.NamedUser(
|
||||
self.__requester, headers, data, completed=True
|
||||
)
|
||||
|
||||
def get_users(self, since=github.GithubObject.NotSet):
|
||||
"""
|
||||
:calls: `GET /users <http://developer.github.com/v3/users>`_
|
||||
|
||||
@@ -83,6 +83,7 @@ class Github:
|
||||
def get_user(self, login: _NotSetType = ...) -> AuthenticatedUser: ...
|
||||
@overload
|
||||
def get_user(self, login: str) -> NamedUser: ...
|
||||
def get_user_by_id(self, user_id: int) -> NamedUser: ...
|
||||
def get_users(
|
||||
self, since: Union[int, _NotSetType] = ...
|
||||
) -> PaginatedList[NamedUser]: ...
|
||||
|
||||
@@ -320,6 +320,9 @@ class Github(Framework.TestCase):
|
||||
def testStringOfNotSet(self):
|
||||
self.assertEqual(str(github.GithubObject.NotSet), "NotSet")
|
||||
|
||||
def testGetUserById(self):
|
||||
self.assertEqual(self.g.get_user_by_id(583231).login, "octocat")
|
||||
|
||||
def testGetUsers(self):
|
||||
self.assertListKeyBegin(
|
||||
self.g.get_users(),
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
https
|
||||
GET
|
||||
api.github.com
|
||||
None
|
||||
/user/583231
|
||||
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
|
||||
None
|
||||
200
|
||||
[('Date', 'Sat, 12 Sep 2020 12:26:09 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('Cache-Control', 'public, max-age=60, s-maxage=60'), ('Vary', 'Accept, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('ETag', 'W/"2409e6c518ebe03ecde9243734f63f93"'), ('Last-Modified', 'Sun, 23 Aug 2020 14:28:27 GMT'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '60'), ('X-RateLimit-Remaining', '59'), ('X-RateLimit-Reset', '1599917169'), ('X-RateLimit-Used', '1'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', 'C442:11459:3E06E4D:4A2F023:5F5CBE61')]
|
||||
{"login":"octocat","id":583231,"node_id":"MDQ6VXNlcjU4MzIzMQ==","avatar_url":"https://avatars3.githubusercontent.com/u/583231?v=4","gravatar_id":"","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","site_admin":false,"name":"The Octocat","company":"@github","blog":"https://github.blog","location":"San Francisco","email":null,"hireable":null,"bio":null,"twitter_username":null,"public_repos":8,"public_gists":8,"followers":3222,"following":9,"created_at":"2011-01-25T18:44:36Z","updated_at":"2020-08-23T14:28:27Z"}
|
||||
|
||||
Reference in New Issue
Block a user