From 86a21ea94b7453208c2eb14c7c091cfa6f8740cd Mon Sep 17 00:00:00 2001 From: jonas747 Date: Sat, 10 Dec 2016 18:45:07 +0100 Subject: [PATCH] Updated userguilds to new api (#296) * Updated userguilds to new api * Fixed typos --- restapi.go | 25 +++++++++++++++++++++++-- restapi_test.go | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/restapi.go b/restapi.go index 5389c86..e7f3357 100644 --- a/restapi.go +++ b/restapi.go @@ -370,9 +370,30 @@ func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error) } // UserGuilds returns an array of UserGuild structures for all guilds. -func (s *Session) UserGuilds() (st []*UserGuild, err error) { +// limit : The number guilds that can be returned. (max 100) +// beforeID : If provided all guilds returned will be before given ID. +// afterID : If provided all guilds returned will be after given ID. +func (s *Session) UserGuilds(limit int, beforeID, afterID string) (st []*UserGuild, err error) { - body, err := s.RequestWithBucketID("GET", EndpointUserGuilds("@me"), nil, EndpointUserGuilds("")) + v := url.Values{} + + if limit > 0 { + v.Set("limit", strconv.Itoa(limit)) + } + if afterID != "" { + v.Set("after", afterID) + } + if beforeID != "" { + v.Set("before", beforeID) + } + + uri := EndpointUserGuilds("@me") + + if len(v) > 0 { + uri = fmt.Sprintf("%s?%s", uri, v.Encode()) + } + + body, err := s.RequestWithBucketID("GET", uri, nil, EndpointUserGuilds("")) if err != nil { return } diff --git a/restapi_test.go b/restapi_test.go index e4d111b..a5d326b 100644 --- a/restapi_test.go +++ b/restapi_test.go @@ -114,7 +114,7 @@ func TestUserGuilds(t *testing.T) { t.Skip("Cannot TestUserGuilds, dg not set.") } - _, err := dg.UserGuilds() + _, err := dg.UserGuilds(10, "", "") if err != nil { t.Errorf(err.Error()) }