2017-02-07 21:33:23 +00: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
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
import "context"
|
|
|
|
|
2017-02-07 21:33:23 +00:00
|
|
|
// UserEmail represents user's email address
|
|
|
|
type UserEmail struct {
|
|
|
|
Email *string `json:"email,omitempty"`
|
|
|
|
Primary *bool `json:"primary,omitempty"`
|
|
|
|
Verified *bool `json:"verified,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListEmails lists all email addresses for the authenticated user.
|
|
|
|
//
|
2017-04-11 15:10:46 +00:00
|
|
|
// GitHub API docs: https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
|
|
|
|
func (s *UsersService) ListEmails(ctx context.Context, opt *ListOptions) ([]*UserEmail, *Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := "user/emails"
|
|
|
|
u, err := addOptions(u, opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := s.client.NewRequest("GET", u, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
var emails []*UserEmail
|
|
|
|
resp, err := s.client.Do(ctx, req, &emails)
|
2017-02-07 21:33:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
return emails, resp, nil
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddEmails adds email addresses of the authenticated user.
|
|
|
|
//
|
2017-04-11 15:10:46 +00:00
|
|
|
// GitHub API docs: https://developer.github.com/v3/users/emails/#add-email-addresses
|
|
|
|
func (s *UsersService) AddEmails(ctx context.Context, emails []string) ([]*UserEmail, *Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := "user/emails"
|
|
|
|
req, err := s.client.NewRequest("POST", u, emails)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
var e []*UserEmail
|
|
|
|
resp, err := s.client.Do(ctx, req, &e)
|
2017-02-07 21:33:23 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
return e, resp, nil
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteEmails deletes email addresses from authenticated user.
|
|
|
|
//
|
2017-04-11 15:10:46 +00:00
|
|
|
// GitHub API docs: https://developer.github.com/v3/users/emails/#delete-email-addresses
|
|
|
|
func (s *UsersService) DeleteEmails(ctx context.Context, emails []string) (*Response, error) {
|
2017-02-07 21:33:23 +00:00
|
|
|
u := "user/emails"
|
|
|
|
req, err := s.client.NewRequest("DELETE", u, emails)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:10:46 +00:00
|
|
|
return s.client.Do(ctx, req, nil)
|
2017-02-07 21:33:23 +00:00
|
|
|
}
|