1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/client/users.go

48 lines
1.1 KiB
Go
Raw Normal View History

2014-08-10 02:51:08 +03:00
package client
import (
"fmt"
"github.com/drone/drone/shared/model"
)
type UserService struct {
*Client
}
2014-09-29 04:38:21 +03:00
// GET /api/users/{host}/{login}
2014-08-10 02:51:08 +03:00
func (s *UserService) Get(remote, login string) (*model.User, error) {
2014-09-29 04:38:21 +03:00
var path = fmt.Sprintf("/api/users/%s/%s", remote, login)
2014-08-10 02:51:08 +03:00
var user = model.User{}
var err = s.run("GET", path, nil, &user)
return &user, err
}
2014-09-29 04:38:21 +03:00
// GET /api/user
2014-08-10 02:51:08 +03:00
func (s *UserService) GetCurrent() (*model.User, error) {
var user = model.User{}
2014-09-29 04:38:21 +03:00
var err = s.run("GET", "/api/user", nil, &user)
2014-08-10 02:51:08 +03:00
return &user, err
}
2014-09-29 04:38:21 +03:00
// POST /api/users/{host}/{login}
2014-08-10 02:51:08 +03:00
func (s *UserService) Create(remote, login string) (*model.User, error) {
2014-09-29 04:38:21 +03:00
var path = fmt.Sprintf("/api/users/%s/%s", remote, login)
2014-08-10 02:51:08 +03:00
var user = model.User{}
var err = s.run("POST", path, nil, &user)
return &user, err
}
2014-09-29 04:38:21 +03:00
// DELETE /api/users/{host}/{login}
2014-08-10 02:51:08 +03:00
func (s *UserService) Delete(remote, login string) error {
2014-09-29 04:38:21 +03:00
var path = fmt.Sprintf("/api/users/%s/%s", remote, login)
2014-08-10 02:51:08 +03:00
return s.run("DELETE", path, nil, nil)
}
2014-09-29 04:38:21 +03:00
// GET /api/users
2014-08-10 02:51:08 +03:00
func (s *UserService) List() ([]*model.User, error) {
var users []*model.User
2014-09-29 04:38:21 +03:00
var err = s.run("GET", "/api/users", nil, &users)
2014-08-10 02:51:08 +03:00
return users, err
}