rename one function in map_usecase file, update README.md
This commit is contained in:
parent
52e04a7399
commit
ef71302e9a
102
README.md
102
README.md
|
@ -1,6 +1,106 @@
|
|||
# TWHelp API
|
||||
|
||||
Graphql API for TribalWars servers data.
|
||||
The main problem with data published by the TribalWars team is that they give you them in .csv format, then you must parse it to your programming language data structure if you want to use it in your code. Have you ever encountered this problem? Then you should try this GraphQL API written in Go. You don't need to parse world data anymore! Fetch data in JSON format from TWHelp API. All TribalWars versions are available.
|
||||
|
||||
## API Limits
|
||||
|
||||
You can fetch in one HTTP request:
|
||||
|
||||
1. 1000 daily player/tribe stats
|
||||
2. 100 ennoblements
|
||||
3. 100 lang versions
|
||||
4. 100 players/tribes
|
||||
5. 1000 villages
|
||||
6. 100 player/tribe history records
|
||||
7. 100 servers
|
||||
8. 60 server stats
|
||||
9. 100 tribe changes
|
||||
|
||||
## Sample queries
|
||||
|
||||
You can check how to make requests from JavaScript script [here](https://github.com/tribalwarshelp/scripts).
|
||||
|
||||
1. All barbarian villages with 10% more population
|
||||
|
||||
```graphql
|
||||
query {
|
||||
villages(server: "en115", filter: { playerID: [0], bonus: 4 }) {
|
||||
total
|
||||
items {
|
||||
id
|
||||
name
|
||||
x
|
||||
y
|
||||
points
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. Top 30 players without a tribe, ordered by points.
|
||||
|
||||
```graphql
|
||||
query {
|
||||
players(
|
||||
server: "pl148"
|
||||
filter: { tribeID: [0], sort: "points DESC", limit: 30 }
|
||||
) {
|
||||
total
|
||||
items {
|
||||
id
|
||||
name
|
||||
rank
|
||||
points
|
||||
totalVillages
|
||||
rankAtt
|
||||
rankDef
|
||||
rankTotal
|
||||
rankSup
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. Search a player by a nickname fragment.
|
||||
|
||||
```graphql
|
||||
query {
|
||||
players(server: "pl148", filter: { nameIEQ: "%pablo%" }) {
|
||||
total
|
||||
items {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Map service
|
||||
|
||||
You can generate a server map with this API. The current endpoint is https://api.tribalwarshelp.com/map/server (replace "server" with the world you're interested in, for example, en115).
|
||||
|
||||
### Available query params:
|
||||
|
||||
| Param | Default |
|
||||
| ------------------------------------------------ | ---------------------------------------------------------- |
|
||||
| showBarbarians | false |
|
||||
| largerMarkers | false |
|
||||
| onlyMarkers | false |
|
||||
| centerX | 500 |
|
||||
| centerY | 500 |
|
||||
| scale | 1 (max 5) |
|
||||
| showGrid | false |
|
||||
| showContinentNumbers | false |
|
||||
| backgroundColor | #000 |
|
||||
| gridLineColor | #fff |
|
||||
| continentNumberColor | #fff |
|
||||
| tribe(this param you can define multiple times) | format tribeid,hexcolor (for example, tribe=631,#0000ff) |
|
||||
| player(this param you can define multiple times) | format playerid,hexcolor (for example, player=631,#0000ff) |
|
||||
|
||||
### Example
|
||||
|
||||
**pl151**
|
||||
![Map](https://api.tribalwarshelp.com/map/pl151?showBarbarian=true&tribe=124,%230000ff&tribe=631,%230000ff&tribe=1675,%230000ff&onlyMarkers=false&scale=1&showGrid=true&showContinentNumbers=true)
|
||||
|
||||
## Development
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ func (ucase *usecase) GetMarkers(ctx context.Context, cfg servermap.GetMarkersCo
|
|||
cache := make(map[int]bool)
|
||||
for _, data := range cfg.Tribes {
|
||||
//id,#color
|
||||
id, color, err := parseQueryParam(data)
|
||||
id, color, err := parseMarker(data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "tribe=%s", data)
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func (ucase *usecase) GetMarkers(ctx context.Context, cfg servermap.GetMarkersCo
|
|||
cache = make(map[int]bool)
|
||||
for _, data := range cfg.Players {
|
||||
//id,#color
|
||||
id, color, err := parseQueryParam(data)
|
||||
id, color, err := parseMarker(data)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "player=%s", data)
|
||||
}
|
||||
|
@ -181,17 +181,18 @@ func (ucase *usecase) GetMarkers(ctx context.Context, cfg servermap.GetMarkersCo
|
|||
return markers, err
|
||||
}
|
||||
|
||||
func parseQueryParam(str string) (int, string, error) {
|
||||
func parseMarker(str string) (int, string, error) {
|
||||
splitted := strings.Split(str, ",")
|
||||
if len(splitted) != 2 {
|
||||
return 0, "", fmt.Errorf("Invalid format (should be id,#hexcolor)")
|
||||
return 0, "", fmt.Errorf("%s: Invalid marker format (should be id,#hexcolor)", str)
|
||||
}
|
||||
id, err := strconv.Atoi(splitted[0])
|
||||
if err != nil {
|
||||
return 0, "", errors.Wrapf(err, "Invalid format (should be id,hexcolor)")
|
||||
return 0, "", errors.Wrapf(err, "%s: Invalid marker format (should be id,#hexcolor)", str)
|
||||
}
|
||||
if id <= 0 {
|
||||
return 0, "", fmt.Errorf("ID should be greater than 0")
|
||||
}
|
||||
|
||||
return id, splitted[1], nil
|
||||
}
|
||||
|
|
Reference in New Issue