Debian Codegraph @

github/users_emails.go

raw
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/rest/users/emails#list-email-addresses-for-the-authenticated-user
21 //
22 //meta:operation GET /user/emails
23 func (s *UsersService) ListEmails(ctx context.Context, opts *ListOptions) ([]*UserEmail, *Response, error) {
24 u := "user/emails"
25 u, err := addOptions(u, opts)
26 if err != nil {
27 return nil, nil, err
28 }
29
30 req, err := s.client.NewRequest("GET", u, nil)
31 if err != nil {
32 return nil, nil, err
33 }
34
35 var emails []*UserEmail
36 resp, err := s.client.Do(ctx, req, &emails)
37 if err != nil {
38 return nil, resp, err
39 }
40
41 return emails, resp, nil
42 }
43
44 // AddEmails adds email addresses of the authenticated user.
45 //
46 // GitHub API docs: https://docs.github.com/rest/users/emails#add-an-email-address-for-the-authenticated-user
47 //
48 //meta:operation POST /user/emails
49 func (s *UsersService) AddEmails(ctx context.Context, emails []string) ([]*UserEmail, *Response, error) {
50 u := "user/emails"
51 req, err := s.client.NewRequest("POST", u, emails)
52 if err != nil {
53 return nil, nil, err
54 }
55
56 var e []*UserEmail
57 resp, err := s.client.Do(ctx, req, &e)
58 if err != nil {
59 return nil, resp, err
60 }
61
62 return e, resp, nil
63 }
64
65 // DeleteEmails deletes email addresses from authenticated user.
66 //
67 // GitHub API docs: https://docs.github.com/rest/users/emails#delete-an-email-address-for-the-authenticated-user
68 //
69 //meta:operation DELETE /user/emails
70 func (s *UsersService) DeleteEmails(ctx context.Context, emails []string) (*Response, error) {
71 u := "user/emails"
72 req, err := s.client.NewRequest("DELETE", u, emails)
73 if err != nil {
74 return nil, err
75 }
76
77 return s.client.Do(ctx, req, nil)
78 }
79
80 // SetEmailVisibility sets the visibility for the primary email address of the authenticated user.
81 // `visibility` can be "private" or "public".
82 //
83 // GitHub API docs: https://docs.github.com/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user
84 //
85 //meta:operation PATCH /user/email/visibility
86 func (s *UsersService) SetEmailVisibility(ctx context.Context, visibility string) ([]*UserEmail, *Response, error) {
87 u := "user/email/visibility"
88
89 updateVisiblilityReq := &UserEmail{
90 Visibility: &visibility,
91 }
92
93 req, err := s.client.NewRequest("PATCH", u, updateVisiblilityReq)
94 if err != nil {
95 return nil, nil, err
96 }
97
98 var e []*UserEmail
99 resp, err := s.client.Do(ctx, req, &e)
100 if err != nil {
101 return nil, resp, err
102 }
103
104 return e, resp, nil
105 }