forgejo/vendor/code.gitea.io/sdk/gitea/user_follow.go

56 lines
2 KiB
Go
Raw Normal View History

2016-11-07 13:53:13 +00:00
// Copyright 2015 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gitea
import "fmt"
2016-11-29 08:09:17 +00:00
// ListMyFollowers list all the followers of current user
2016-11-07 13:53:13 +00:00
func (c *Client) ListMyFollowers(page int) ([]*User, error) {
users := make([]*User, 0, 10)
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?page=%d", page), nil, nil, &users)
}
2016-11-29 08:09:17 +00:00
// ListFollowers list all the followers of one user
2016-11-07 13:53:13 +00:00
func (c *Client) ListFollowers(user string, page int) ([]*User, error) {
users := make([]*User, 0, 10)
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?page=%d", user, page), nil, nil, &users)
}
2016-11-29 08:09:17 +00:00
// ListMyFollowing list all the users current user followed
2016-11-07 13:53:13 +00:00
func (c *Client) ListMyFollowing(page int) ([]*User, error) {
users := make([]*User, 0, 10)
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?page=%d", page), nil, nil, &users)
}
2016-11-29 08:09:17 +00:00
// ListFollowing list all the users the user followed
2016-11-07 13:53:13 +00:00
func (c *Client) ListFollowing(user string, page int) ([]*User, error) {
users := make([]*User, 0, 10)
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?page=%d", user, page), nil, nil, &users)
}
2016-11-29 08:09:17 +00:00
// IsFollowing if current user followed the target
2016-11-07 13:53:13 +00:00
func (c *Client) IsFollowing(target string) bool {
_, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
return err == nil
}
2016-11-29 08:09:17 +00:00
// IsUserFollowing if the user followed the target
2016-11-07 13:53:13 +00:00
func (c *Client) IsUserFollowing(user, target string) bool {
_, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil)
return err == nil
}
2016-11-29 08:09:17 +00:00
// Follow set current user follow the target
2016-11-07 13:53:13 +00:00
func (c *Client) Follow(target string) error {
_, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
return err
}
2016-11-29 08:09:17 +00:00
// Unfollow set current user unfollow the target
2016-11-07 13:53:13 +00:00
func (c *Client) Unfollow(target string) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
return err
}