user_follow.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package gogs
  5. import "fmt"
  6. func (c *Client) ListMyFollowers(page int) ([]*User, error) {
  7. users := make([]*User, 0, 10)
  8. return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?page=%d", page), nil, nil, &users)
  9. }
  10. func (c *Client) ListFollowers(user string, page int) ([]*User, error) {
  11. users := make([]*User, 0, 10)
  12. return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?page=%d", user, page), nil, nil, &users)
  13. }
  14. func (c *Client) ListMyFollowing(page int) ([]*User, error) {
  15. users := make([]*User, 0, 10)
  16. return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?page=%d", page), nil, nil, &users)
  17. }
  18. func (c *Client) ListFollowing(user string, page int) ([]*User, error) {
  19. users := make([]*User, 0, 10)
  20. return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?page=%d", user, page), nil, nil, &users)
  21. }
  22. func (c *Client) IsFollowing(target string) bool {
  23. _, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
  24. return err == nil
  25. }
  26. func (c *Client) IsUserFollowing(user, target string) bool {
  27. _, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil)
  28. return err == nil
  29. }
  30. func (c *Client) Follow(target string) error {
  31. _, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
  32. return err
  33. }
  34. func (c *Client) Unfollow(target string) error {
  35. _, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
  36. return err
  37. }