Parcourir la source

Updated userguilds to new api (#296)

* Updated userguilds to new api

* Fixed typos
jonas747 il y a 8 ans
Parent
commit
86a21ea94b
2 fichiers modifiés avec 24 ajouts et 3 suppressions
  1. 23 2
      restapi.go
  2. 1 1
      restapi_test.go

+ 23 - 2
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
 	}

+ 1 - 1
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())
 	}