diff --git a/account.go b/account.go index e11a5ff..caf1d6e 100644 --- a/account.go +++ b/account.go @@ -204,3 +204,11 @@ func (gw2 *GW2Api) CharactersPage(page, pageSize int) (chars []Character, err er err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermCharacter, params, &chars) return } + +// AccountMinis returns the ids of all unlocked minis in the accounts collection +func (gw2 *GW2Api) AccountMinis() (minis []int, err error) { + ver := "v2" + tag := "account/minis" + err = gw2.fetchAuthenticatedEndpoint(ver, tag, PermUnlocks, nil, &minis) + return +} diff --git a/account_test.go b/account_test.go index 8c95708..47556df 100644 --- a/account_test.go +++ b/account_test.go @@ -156,3 +156,24 @@ func TestCharactersPage(t *testing.T) { t.Error("Fetched an unlikely number characters") } } + +func TestAccountMinis(t *testing.T) { + var apikey string + if apikey = os.Getenv("APIKEY"); len(apikey) < 1 { + t.Skip("Cannot test without APIKEY") + } + var api *GW2Api + var err error + if api, err = NewAuthenticatedGW2Api(apikey); err != nil { + t.Error(err) + } + if !api.HasPermission(PermUnlocks) { + t.Skip("API-Key does not have required permission for the test") + } + var minis []int + if minis, err = api.AccountMinis(); err != nil { + t.Error("Failed to parse the mini unlock data: ", err) + } else if len(minis) < 1 { + t.Error("Fetched an unlikely number of mini unlocks") + } +} diff --git a/misc.go b/misc.go index 1fdf1b0..edf4d90 100644 --- a/misc.go +++ b/misc.go @@ -195,3 +195,34 @@ func (gw2 *GW2Api) FileIds(ids ...string) (files []File, err error) { err = gw2.fetchEndpoint(ver, tag, params, &files) return } + +// Minis returns a list of all mini ids +func (gw2 *GW2Api) Minis() (res []int, err error) { + ver := "v2" + tag := "minis" + err = gw2.fetchEndpoint(ver, tag, nil, &res) + return +} + +// Mini has the basic information and the associated item id for the mini +type Mini struct { + ID int `json:"id"` + Name string `json:"name"` + Icon string `json:"icon"` + Order int `json:"order"` + ItemID int `json:"item_id"` +} + +// MiniIds returns the detailed information about requested minis localized to +// lang +func (gw2 *GW2Api) MiniIds(lang string, ids ...int) (minis []Mini, err error) { + ver := "v2" + tag := "minis" + params := url.Values{} + if lang != "" { + params.Add("lang", lang) + } + params.Add("ids", commaList(stringSlice(ids))) + err = gw2.fetchEndpoint(ver, tag, params, &minis) + return +} diff --git a/misc_test.go b/misc_test.go index e2e6787..9e6b53d 100644 --- a/misc_test.go +++ b/misc_test.go @@ -103,3 +103,20 @@ func TestFiles(t *testing.T) { t.Error("Failed to fetch existing files") } } + +func TestMinis(t *testing.T) { + var err error + api := NewGW2Api() + + var testMinis []int + if testMinis, err = api.Minis(); err != nil { + t.Error("Failed to fetch minis") + } + + var minis []Mini + if minis, err = api.MiniIds("en", testMinis[0:2]...); err != nil { + t.Error("Failed to parse the mini data: ", err) + } else if len(minis) != 2 { + t.Error("Failed to fetch existing minis") + } +}