summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--esi.go35
-rw-r--r--models.go16
-rw-r--r--storage.go11
3 files changed, 62 insertions, 0 deletions
diff --git a/esi.go b/esi.go
new file mode 100644
index 0000000..f50eb4d
--- /dev/null
+++ b/esi.go
@@ -0,0 +1,35 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "net/http"
+)
+
+func GetKillmail(id uint64, hash string) (EsiKillmail, error) {
+ r, err := http.Get(fmt.Sprintf("https://esi.evetech.net/latest/killmails/%d/%s/", id, hash))
+ if err != nil {
+ return EsiKillmail{}, err
+ }
+ decoder := json.NewDecoder(r.Body)
+ var details EsiKillmail
+ if err := decoder.Decode(&details); err != nil {
+ return EsiKillmail{}, err
+ }
+
+ return details, nil
+}
+
+func GetSolarSystem(id int32) (EsiUniverseSystem, error) {
+ r, err := http.Get(fmt.Sprintf("https://esi.evetech.net/latest/universe/systems/%d/", id))
+ if err != nil {
+ return EsiUniverseSystem{}, err
+ }
+ decoder := json.NewDecoder(r.Body)
+ var details EsiUniverseSystem
+ if err := decoder.Decode(&details); err != nil {
+ return EsiUniverseSystem{}, err
+ }
+
+ return details, nil
+}
diff --git a/models.go b/models.go
index 9a0a67f..95c30c8 100644
--- a/models.go
+++ b/models.go
@@ -16,4 +16,20 @@ type Battle struct {
LastModified time.Time `json:"-"`
Teams [2]Team `json:"teams"`
Killmails []Killmail `json:"killmails"`
+ Name string `json:"name"`
+}
+
+type EsiKillmail struct {
+ SolarSystemId int32 `json:"solar_system_id"`
+ Victim struct {
+ Position struct {
+ X float64 `json:"x"`
+ Y float64 `json:"y"`
+ Z float64 `json:"z"`
+ } `json:"position"`
+ } `json:"victim"`
+}
+
+type EsiUniverseSystem struct {
+ Name string `json:"name"`
}
diff --git a/storage.go b/storage.go
index 75108ac..9a8b8fc 100644
--- a/storage.go
+++ b/storage.go
@@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
+ "fmt"
"io"
"io/ioutil"
"net/http"
@@ -68,6 +69,16 @@ func (s *Storage) AddBattle(battle *Battle) error {
return errors.New("missing killmails")
}
battle.CalculateHash()
+ killmail := battle.Killmails[0]
+ details, err := GetKillmail(killmail.Id, killmail.Hash)
+ if err != nil {
+ return err
+ }
+ system, err := GetSolarSystem(details.SolarSystemId)
+ if err != nil {
+ return err
+ }
+ battle.Name = fmt.Sprintf("Battle in %s", system.Name)
data, err := json.Marshal(battle)
if err != nil {
return err