Repository: PyGithub/PyGithub

Issue:
AuthenticatedUser.get_emails() returned data changed to list of dicts
According to the [provided type information](https://github.com/PyGithub/PyGithub/blob/master/github/AuthenticatedUser.pyi#L111) for `AuthenticatedUser`, the `get_emails` function returns a list of string.  However, in my experience with version 1.54.1 of this module, it appears to return a list of dictionaries that looks like the following:

```
[
  {
    "email": "xxx@yyy.com",
    "primary": false,
    "verified": true,
    "visibility": null
  },
  ...
]
```


Discussion:
It used too, and in fact our test suite still works based on that assumption. https://github.com/PyGithub/PyGithub/blob/master/tests/AuthenticatedUser.py#L101

So it looks like GitHub has changed the API out from under us.

Resolving patch:
diff --git a/github/AuthenticatedUser.py b/github/AuthenticatedUser.py
--- a/github/AuthenticatedUser.py
+++ b/github/AuthenticatedUser.py
@@ -40,6 +40,7 @@
 ################################################################################
 
 import datetime
+from collections import namedtuple
 
 import github.Authorization
 import github.Event
@@ -373,7 +374,7 @@ def add_to_emails(self, *emails):
         :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 @@ def get_authorizations(self):
     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 @@ def remove_from_emails(self, *emails):
         :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
         )


Test patch:
diff --git a/tests/AuthenticatedUser.py b/tests/AuthenticatedUser.py
--- a/tests/AuthenticatedUser.py
+++ b/tests/AuthenticatedUser.py
@@ -99,13 +99,17 @@ def testEditWithAllArguments(self):
         self.assertEqual(self.user.bio, "Bio edited by PyGithub")
 
     def testEmails(self):
+        emails = self.user.get_emails()
         self.assertEqual(
-            self.user.get_emails(),
+            [item.email for item in emails],
             ["vincent@vincent-jacques.net", "github.com@vincent-jacques.net"],
         )
+        self.assertTrue(emails[0].primary)
+        self.assertTrue(emails[0].verified)
+        self.assertEqual(emails[0].visibility, "private")
         self.user.add_to_emails("1@foobar.com", "2@foobar.com")
         self.assertEqual(
-            self.user.get_emails(),
+            [item.email for item in self.user.get_emails()],
             [
                 "vincent@vincent-jacques.net",
                 "1@foobar.com",
@@ -115,7 +119,7 @@ def testEmails(self):
         )
         self.user.remove_from_emails("1@foobar.com", "2@foobar.com")
         self.assertEqual(
-            self.user.get_emails(),
+            [item.email for item in self.user.get_emails()],
             ["vincent@vincent-jacques.net", "github.com@vincent-jacques.net"],
         )
 
diff --git a/tests/ReplayData/AuthenticatedUser.testEmails.txt b/tests/ReplayData/AuthenticatedUser.testEmails.txt
--- a/tests/ReplayData/AuthenticatedUser.testEmails.txt
+++ b/tests/ReplayData/AuthenticatedUser.testEmails.txt
@@ -7,7 +7,7 @@ None
 None
 200
 [('status', '200 OK'), ('x-ratelimit-remaining', '4934'), ('content-length', '64'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"ea6dacf29569317ccf460b4bb07075e5"'), ('date', 'Sun, 20 May 2012 12:41:39 GMT'), ('content-type', 'application/json; charset=utf-8')]
-["vincent@vincent-jacques.net","github.com@vincent-jacques.net"]
+[{"email": "vincent@vincent-jacques.net", "primary": true, "verified": true, "visibility": "private"}, {"email": "github.com@vincent-jacques.net", "primary": false, "verified": true, "visibility": null}]
 
 https
 POST
@@ -15,10 +15,10 @@ api.github.com
 None
 /user/emails
 {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
-["1@foobar.com", "2@foobar.com"]
+{"emails": ["1@foobar.com", "2@foobar.com"]}
 201
 [('status', '201 Created'), ('x-ratelimit-remaining', '4933'), ('content-length', '94'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"8efae10ea5e433b0d68201389058e4ee"'), ('date', 'Sun, 20 May 2012 12:41:40 GMT'), ('content-type', 'application/json; charset=utf-8')]
-["vincent@vincent-jacques.net","1@foobar.com","2@foobar.com","github.com@vincent-jacques.net"]
+[{"email": "vincent@vincent-jacques.net", "primary": true, "verified": true, "visibility": "private"}, {"email": "1@foobar.com", "primary": false, "verified": false, "visibility": null}, {"email": "2@foobar.com", "primary": false, "verified": false, "visibility": null}, {"email": "github.com@vincent-jacques.net", "primary": false, "verified": true, "visibility": null}]
 
 https
 GET
@@ -29,7 +29,7 @@ None
 None
 200
 [('status', '200 OK'), ('content-length', '94'), ('x-ratelimit-remaining', '4932'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"8efae10ea5e433b0d68201389058e4ee"'), ('date', 'Sun, 20 May 2012 12:41:41 GMT'), ('content-type', 'application/json; charset=utf-8')]
-["vincent@vincent-jacques.net","1@foobar.com","2@foobar.com","github.com@vincent-jacques.net"]
+[{"email": "vincent@vincent-jacques.net", "primary": true, "verified": true, "visibility": "private"}, {"email": "1@foobar.com", "primary": false, "verified": false, "visibility": null}, {"email": "2@foobar.com", "primary": false, "verified": false, "visibility": null}, {"email": "github.com@vincent-jacques.net", "primary": false, "verified": true, "visibility": null}]
 
 https
 DELETE
@@ -37,7 +37,7 @@ api.github.com
 None
 /user/emails
 {'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
-["1@foobar.com", "2@foobar.com"]
+{"emails": ["1@foobar.com", "2@foobar.com"]}
 204
 [('status', '204 No Content'), ('x-ratelimit-remaining', '4931'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"d41d8cd98f00b204e9800998ecf8427e"'), ('date', 'Sun, 20 May 2012 12:41:41 GMT')]
 
@@ -51,5 +51,5 @@ None
 None
 200
 [('status', '200 OK'), ('x-ratelimit-remaining', '4930'), ('content-length', '64'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"ea6dacf29569317ccf460b4bb07075e5"'), ('date', 'Sun, 20 May 2012 12:41:42 GMT'), ('content-type', 'application/json; charset=utf-8')]
-["vincent@vincent-jacques.net","github.com@vincent-jacques.net"]
+[{"email": "vincent@vincent-jacques.net", "primary": true, "verified": true, "visibility": "private"}, {"email": "github.com@vincent-jacques.net", "primary": false, "verified": true, "visibility": null}]