mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 11:21:16 +00:00
Adjust to Github API changes regarding emails (#1890)
Handle AuthenticatedUser.get_emails() correctly with the GitHub API changes. Fixes #1852
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
################################################################################
|
||||
|
||||
import datetime
|
||||
from collections import namedtuple
|
||||
|
||||
import github.Authorization
|
||||
import github.Event
|
||||
@@ -373,7 +374,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
|
||||
:rtype: None
|
||||
"""
|
||||
assert all(isinstance(element, str) for element in emails), emails
|
||||
post_parameters = emails
|
||||
post_parameters = {"emails": emails}
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"POST", "/user/emails", input=post_parameters
|
||||
)
|
||||
@@ -763,10 +764,11 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
|
||||
def get_emails(self):
|
||||
"""
|
||||
:calls: `GET /user/emails <http://developer.github.com/v3/users/emails>`_
|
||||
:rtype: list of string
|
||||
:rtype: list of namedtuples with members email, primary, verified and visibility
|
||||
"""
|
||||
headers, data = self._requester.requestJsonAndCheck("GET", "/user/emails")
|
||||
return data
|
||||
itemdata = namedtuple("EmailData", data[0].keys())
|
||||
return [itemdata._make(item.values()) for item in data]
|
||||
|
||||
def get_events(self):
|
||||
"""
|
||||
@@ -1189,7 +1191,7 @@ class AuthenticatedUser(github.GithubObject.CompletableGithubObject):
|
||||
:rtype: None
|
||||
"""
|
||||
assert all(isinstance(element, str) for element in emails), emails
|
||||
post_parameters = emails
|
||||
post_parameters = {"emails": emails}
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"DELETE", "/user/emails", input=post_parameters
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
from typing import Any, Dict, List, Optional, Union, NamedTuple
|
||||
|
||||
from github.Authorization import Authorization
|
||||
from github.Event import Event
|
||||
@@ -20,6 +20,12 @@ from github.Repository import Repository
|
||||
from github.Team import Team
|
||||
from github.UserKey import UserKey
|
||||
|
||||
class EmailData(NamedTuple):
|
||||
email: str
|
||||
primary: bool
|
||||
verified: bool
|
||||
visibility: str
|
||||
|
||||
class AuthenticatedUser(CompletableGithubObject):
|
||||
def __repr__(self) -> str: ...
|
||||
def _initAttributes(self) -> None: ...
|
||||
@@ -108,7 +114,7 @@ class AuthenticatedUser(CompletableGithubObject):
|
||||
def following_url(self) -> str: ...
|
||||
def get_authorization(self, id: int) -> Authorization: ...
|
||||
def get_authorizations(self) -> PaginatedList[Authorization]: ...
|
||||
def get_emails(self) -> List[str]: ...
|
||||
def get_emails(self) -> List[EmailData]: ...
|
||||
def get_events(self) -> PaginatedList[Event]: ...
|
||||
def get_followers(self) -> PaginatedList[NamedUser]: ...
|
||||
def get_following(self) -> PaginatedList[NamedUser]: ...
|
||||
|
||||
Reference in New Issue
Block a user