diff --git a/types/user.go b/types/user.go index debade6..96716f4 100644 --- a/types/user.go +++ b/types/user.go @@ -44,6 +44,15 @@ type VaultInfo struct { ModifiedDate time.Time `json:"modified_date"` } +type Fleets struct { + Next string `json:"next"` + Previous string `json:"previous"` + Page int `json:"page"` + Last int `json:"last"` + Count int `json:"count"` + Results []Fleet `json:"results"` +} + type Fleet struct { ID uuid.UUID `json:"id"` Name string `json:"name"` diff --git a/util/util.go b/util/util.go index 7d46901..f9a735b 100644 --- a/util/util.go +++ b/util/util.go @@ -100,15 +100,38 @@ func GetMe() *types.User { } func GetFleetInfo() *types.Fleet { - resp := request.Trickest.Get().DoF("fleet/%s", GetVault()) + fleet := GetFleetInfoLegacy() + if fleet != nil { + return fleet + } + resp := request.Trickest.Get().DoF("fleet/?vault=%s", GetVault()) if resp == nil || resp.Status() != http.StatusOK { request.ProcessUnexpectedResponse(resp) } + var fleets types.Fleets + err := json.Unmarshal(resp.Body(), &fleets) + if err != nil { + fmt.Println("Error unmarshalling fleet response!") + return nil + } + + if len(fleets.Results) == 0 { + fmt.Println("Error: Couldn't find any active fleets") + } + + return &fleets.Results[0] +} + +func GetFleetInfoLegacy() *types.Fleet { + resp := request.Trickest.Get().DoF("fleet/%s", GetVault()) + if resp == nil || resp.Status() != http.StatusOK { + return nil + } + var fleet types.Fleet err := json.Unmarshal(resp.Body(), &fleet) if err != nil { - fmt.Println("Error unmarshalling fleet response!") return nil }