Browse Source

Provide pagination to `UserService.ListFollowing`

Justin Abrahms 12 years ago
committed by Will Norris
parent
commit
82f9e1976e
2 changed files with 15 additions and 4 deletions
  1. +10
    -1
      github/users_followers.go
  2. +5
    -3
      github/users_followers_test.go

+ 10
- 1
github/users_followers.go View File

@ -6,6 +6,8 @@
package github package github
import "fmt" import "fmt"
import "net/url"
import "strconv"
// ListFollowers lists the followers for a user. Passing the empty string will // ListFollowers lists the followers for a user. Passing the empty string will
// fetch followers for the authenticated user. // fetch followers for the authenticated user.
@ -33,7 +35,7 @@ func (s *UsersService) ListFollowers(user string) ([]User, *Response, error) {
// string will list people the authenticated user is following. // string will list people the authenticated user is following.
// //
// GitHub API docs: http://developer.github.com/v3/users/followers/#list-users-followed-by-another-user // GitHub API docs: http://developer.github.com/v3/users/followers/#list-users-followed-by-another-user
func (s *UsersService) ListFollowing(user string) ([]User, *Response, error) {
func (s *UsersService) ListFollowing(user string, opt *ListOptions) ([]User, *Response, error) {
var u string var u string
if user != "" { if user != "" {
u = fmt.Sprintf("users/%v/following", user) u = fmt.Sprintf("users/%v/following", user)
@ -41,6 +43,13 @@ func (s *UsersService) ListFollowing(user string) ([]User, *Response, error) {
u = "user/following" u = "user/following"
} }
if opt != nil {
params := url.Values{
"page": []string{strconv.Itoa(opt.Page)},
}
u += "?" + params.Encode()
}
req, err := s.client.NewRequest("GET", u, nil) req, err := s.client.NewRequest("GET", u, nil)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err


+ 5
- 3
github/users_followers_test.go View File

@ -63,10 +63,12 @@ func TestUsersService_ListFollowing_authenticatedUser(t *testing.T) {
mux.HandleFunc("/user/following", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/user/following", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET") testMethod(t, r, "GET")
testFormValues(t, r, values{"page": "2"})
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
users, _, err := client.Users.ListFollowing("")
opts := &ListOptions{2}
users, _, err := client.Users.ListFollowing("", opts)
if err != nil { if err != nil {
t.Errorf("Users.ListFollowing returned error: %v", err) t.Errorf("Users.ListFollowing returned error: %v", err)
} }
@ -86,7 +88,7 @@ func TestUsersService_ListFollowing_specifiedUser(t *testing.T) {
fmt.Fprint(w, `[{"id":1}]`) fmt.Fprint(w, `[{"id":1}]`)
}) })
users, _, err := client.Users.ListFollowing("u")
users, _, err := client.Users.ListFollowing("u", nil)
if err != nil { if err != nil {
t.Errorf("Users.ListFollowing returned error: %v", err) t.Errorf("Users.ListFollowing returned error: %v", err)
} }
@ -98,7 +100,7 @@ func TestUsersService_ListFollowing_specifiedUser(t *testing.T) {
} }
func TestUsersService_ListFollowing_invalidUser(t *testing.T) { func TestUsersService_ListFollowing_invalidUser(t *testing.T) {
_, _, err := client.Users.ListFollowing("%")
_, _, err := client.Users.ListFollowing("%", nil)
testURLParseError(t, err) testURLParseError(t, err)
} }


Loading…
Cancel
Save