Skip to content

Commit

Permalink
minis endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw committed Nov 10, 2015
1 parent 11a7a44 commit f1072ee
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
21 changes: 21 additions & 0 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
31 changes: 31 additions & 0 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 17 additions & 0 deletions misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit f1072ee

Please sign in to comment.