2019-04-25 13:06:53 -04: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"
|
|
|
|
|
2020-05-27 09:48:09 -04:00
|
|
|
// ListFollowersOptions options for listing followers
|
|
|
|
type ListFollowersOptions struct {
|
|
|
|
ListOptions
|
|
|
|
}
|
|
|
|
|
2019-04-25 13:06:53 -04:00
|
|
|
// ListMyFollowers list all the followers of current user
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) ListMyFollowers(opt ListFollowersOptions) ([]*User, *Response, error) {
|
2020-05-27 09:48:09 -04:00
|
|
|
opt.setDefaults()
|
|
|
|
users := make([]*User, 0, opt.PageSize)
|
2020-09-15 22:01:41 -04:00
|
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/followers?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
|
|
|
return users, resp, err
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListFollowers list all the followers of one user
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) ListFollowers(user string, opt ListFollowersOptions) ([]*User, *Response, error) {
|
2020-05-27 09:48:09 -04:00
|
|
|
opt.setDefaults()
|
|
|
|
users := make([]*User, 0, opt.PageSize)
|
2020-09-15 22:01:41 -04:00
|
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?%s", user, opt.getURLQuery().Encode()), nil, nil, &users)
|
|
|
|
return users, resp, err
|
2020-05-27 09:48:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListFollowingOptions options for listing a user's users being followed
|
|
|
|
type ListFollowingOptions struct {
|
|
|
|
ListOptions
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListMyFollowing list all the users current user followed
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) ListMyFollowing(opt ListFollowingOptions) ([]*User, *Response, error) {
|
2020-05-27 09:48:09 -04:00
|
|
|
opt.setDefaults()
|
|
|
|
users := make([]*User, 0, opt.PageSize)
|
2020-09-15 22:01:41 -04:00
|
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/user/following?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
|
|
|
return users, resp, err
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ListFollowing list all the users the user followed
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) ListFollowing(user string, opt ListFollowingOptions) ([]*User, *Response, error) {
|
2020-05-27 09:48:09 -04:00
|
|
|
opt.setDefaults()
|
|
|
|
users := make([]*User, 0, opt.PageSize)
|
2020-09-15 22:01:41 -04:00
|
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?%s", user, opt.getURLQuery().Encode()), nil, nil, &users)
|
|
|
|
return users, resp, err
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsFollowing if current user followed the target
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) IsFollowing(target string) (bool, *Response) {
|
|
|
|
_, resp, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
|
|
|
return err == nil, resp
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsUserFollowing if the user followed the target
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) IsUserFollowing(user, target string) (bool, *Response) {
|
|
|
|
_, resp, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil)
|
|
|
|
return err == nil, resp
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Follow set current user follow the target
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) Follow(target string) (*Response, error) {
|
|
|
|
_, resp, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
|
|
|
return resp, err
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unfollow set current user unfollow the target
|
2020-09-15 22:01:41 -04:00
|
|
|
func (c *Client) Unfollow(target string) (*Response, error) {
|
|
|
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
|
|
|
return resp, err
|
2019-04-25 13:06:53 -04:00
|
|
|
}
|