@@ -249,7 +249,7 @@ func (c *Client) execute(method string, urlStr string, text string) (interface{}
249249 return result , nil
250250}
251251
252- func (c * Client ) executePaginated (method string , urlStr string , text string ) (interface {}, error ) {
252+ func (c * Client ) executePaginated (method string , urlStr string , text string , page * int ) (interface {}, error ) {
253253 if c .Pagelen != DEFAULT_PAGE_LENGTH {
254254 urlObj , err := url .Parse (urlStr )
255255 if err != nil {
@@ -271,7 +271,7 @@ func (c *Client) executePaginated(method string, urlStr string, text string) (in
271271 }
272272
273273 c .authenticateRequest (req )
274- result , err := c .doPaginatedRequest (req , false )
274+ result , err := c .doPaginatedRequest (req , page , false )
275275 if err != nil {
276276 return nil , err
277277 }
@@ -358,7 +358,19 @@ func (c *Client) doRequest(req *http.Request, emptyResponse bool) (interface{},
358358 return result , nil
359359}
360360
361- func (c * Client ) doPaginatedRequest (req * http.Request , emptyResponse bool ) (interface {}, error ) {
361+ func (c * Client ) doPaginatedRequest (req * http.Request , page * int , emptyResponse bool ) (interface {}, error ) {
362+ disableAutoPaging := c .DisableAutoPaging
363+ curPage := 1
364+ if page != nil {
365+ disableAutoPaging = true
366+ curPage = * page
367+ q := req .URL .Query ()
368+ q .Set ("page" , strconv .Itoa (curPage ))
369+ req .URL .RawQuery = q .Encode ()
370+ }
371+ // q.Encode() does not encode "~".
372+ req .URL .RawQuery = strings .ReplaceAll (req .URL .RawQuery , "~" , "%7E" )
373+
362374 resBody , err := c .doRawRequest (req , emptyResponse )
363375 if err != nil {
364376 return nil , err
@@ -375,18 +387,15 @@ func (c *Client) doPaginatedRequest(req *http.Request, emptyResponse bool) (inte
375387 }
376388
377389 responsePaginated := & Response {}
378- var curPage int
379-
380390 err = json .Unmarshal (responseBytes , responsePaginated )
381391 if err == nil && len (responsePaginated .Values ) > 0 {
382- var values [] interface {}
392+ values := responsePaginated . Values
383393 for {
384- curPage ++
385- values = append (values , responsePaginated .Values ... )
386- if c .DisableAutoPaging || len (responsePaginated .Next ) == 0 ||
394+ if disableAutoPaging || responsePaginated .Next == "" ||
387395 (curPage >= c .LimitPages && c .LimitPages != 0 ) {
388396 break
389397 }
398+ curPage ++
390399 newReq , err := http .NewRequest (req .Method , responsePaginated .Next , nil )
391400 if err != nil {
392401 return resBody , err
@@ -399,6 +408,7 @@ func (c *Client) doPaginatedRequest(req *http.Request, emptyResponse bool) (inte
399408
400409 responsePaginated = & Response {}
401410 json .NewDecoder (resp ).Decode (responsePaginated )
411+ values = append (values , responsePaginated .Values ... )
402412 }
403413 responsePaginated .Values = values
404414 responseBytes , err = json .Marshal (responsePaginated )
0 commit comments