woodpecker/client/users.go

48 lines
1.1 KiB
Go
Raw Normal View History

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