Skip to content

Commit 6cc168c

Browse files
committed
add user_email
1 parent 4b541fa commit 6cc168c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func Version() string {
17-
return "0.4.0"
17+
return "0.5.0"
1818
}
1919

2020
// Client represents a Gogs API client.

user_email.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Comments
 (0)