From 82f9e1976e051ccc5cfbc19e9f822e8a1e1e624d Mon Sep 17 00:00:00 2001 From: Justin Abrahms Date: Mon, 2 Sep 2013 02:03:30 -0700 Subject: [PATCH] Provide pagination to `UserService.ListFollowing` --- github/users_followers.go | 11 ++++++++++- github/users_followers_test.go | 8 +++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/github/users_followers.go b/github/users_followers.go index 3161fe4..a629769 100644 --- a/github/users_followers.go +++ b/github/users_followers.go @@ -6,6 +6,8 @@ package github import "fmt" +import "net/url" +import "strconv" // ListFollowers lists the followers for a user. Passing the empty string will // 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. // // 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 if user != "" { u = fmt.Sprintf("users/%v/following", user) @@ -41,6 +43,13 @@ func (s *UsersService) ListFollowing(user string) ([]User, *Response, error) { 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) if err != nil { return nil, nil, err diff --git a/github/users_followers_test.go b/github/users_followers_test.go index 1b874d9..3bf5ac7 100644 --- a/github/users_followers_test.go +++ b/github/users_followers_test.go @@ -63,10 +63,12 @@ func TestUsersService_ListFollowing_authenticatedUser(t *testing.T) { mux.HandleFunc("/user/following", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testFormValues(t, r, values{"page": "2"}) fmt.Fprint(w, `[{"id":1}]`) }) - users, _, err := client.Users.ListFollowing("") + opts := &ListOptions{2} + users, _, err := client.Users.ListFollowing("", opts) if err != nil { t.Errorf("Users.ListFollowing returned error: %v", err) } @@ -86,7 +88,7 @@ func TestUsersService_ListFollowing_specifiedUser(t *testing.T) { fmt.Fprint(w, `[{"id":1}]`) }) - users, _, err := client.Users.ListFollowing("u") + users, _, err := client.Users.ListFollowing("u", nil) if err != nil { 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) { - _, _, err := client.Users.ListFollowing("%") + _, _, err := client.Users.ListFollowing("%", nil) testURLParseError(t, err) }