Skip to content

Commit

Permalink
Support limit for following (#38)
Browse files Browse the repository at this point in the history
* Support limit for following

* Add tests for limit
  • Loading branch information
BrandonRomano authored Oct 19, 2017
1 parent 2f8ab36 commit 52dcea0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions controllers/me_following_users_controller.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controllers

import (
"strconv"

"github.com/BrandonRomano/wrecker"
"github.com/carrot/go-pinterest/models"
)
Expand All @@ -22,6 +24,7 @@ func newMeFollowingUsersController(wc *wrecker.Wrecker) *MeFollowingUsersControl
// parameters for the Fetch method
type FollowingUsersControllerFetchOptionals struct {
Cursor string
Limit int
}

// Fetch loads the users that the authorized user follows
Expand All @@ -36,6 +39,9 @@ func (c *MeFollowingUsersController) Fetch(optionals *FollowingUsersControllerFe
if optionals.Cursor != "" {
request.URLParam("cursor", optionals.Cursor)
}
if optionals.Limit != 0 {
request.URLParam("limit", strconv.Itoa(optionals.Limit))
}
httpResp, err := request.Execute()

// Check Error
Expand Down
5 changes: 3 additions & 2 deletions pinterest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,14 @@ func (suite *ClientTestSuite) TestSuccessfulMeFollowingUsersFetch() {
assert.Equal(suite.T(), len(*users), 25)

// Load second page
suite.client.Me.Following.Users.Fetch(
users, _, err = suite.client.Me.Following.Users.Fetch(
&controllers.FollowingUsersControllerFetchOptionals{
Cursor: page.Cursor,
Limit: 3,
},
)
assert.Equal(suite.T(), nil, err)
assert.True(suite.T(), len(*users) > 0)
assert.True(suite.T(), len(*users) == 3)
}

// TestTimeoutMeFollowingUsersFetch tests that an error is appropriately thrown
Expand Down

0 comments on commit 52dcea0

Please sign in to comment.