Created
October 14, 2015 15:25
-
-
Save quiznilo1/ac3f45305a9cc4e5aea6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eve | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"github.com/go-resty/resty" | |
) | |
// Objects | |
const CRESTRoot = "https://public-crest.eveonline.com/" | |
const AllianceEP = "alliances/" | |
type CREST struct { | |
Root string | |
Version string | |
} | |
type Player struct { | |
} | |
type Corporation struct { | |
Name string `json:"name"` | |
Ticker string `json:"shortName"` | |
ID uint64 `json:"id"` | |
CLink string `json:"href"` | |
} | |
type Alliance struct { | |
Name string `json:"name"` | |
Ticker string `json:"shortName"` | |
Id uint64 `json:"id"` | |
CLink string `json:"href"` | |
Members []Corporation | |
} | |
var AllAlliances []Alliance | |
func GetAllAlliances() []Alliance { | |
/* | |
resp, err := resty.R().Get(CRESTRoot + AllianceEP) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
fmt.Printf("Response Body: %s\n\n", resp) | |
*/ | |
return GetAlliancePage(CRESTRoot+AllianceEP, []Alliance{}) | |
} | |
func GetAlliancePage(root string, sofar []Alliance) []Alliance { | |
fmt.Println("Getting alliances...") | |
type Response struct { | |
PageCount int `json:"pageCount"` | |
Items []Alliance `json:"items"` | |
NextPage string `json:"next"` | |
TotalCount int `json:"totalCount"` | |
} | |
resp, err := resty.R().Get(root) | |
if err != nil { | |
log.Fatalln(err) | |
} | |
var r Response | |
if err := json.Unmarshal([]byte(resp.String()), &r); err != nil { | |
log.Fatalln(err) | |
} | |
fmt.Println("Success") | |
for _, k := range r.Items { | |
fmt.Println(k) | |
sofar = append(sofar, k) | |
} | |
if r.NextPage != "" { | |
return GetAlliancePage(r.NextPage, sofar) | |
} | |
return sofar | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment