Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Commit 2a795f0

Browse files
committed
user - follow
1 parent 78460e9 commit 2a795f0

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

gogs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
func Version() string {
17-
return "0.6.0"
17+
return "0.7.0"
1818
}
1919

2020
// Client represents a Gogs API client.
@@ -66,7 +66,7 @@ func (c *Client) getResponse(method, path string, header http.Header, body io.Re
6666
return nil, errors.New("404 Not Found")
6767
}
6868

69-
if resp.StatusCode != 200 && resp.StatusCode != 201 {
69+
if resp.StatusCode%100 != 2 {
7070
errMap := make(map[string]interface{})
7171
if err = json.Unmarshal(data, &errMap); err != nil {
7272
return nil, err

user_follow.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
5+
package gogs
6+
7+
import "fmt"
8+
9+
func (c *Client) ListMyFollowers(page int) ([]*User, error) {
10+
users := make([]*User, 0, 10)
11+
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?page=%d", page), nil, nil, &users)
12+
}
13+
14+
func (c *Client) ListFollowers(user string, page int) ([]*User, error) {
15+
users := make([]*User, 0, 10)
16+
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?page=%d", user, page), nil, nil, &users)
17+
}
18+
19+
func (c *Client) ListMyFollowing(page int) ([]*User, error) {
20+
users := make([]*User, 0, 10)
21+
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?page=%d", page), nil, nil, &users)
22+
}
23+
24+
func (c *Client) ListFollowing(user string, page int) ([]*User, error) {
25+
users := make([]*User, 0, 10)
26+
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?page=%d", user, page), nil, nil, &users)
27+
}
28+
29+
func (c *Client) IsFollowing(target string) bool {
30+
_, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
31+
return err == nil
32+
}
33+
34+
func (c *Client) IsUserFollowing(user, target string) bool {
35+
_, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil)
36+
return err == nil
37+
}
38+
39+
func (c *Client) Follow(target string) error {
40+
_, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
41+
return err
42+
}
43+
44+
func (c *Client) Unfollow(target string) error {
45+
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
46+
return err
47+
}

0 commit comments

Comments
 (0)