Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions commerce.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func (s *Session) CommerceListings(ids ...int) (items []*CommerceListing, err er
return
}

// CommerceListingsPagination returns buy and sell orders for the items with pagination
func (s *Session) CommerceListingsPagination(page, pageSize int) (items []*CommerceListing, err error) {
err = s.get(concatStrings("/v2/commerce/listings", genArgsPagination(page, pageSize)), &items)
return
}

// CommerceListingsIds returns ids of all items available on trading post
func (s *Session) CommerceListingsIds() (ids []int, err error) {
err = s.get("/v2/commerce/listings", &ids)
Expand Down
9 changes: 9 additions & 0 deletions commerce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func TestCommerceListings(t *testing.T) {
}
}

func TestCommerceListingsPagination(t *testing.T) {
api := New()

_, err := api.CommerceListingsPagination(0, 201)
if err != nil {
t.Errorf("CommerceListingsPagination failed: '%s'", err)
}
}

func TestCommerceListingsIds(t *testing.T) {
api := New()
if _, err := api.CommerceListingsIds(); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions gw2api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gw2api
import (
"encoding/json"
"net/http"
"strconv"
"strings"
)

Expand Down Expand Up @@ -138,3 +139,17 @@ func genArgsString(ids ...string) string {
return concatStrings("?ids=", strings.Join(ids, ","))
}
}

// genArgsPagination generates the http arguments for pagination based on the given page and page size
// Official max page size is 200
func genArgsPagination(page, pageSize int) string {
if pageSize == 0 {
pageSize = 10
}

if pageSize > 200 {
pageSize = 200
}

return concatStrings("?page=", strconv.Itoa(page), "&page_size=", strconv.Itoa(pageSize))
}