Browse Source

update Users.ListEmails to use v3 media type

This is a breaking change, but it appears that this method has been
broken for some time now and no one has complained yet, so I'm going to
assume no one is using it yet.

Notably, this is also the first (of many, I'm sure) bug I've discovered
while working on the new integration tests (#98).  Yay for better tests!
Will Norris 12 years ago
parent
commit
70f2a5f404
3 changed files with 34 additions and 18 deletions
  1. +11
    -7
      github/users_emails.go
  2. +11
    -7
      github/users_emails_test.go
  3. +12
    -4
      tests/integration/users_test.go

+ 11
- 7
github/users_emails.go View File

@ -6,9 +6,13 @@
package github
// UserEmail represents user's email address
type UserEmail string
type UserEmail struct {
Email *string `json:"email,omitempty"`
Primary *bool `json:"primary,omitempty"`
Verified *bool `json:"verified,omitempty"`
}
// ListEmails lists all authenticated user email addresses
// ListEmails lists all email addresses for the authenticated user.
//
// GitHub API docs: http://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
func (s *UsersService) ListEmails() ([]UserEmail, *Response, error) {
@ -27,17 +31,17 @@ func (s *UsersService) ListEmails() ([]UserEmail, *Response, error) {
return *emails, resp, err
}
// AddEmails adds email addresses of authenticated user
// AddEmails adds email addresses of the authenticated user.
//
// GitHub API docs: http://developer.github.com/v3/users/emails/#add-email-addresses
func (s *UsersService) AddEmails(emails []UserEmail) ([]UserEmail, *Response, error) {
func (s *UsersService) AddEmails(emails []string) ([]string, *Response, error) {
u := "user/emails"
req, err := s.client.NewRequest("POST", u, emails)
if err != nil {
return nil, nil, err
}
e := new([]UserEmail)
e := new([]string)
resp, err := s.client.Do(req, e)
if err != nil {
return nil, resp, err
@ -46,10 +50,10 @@ func (s *UsersService) AddEmails(emails []UserEmail) ([]UserEmail, *Response, er
return *e, resp, err
}
// DeleteEmails deletes email addresses from authenticated user
// DeleteEmails deletes email addresses from authenticated user.
//
// GitHub API docs: http://developer.github.com/v3/users/emails/#delete-email-addresses
func (s *UsersService) DeleteEmails(emails []UserEmail) (*Response, error) {
func (s *UsersService) DeleteEmails(emails []string) (*Response, error) {
u := "user/emails"
req, err := s.client.NewRequest("DELETE", u, emails)
if err != nil {


+ 11
- 7
github/users_emails_test.go View File

@ -19,7 +19,11 @@ func TestUsersService_ListEmails(t *testing.T) {
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `["user@example.com"]`)
fmt.Fprint(w, `[{
"email": "user@example.com",
"verified": false,
"primary": true
}]`)
})
emails, _, err := client.Users.ListEmails()
@ -27,7 +31,7 @@ func TestUsersService_ListEmails(t *testing.T) {
t.Errorf("Users.ListEmails returned error: %v", err)
}
want := []UserEmail{"user@example.com"}
want := []UserEmail{{Email: String("user@example.com"), Verified: Bool(false), Primary: Bool(true)}}
if !reflect.DeepEqual(emails, want) {
t.Errorf("Users.ListEmails returned %+v, want %+v", emails, want)
}
@ -37,10 +41,10 @@ func TestUsersService_AddEmails(t *testing.T) {
setup()
defer teardown()
input := []UserEmail{"new@example.com"}
input := []string{"new@example.com"}
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
v := new([]UserEmail)
v := new([]string)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "POST")
@ -56,7 +60,7 @@ func TestUsersService_AddEmails(t *testing.T) {
t.Errorf("Users.AddEmails returned error: %v", err)
}
want := []UserEmail{"old@example.com", "new@example.com"}
want := []string{"old@example.com", "new@example.com"}
if !reflect.DeepEqual(emails, want) {
t.Errorf("Users.AddEmails returned %+v, want %+v", emails, want)
}
@ -66,10 +70,10 @@ func TestUsersService_DeleteEmails(t *testing.T) {
setup()
defer teardown()
input := []UserEmail{"user@example.com"}
input := []string{"user@example.com"}
mux.HandleFunc("/user/emails", func(w http.ResponseWriter, r *http.Request) {
v := new([]UserEmail)
v := new([]string)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "DELETE")


+ 12
- 4
tests/integration/users_test.go View File

@ -5,10 +5,7 @@
package tests
import (
"fmt"
"testing"
)
import "testing"
func TestUsers_List(t *testing.T) {
u, _, err := client.Users.ListAll(nil)
@ -50,3 +47,14 @@ func TestUsers_Get(t *testing.T) {
}
}
}
func TestUsers_Emails(t *testing.T) {
if !checkAuth("TestUsers_Emails") {
return
}
emails, _, err := client.Users.ListEmails()
if err != nil {
t.Fatalf("Users.ListEmails() returned error: %v", err)
}
}

Loading…
Cancel
Save