|
| 1 | +// Copyright 2015 The Gogs Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package gogs |
| 6 | + |
| 7 | +import ( |
| 8 | + "bytes" |
| 9 | + "encoding/json" |
| 10 | + "net/http" |
| 11 | +) |
| 12 | + |
| 13 | +type Email struct { |
| 14 | + Email string `json:"email"` |
| 15 | + Verified bool `json:"verified"` |
| 16 | + Primary bool `json:"primary"` |
| 17 | +} |
| 18 | + |
| 19 | +func (c *Client) ListEmails() ([]*Email, error) { |
| 20 | + emails := make([]*Email, 0, 3) |
| 21 | + return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails) |
| 22 | +} |
| 23 | + |
| 24 | +type CreateEmailOption struct { |
| 25 | + Emails []string `json:"emails"` |
| 26 | +} |
| 27 | + |
| 28 | +func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) { |
| 29 | + body, err := json.Marshal(&opt) |
| 30 | + if err != nil { |
| 31 | + return nil, err |
| 32 | + } |
| 33 | + emails := make([]*Email, 0, 3) |
| 34 | + return emails, c.getParsedResponse("POST", "/user/emails", |
| 35 | + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body), emails) |
| 36 | +} |
| 37 | + |
| 38 | +func (c *Client) DeleteEmail(opt CreateEmailOption) error { |
| 39 | + body, err := json.Marshal(&opt) |
| 40 | + if err != nil { |
| 41 | + return err |
| 42 | + } |
| 43 | + _, err = c.getResponse("DELETE", "/user/emails", |
| 44 | + http.Header{"content-type": []string{"application/json"}}, bytes.NewReader(body)) |
| 45 | + return err |
| 46 | +} |
0 commit comments