First tests of Planetery interaction

This commit is contained in:
Thomas Schwery 2017-01-30 08:16:34 +01:00
parent 59a549c298
commit 428eca4b5a

101
main.go
View file

@ -14,14 +14,16 @@ import (
"github.com/go-openapi/strfmt"
apiclient "client"
skillsclient "client/skills"
ESI "client"
ESIPlanetaryInteraction "client/planetary_interaction"
ESISkills "client/skills"
httptransport "github.com/go-openapi/runtime/client"
//"database/sql"
//_ "github.com/mattn/go-sqlite3"
)
// Character - Structure to save the verification data.
type Character struct {
CharacterID int32
CharacterName string
@ -36,6 +38,7 @@ var (
Scopes: []string{
"esi-skills.read_skillqueue.v1",
"esi-skills.read_skills.v1",
"esi-planets.manage_planets.v1",
},
Endpoint: oauth2.Endpoint{
AuthURL: "https://login.eveonline.com/oauth/authorize/",
@ -61,7 +64,7 @@ func main() {
m := getCharacterInfo(client)
fmt.Printf("Character id is %d\n", m.CharacterID)
getCharacterSkillQueue(client, m)
getCharacterPlanets(client, m)
}
func getCharacterInfo(client *http.Client) *Character {
@ -77,9 +80,9 @@ func getCharacterInfo(client *http.Client) *Character {
contents, _ := ioutil.ReadAll(response.Body)
var m Character
errJson := json.Unmarshal(contents, &m)
if errJson != nil {
fmt.Printf("JSON read error with '%s'\n", errJson)
errJSON := json.Unmarshal(contents, &m)
if errJSON != nil {
fmt.Printf("JSON read error with '%s'\n", errJSON)
return nil
}
@ -95,22 +98,88 @@ func getCharacterSkillQueue(client *http.Client, m *Character) {
transport := httptransport.NewWithClient("esi.tech.ccp.is", "/latest", []string{"https"}, client)
// create the API client, with the transport
swaggerclient := apiclient.New(transport, strfmt.Default)
swaggerclient := ESI.New(transport, strfmt.Default)
charIDSkilqueue := skillsclient.NewGetCharactersCharacterIDSkillqueueParams().WithCharacterID(m.CharacterID)
charIDSkilqueue := ESISkills.NewGetCharactersCharacterIDSkillqueueParams().WithCharacterID(m.CharacterID)
skillqueueresp, _ := swaggerclient.Skills.GetCharactersCharacterIDSkillqueue(charIDSkilqueue, nil)
skillqueue := skillqueueresp.Payload
for _, skill := range skillqueue {
// element is the element from someSlice for where we are
name := "UNK"
name := "UNK-SKILL"
level := skill.FinishedLevel
id := skill.SkillID
startDate := skill.StartDate
endDate := skill.FinishDate
fmt.Printf(" %s: %d\n %d - %s to %s\n\n", name, id, level, startDate, endDate)
fmt.Printf(" %s: %d (%d) - %s to %s\n", name, id, *level, startDate, endDate)
}
}
func getCharacterPlanets(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)
callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams().WithCharacterID(m.CharacterID)
esiresponse, _ := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanets(callParam, nil)
planets := esiresponse.Payload
for _, planet := range planets {
// element is the element from someSlice for where we are
name := "UNK-PLANET"
solarSystemName := "UNK-SYSTEM"
level := planet.UpgradeLevel
id := planet.PlanetID
solarSystem := planet.SolarSystemID
planetType := planet.PlanetType
lastUpdate := planet.LastUpdate
pins := planet.NumPins
pcallParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsPlanetIDParams().WithCharacterID(m.CharacterID).WithPlanetID(*id)
fmt.Printf(" %s (%d) %s (%d) - %s, level %d with %d structures - %s\n",
name, *id,
solarSystemName, *solarSystem,
*planetType,
*level, *pins,
lastUpdate,
)
pesiresponse, _ := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanetsPlanetID(pcallParam, nil)
for _, pin := range pesiresponse.Payload.Pins {
if pin.ExtractorDetails != nil {
fmt.Printf(" Extractor %d (%s), cycles of %d, %d per cycle\n",
*pin.PinID,
pin.LastCycleStart,
*pin.ExtractorDetails.CycleTime,
*pin.ExtractorDetails.QtyPerCycle,
)
} else if pin.SchematicID != 0 {
// Get the schematic from ESI and cache it
fmt.Printf(" Factory %d (%s) %d\n",
*pin.PinID,
pin.LastCycleStart,
pin.SchematicID,
)
} else {
/*
fmt.Printf(" %d %d (%s)\n%v\n",
*pin.TypeID,
*pin.PinID,
pin.LastCycleStart,
pin)
*/
}
}
}
}
@ -155,16 +224,16 @@ func handleAuthenticationCallback(w http.ResponseWriter, r *http.Request) {
client := googleOauthConfig.Client(oauth2.NoContext, token)
req, err := http.NewRequest("GET", "https://login.eveonline.com/oauth/verify", nil)
req, _ := http.NewRequest("GET", "https://login.eveonline.com/oauth/verify", nil)
response, _ := client.Do(req)
defer response.Body.Close()
contents, _ := ioutil.ReadAll(response.Body)
var m Character
errJson := json.Unmarshal(contents, &m)
if errJson != nil {
fmt.Printf("JSON read error with '%s'\n", errJson)
errJSON := json.Unmarshal(contents, &m)
if errJSON != nil {
fmt.Printf("JSON read error with '%s'\n", errJSON)
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
return
}
@ -172,6 +241,8 @@ func handleAuthenticationCallback(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Got token for character %s.\n", m.CharacterName)
fmt.Fprintf(w, "You can now close this navigator tab.\n")
log.Printf("Refresh token is %s\n", token.RefreshToken)
messages <- token
}
@ -204,7 +275,7 @@ func getDatabaseToken() *oauth2.Token {
log.Print("Using hardcoded refresh token")
token := new(oauth2.Token)
token.RefreshToken = "RZVPAbQpDq4qjwGwWNEHRssnfIEiD789B9nWWyZAZXcuQ2FhulkokZt21uNuRe7D0"
token.RefreshToken = "4sNssL9aVy6Sqf8JUT6Q1hPQjo1lpzJ0mrPIB417QFdz6YooWl9g78qaH2DkZVwq0"
token.TokenType = "Bearer"
return token