diff --git a/main.go b/main.go index 962495f..239e2b8 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "net/http" + "errors" "fmt" "log" "os" @@ -89,13 +90,16 @@ func main() { } } - printCharacterInformation(client, m) + transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client) + swaggerclient := ESI.New(transport, strfmt.Default) + + printCharacterInformation(swaggerclient, m) fmt.Printf("\n\nPlanetary interaction\n") - printCharacterPlanets(client, m) + printCharacterPlanets(swaggerclient, m) fmt.Printf("\n\nSkill queue\n") - printCharacterSkillQueue(client, m) + printCharacterSkillQueue(swaggerclient, m) } func getCharacterInfo(client *http.Client) (*Character, error) { @@ -112,22 +116,23 @@ func getCharacterInfo(client *http.Client) (*Character, error) { var m Character errJSON := json.Unmarshal(contents, &m) if errJSON != nil { + log.Printf("Unmarshalling error: %s\n", errJSON) return nil, errJSON } + if m.CharacterID == 0 || m.CharacterName == "" { + log.Printf("Invalid return value from verify call: %s", contents) + return nil, errors.New("Invalid token") + } + return &m, nil } -func printCharacterSkillQueue(client *http.Client, m *Character) { +func printCharacterSkillQueue(swaggerclient *ESI.App, m *Character) { + callParam := ESISkills.NewGetCharactersCharacterIDSkillqueueParams() + callParam.WithCharacterID(m.CharacterID) - // create the transport - transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client) - - // create the API client, with the transport - swaggerclient := ESI.New(transport, strfmt.Default) - - charIDSkilqueue := ESISkills.NewGetCharactersCharacterIDSkillqueueParams().WithCharacterID(m.CharacterID) - skillqueueresp, skillerr := swaggerclient.Skills.GetCharactersCharacterIDSkillqueue(charIDSkilqueue, nil) + skillqueueresp, skillerr := swaggerclient.Skills.GetCharactersCharacterIDSkillqueue(callParam, nil) if skillerr != nil { log.Fatalf("Error on GetCharactersCharacterIDSkillqueue\n%s\n", skillerr) } @@ -168,18 +173,13 @@ func printCharacterSkillQueue(client *http.Client, m *Character) { } } -func printCharacterInformation(client *http.Client, m *Character) { - // create the transport - transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client) - - // create the API client, with the transport - swaggerclient := ESI.New(transport, strfmt.Default) - +func printCharacterInformation(swaggerclient *ESI.App, m *Character) { callParam := ESIWallet.NewGetCharactersCharacterIDWalletsParams() callParam.WithCharacterID(m.CharacterID) esiresponse, esierr := swaggerclient.Wallet.GetCharactersCharacterIDWallets(callParam, nil) if esierr != nil { + fmt.Println("Error while getting the wallet information") log.Fatalf("Got error on GetCharactersCharacterIDWallets: %s", esierr) } @@ -196,16 +196,16 @@ func printCharacterInformation(client *http.Client, m *Character) { } } -func printCharacterPlanets(client *http.Client, m *Character) { +func printCharacterPlanets(swaggerclient *ESI.App, m *Character) { - // create the transport - transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client) + callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams() + callParam.WithCharacterID(m.CharacterID) - // create the API client, with the transport - swaggerclient := ESI.New(transport, strfmt.Default) - - callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams().WithCharacterID(m.CharacterID) - esiresponse, _ := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanets(callParam, nil) + esiresponse, esierr := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanets(callParam, nil) + if esierr != nil { + fmt.Println("Error while getting the planetary interaction information.") + log.Fatalf("Got error on GetCharactersCharacterIDPlanets: %s", esierr) + } planets := esiresponse.Payload @@ -229,11 +229,12 @@ func printCharacterPlanets(client *http.Client, m *Character) { solarSystemInfo.SolarSystemName, *planet.PlanetType, *planet.UpgradeLevel, *planet.NumPins, - planet.LastUpdate, + time.Time(*planet.LastUpdate).Format("_2 Jan 2006, 15:04"), ) pesiresponse, pesierr := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanetsPlanetID(pcallParam, nil) if pesierr != nil { + fmt.Println("Error while getting the planetary interaction information") log.Fatalf("Error on CharactersCharacterIDPlanetsPlanetID: %s", pesierr) } for _, pin := range pesiresponse.Payload.Pins { @@ -511,11 +512,11 @@ func putCacheData(key string, value string) { func getDatabaseToken() *oauth2.Token { refreshToken := getCachedData("refreshToken") - accessToken := getCachedData("accessToken") + //accessToken := getCachedData("accessToken") token := new(oauth2.Token) token.RefreshToken = refreshToken - token.AccessToken = accessToken + //token.AccessToken = accessToken token.TokenType = "Bearer" return token