2019-05-07 09:12:51 +08:00
|
|
|
// Copyright 2013 The go-github AUTHORS. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package github
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
// UserEmail represents user's email address
|
|
|
|
type UserEmail struct {
|
2020-07-31 22:22:34 +08:00
|
|
|
Email *string `json:"email,omitempty"`
|
|
|
|
Primary *bool `json:"primary,omitempty"`
|
|
|
|
Verified *bool `json:"verified,omitempty"`
|
|
|
|
Visibility *string `json:"visibility,omitempty"`
|
2019-05-07 09:12:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListEmails lists all email addresses for the authenticated user.
|
|
|
|
//
|
2020-07-31 22:22:34 +08:00
|
|
|
// GitHub API docs: https://developer.github.com/v3/users/emails/#list-email-addresses-for-the-authenticated-user
|
|
|
|
func (s *UsersService) ListEmails(ctx context.Context, opts *ListOptions) ([]*UserEmail, *Response, error) {
|
2019-05-07 09:12:51 +08:00
|
|
|
u := "user/emails"
|
2020-07-31 22:22:34 +08:00
|
|
|
u, err := addOptions(u, opts)
|
2019-05-07 09:12:51 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var emails []*UserEmail
|
|
|
|
resp, err := s.client.Do(ctx, req, &emails)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return emails, resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddEmails adds email addresses of the authenticated user.
|
|
|
|
//
|
2020-07-31 22:22:34 +08:00
|
|
|
// GitHub API docs: https://developer.github.com/v3/users/emails/#add-an-email-address-for-the-authenticated-user
|
2019-05-07 09:12:51 +08:00
|
|
|
func (s *UsersService) AddEmails(ctx context.Context, emails []string) ([]*UserEmail, *Response, error) {
|
|
|
|
u := "user/emails"
|
|
|
|
req, err := s.client.NewRequest("POST", u, emails)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var e []*UserEmail
|
|
|
|
resp, err := s.client.Do(ctx, req, &e)
|
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return e, resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteEmails deletes email addresses from authenticated user.
|
|
|
|
//
|
2020-07-31 22:22:34 +08:00
|
|
|
// GitHub API docs: https://developer.github.com/v3/users/emails/#delete-an-email-address-for-the-authenticated-user
|
2019-05-07 09:12:51 +08:00
|
|
|
func (s *UsersService) DeleteEmails(ctx context.Context, emails []string) (*Response, error) {
|
|
|
|
u := "user/emails"
|
|
|
|
req, err := s.client.NewRequest("DELETE", u, emails)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.client.Do(ctx, req, nil)
|
|
|
|
}
|