forked from plouc/go-gitlab-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.go
95 lines (73 loc) · 2.31 KB
/
users.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package gogitlab
import (
"encoding/json"
"strconv"
)
const (
users_url = "/users?page=:page&per_page=:per_page" // Get users list
user_url = "/users/:id" // Get a single user.
current_user_url = "/user" // Get current user
)
type User struct {
Id int `json:"id,omitempty"`
Username string `json:"username,omitempty"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
State string `json:"state,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Bio string `json:"bio,omitempty"`
Skype string `json:"skype,omitempty"`
LinkedIn string `json:"linkedin,omitempty"`
Twitter string `json:"twitter,omitempty"`
WebURL string `json:"web_url"`
ExternUid string `json:"extern_uid,omitempty"`
Provider string `json:"provider,omitempty"`
ThemeId int `json:"theme_id,omitempty"`
ColorSchemeId int `json:"color_scheme_id,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
}
func (g *Gitlab) Users(page, per_page int) ([]*User, error) {
url := g.ResourceUrl(users_url, map[string]string{":page": strconv.Itoa(page), ":per_page": strconv.Itoa(per_page)})
var users []*User
contents, err := g.buildAndExecRequest("GET", url, nil)
if err == nil {
err = json.Unmarshal(contents, &users)
}
return users, err
}
/*
Get a single user.
GET /users/:id
Parameters:
id The ID of a user
Usage:
user, err := gitlab.User("your_user_id")
if err != nil {
fmt.Println(err.Error())
}
fmt.Printf("%+v\n", user)
*/
func (g *Gitlab) User(id string) (*User, error) {
url := g.ResourceUrl(user_url, map[string]string{":id": id})
user := new(User)
contents, err := g.buildAndExecRequest("GET", url, nil)
if err == nil {
err = json.Unmarshal(contents, &user)
}
return user, err
}
func (g *Gitlab) DeleteUser(id string) error {
url := g.ResourceUrl(user_url, map[string]string{":id": id})
var err error
_, err = g.buildAndExecRequest("DELETE", url, nil)
return err
}
func (g *Gitlab) CurrentUser() (User, error) {
url := g.ResourceUrl(current_user_url, nil)
var user User
contents, err := g.buildAndExecRequest("GET", url, nil)
if err == nil {
err = json.Unmarshal(contents, &user)
}
return user, err
}