github.com/google/go-github/v49@v49.1.0/github/users_emails.go (about) 1 // Copyright 2013 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import "context" 9 10 // UserEmail represents user's email address 11 type UserEmail struct { 12 Email *string `json:"email,omitempty"` 13 Primary *bool `json:"primary,omitempty"` 14 Verified *bool `json:"verified,omitempty"` 15 Visibility *string `json:"visibility,omitempty"` 16 } 17 18 // ListEmails lists all email addresses for the authenticated user. 19 // 20 // GitHub API docs: https://docs.github.com/en/rest/users/emails#list-email-addresses-for-the-authenticated-user 21 func (s *UsersService) ListEmails(ctx context.Context, opts *ListOptions) ([]*UserEmail, *Response, error) { 22 u := "user/emails" 23 u, err := addOptions(u, opts) 24 if err != nil { 25 return nil, nil, err 26 } 27 28 req, err := s.client.NewRequest("GET", u, nil) 29 if err != nil { 30 return nil, nil, err 31 } 32 33 var emails []*UserEmail 34 resp, err := s.client.Do(ctx, req, &emails) 35 if err != nil { 36 return nil, resp, err 37 } 38 39 return emails, resp, nil 40 } 41 42 // AddEmails adds email addresses of the authenticated user. 43 // 44 // GitHub API docs: https://docs.github.com/en/rest/users/emails#add-an-email-address-for-the-authenticated-user 45 func (s *UsersService) AddEmails(ctx context.Context, emails []string) ([]*UserEmail, *Response, error) { 46 u := "user/emails" 47 req, err := s.client.NewRequest("POST", u, emails) 48 if err != nil { 49 return nil, nil, err 50 } 51 52 var e []*UserEmail 53 resp, err := s.client.Do(ctx, req, &e) 54 if err != nil { 55 return nil, resp, err 56 } 57 58 return e, resp, nil 59 } 60 61 // DeleteEmails deletes email addresses from authenticated user. 62 // 63 // GitHub API docs: https://docs.github.com/en/rest/users/emails#delete-an-email-address-for-the-authenticated-user 64 func (s *UsersService) DeleteEmails(ctx context.Context, emails []string) (*Response, error) { 65 u := "user/emails" 66 req, err := s.client.NewRequest("DELETE", u, emails) 67 if err != nil { 68 return nil, err 69 } 70 71 return s.client.Do(ctx, req, nil) 72 }