mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-08 16:56:03 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4001fe5eac | ||
|
|
2992dd8f8b |
1524
CHANGELOG.md
1524
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -7,14 +7,49 @@ defmodule WandererAppWeb.APIController do
|
||||
alias WandererApp.MapSystemRepo
|
||||
alias WandererApp.MapCharacterSettingsRepo
|
||||
alias WandererApp.Api.Character
|
||||
alias WandererApp.CachedInfo
|
||||
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# SYSTEMS
|
||||
# Common
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
@doc """
|
||||
GET /api/system-static-info
|
||||
|
||||
Requires 'id' (the solar_system_id)
|
||||
|
||||
Example:
|
||||
GET /api/common/system_static?id=31002229
|
||||
GET /api/common/system_static?id=31002229
|
||||
"""
|
||||
def show_system_static(conn, params) do
|
||||
with {:ok, solar_system_str} <- require_param(params, "id"),
|
||||
{:ok, solar_system_id} <- parse_int(solar_system_str) do
|
||||
case CachedInfo.get_system_static_info(solar_system_id) do
|
||||
{:ok, system} ->
|
||||
data = static_system_to_json(system)
|
||||
json(conn, %{data: data})
|
||||
|
||||
{:error, :not_found} ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{error: "System not found"})
|
||||
end
|
||||
else
|
||||
{:error, msg} ->
|
||||
conn
|
||||
|> put_status(:bad_request)
|
||||
|> json(%{error: msg})
|
||||
end
|
||||
end
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Map
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
@doc """
|
||||
GET /api/systems
|
||||
GET /api/map/systems
|
||||
|
||||
Requires either `?map_id=<UUID>` **OR** `?slug=<map-slug>` in the query params.
|
||||
|
||||
@@ -22,9 +57,9 @@ If `?all=true` is provided, **all** systems are returned.
|
||||
Otherwise, only "visible" systems are returned.
|
||||
|
||||
Examples:
|
||||
GET /api/systems?map_id=466e922b-e758-485e-9b86-afae06b88363
|
||||
GET /api/systems?slug=my-unique-wormhole-map
|
||||
GET /api/systems?map_id=<UUID>&all=true
|
||||
GET /api/map/systems?map_id=466e922b-e758-485e-9b86-afae06b88363
|
||||
GET /api/map/systems?slug=my-unique-wormhole-map
|
||||
GET /api/map/systems?map_id=<UUID>&all=true
|
||||
"""
|
||||
def list_systems(conn, params) do
|
||||
with {:ok, map_id} <- fetch_map_id(params) do
|
||||
@@ -56,14 +91,14 @@ end
|
||||
|
||||
|
||||
@doc """
|
||||
GET /api/system
|
||||
GET /api/map/system
|
||||
|
||||
Requires 'id' (the solar_system_id)
|
||||
plus either ?map_id=<UUID> or ?slug=<map-slug>.
|
||||
|
||||
Example:
|
||||
GET /api/system?id=31002229&map_id=466e922b-e758-485e-9b86-afae06b88363
|
||||
GET /api/system?id=31002229&slug=my-unique-wormhole-map
|
||||
GET /api/map/system?id=31002229&map_id=466e922b-e758-485e-9b86-afae06b88363
|
||||
GET /api/map/system?id=31002229&slug=my-unique-wormhole-map
|
||||
"""
|
||||
def show_system(conn, params) do
|
||||
with {:ok, solar_system_str} <- require_param(params, "id"),
|
||||
@@ -87,16 +122,14 @@ end
|
||||
end
|
||||
end
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Characters
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
@doc """
|
||||
GET /api/tracked_characters_with_info
|
||||
GET /api/map/tracked_characters_with_info
|
||||
|
||||
Example usage:
|
||||
GET /api/tracked_characters_with_info?map_id=<uuid>
|
||||
GET /api/tracked_characters_with_info?slug=<map-slug>
|
||||
GET /api/map/tracked_characters_with_info?map_id=<uuid>
|
||||
GET /api/map/tracked_characters_with_info?slug=<map-slug>
|
||||
|
||||
Returns a list of tracked records, plus their fully-loaded `character` data.
|
||||
"""
|
||||
@@ -211,39 +244,65 @@ end
|
||||
end
|
||||
|
||||
defp map_system_to_json(system) do
|
||||
%{
|
||||
id: system.id,
|
||||
map_id: system.map_id,
|
||||
solar_system_id: system.solar_system_id,
|
||||
name: system.name,
|
||||
custom_name: system.custom_name,
|
||||
temporary_name: system.temporary_name,
|
||||
description: system.description,
|
||||
tag: system.tag,
|
||||
labels: system.labels,
|
||||
locked: system.locked,
|
||||
visible: system.visible,
|
||||
status: system.status,
|
||||
position_x: system.position_x,
|
||||
position_y: system.position_y,
|
||||
inserted_at: system.inserted_at,
|
||||
updated_at: system.updated_at
|
||||
}
|
||||
Map.take(system, [
|
||||
:id,
|
||||
:map_id,
|
||||
:solar_system_id,
|
||||
:name,
|
||||
:custom_name,
|
||||
:temporary_name,
|
||||
:description,
|
||||
:tag,
|
||||
:labels,
|
||||
:locked,
|
||||
:visible,
|
||||
:status,
|
||||
:position_x,
|
||||
:position_y,
|
||||
:inserted_at,
|
||||
:updated_at
|
||||
])
|
||||
end
|
||||
|
||||
defp character_to_json(ch) do
|
||||
%{
|
||||
id: ch.id,
|
||||
eve_id: ch.eve_id,
|
||||
name: ch.name,
|
||||
corporation_id: ch.corporation_id,
|
||||
corporation_name: ch.corporation_name,
|
||||
corporation_ticker: ch.corporation_ticker,
|
||||
alliance_id: ch.alliance_id,
|
||||
alliance_name: ch.alliance_name,
|
||||
alliance_ticker: ch.alliance_ticker,
|
||||
inserted_at: ch.inserted_at,
|
||||
updated_at: ch.updated_at
|
||||
}
|
||||
Map.take(ch, [
|
||||
:id,
|
||||
:eve_id,
|
||||
:name,
|
||||
:corporation_id,
|
||||
:corporation_name,
|
||||
:corporation_ticker,
|
||||
:alliance_id,
|
||||
:alliance_name,
|
||||
:alliance_ticker,
|
||||
:inserted_at,
|
||||
:updated_at
|
||||
])
|
||||
end
|
||||
|
||||
|
||||
defp static_system_to_json(system) do
|
||||
system
|
||||
|> Map.take([
|
||||
:solar_system_id,
|
||||
:region_id,
|
||||
:constellation_id,
|
||||
:solar_system_name,
|
||||
:solar_system_name_lc,
|
||||
:constellation_name,
|
||||
:region_name,
|
||||
:system_class,
|
||||
:security,
|
||||
:type_description,
|
||||
:class_title,
|
||||
:is_shattered,
|
||||
:effect_name,
|
||||
:effect_power,
|
||||
:statics,
|
||||
:wandering,
|
||||
:triglavian_invasion_status,
|
||||
:sun_type_id
|
||||
])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -107,23 +107,36 @@ defmodule WandererAppWeb.Router do
|
||||
pipeline :api do
|
||||
plug(:accepts, ["json"])
|
||||
plug WandererAppWeb.Plugs.CheckApiDisabled
|
||||
end
|
||||
|
||||
pipeline :api_map do
|
||||
plug WandererAppWeb.Plugs.CheckMapApiKey
|
||||
end
|
||||
|
||||
if not WandererApp.Env.public_api_disabled?() do
|
||||
scope "/api", WandererAppWeb do
|
||||
pipe_through [:api]
|
||||
scope "/api/map", WandererAppWeb do
|
||||
pipe_through [:api_map]
|
||||
pipe_through [:api]
|
||||
|
||||
# GET /api/systems?map_id=... or ?slug=...
|
||||
get "/systems", APIController, :list_systems
|
||||
# GET /api/map/systems?map_id=... or ?slug=...
|
||||
get "/systems", APIController, :list_systems
|
||||
|
||||
# GET /api/system?id=... plus either map_id=... or slug=...
|
||||
get "/system", APIController, :show_system
|
||||
# GET /api/map/system-static-info?id=... plus either map_id=... or slug=...
|
||||
get "/system-static-info", APIController, :show_system_static
|
||||
|
||||
# GET /api/characters?map_id=... or slug=...
|
||||
get "/characters", APIController, :tracked_characters_with_info
|
||||
end
|
||||
end
|
||||
# GET /api/map/system?id=... plus either map_id=... or slug=...
|
||||
get "/system", APIController, :show_system
|
||||
|
||||
# GET /api/map/characters?map_id=... or slug=...
|
||||
get "/characters", APIController, :tracked_characters_with_info
|
||||
end
|
||||
|
||||
scope "/api/common", WandererAppWeb do
|
||||
pipe_through [:api]
|
||||
|
||||
# GET /api/common/system-static-info?id=...
|
||||
get "/system-static-info", APIController, :show_system_static
|
||||
|
||||
end
|
||||
|
||||
scope "/", WandererAppWeb do
|
||||
pipe_through [:browser, :blog, :redirect_if_user_is_authenticated]
|
||||
|
||||
3
mix.exs
3
mix.exs
@@ -2,7 +2,8 @@ defmodule WandererApp.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
@source_url "https://github.com/wanderer-industries/wanderer"
|
||||
@version "1.35.0"
|
||||
|
||||
@version "1.36.0"
|
||||
|
||||
def project do
|
||||
[
|
||||
|
||||
@@ -20,20 +20,22 @@ As part of the Wanderer platform, a public API has been introduced to help users
|
||||
|
||||
## Authentication
|
||||
|
||||
Each request to the Wanderer API must include a valid API key in the `Authorization` header. The format is:
|
||||
Each request to the Wanderer APIs that being with /api/map must include a valid API key in the `Authorization` header. The format is:
|
||||
|
||||
Authorization: Bearer <YOUR_MAP_API_KEY>
|
||||
|
||||
If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` response.
|
||||
|
||||
No api key is required for routes that being with /api/common
|
||||
|
||||
---
|
||||
|
||||
## Endpoints Overview
|
||||
|
||||
### 1. List Systems
|
||||
|
||||
GET /api/systems?map_id=<UUID>
|
||||
GET /api/systems?slug=<map-slug>
|
||||
GET /api/map/systems?map_id=<UUID>
|
||||
GET /api/map/systems?slug=<map-slug>
|
||||
|
||||
- **Description:** Retrieves a list of systems associated with the specified map (by `map_id` or `slug`).
|
||||
- **Authentication:** Required via `Authorization` header.
|
||||
@@ -44,7 +46,7 @@ If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` re
|
||||
|
||||
#### Example Request
|
||||
```
|
||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/systems?slug=some-slug"
|
||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/map/systems?slug=some-slug"
|
||||
```
|
||||
#### Example Response
|
||||
```
|
||||
@@ -75,8 +77,8 @@ If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` re
|
||||
|
||||
### 2. Show Single System
|
||||
|
||||
GET /api/system?id=<SOLAR_SYSTEM_ID>&map_id=<UUID>
|
||||
GET /api/system?id=<SOLAR_SYSTEM_ID>&slug=<map-slug>
|
||||
GET /api/map/system?id=<SOLAR_SYSTEM_ID>&map_id=<UUID>
|
||||
GET /api/map/system?id=<SOLAR_SYSTEM_ID>&slug=<map-slug>
|
||||
|
||||
- **Description:** Retrieves information for a specific system on the specified map. You must provide:
|
||||
- `id` (the `solar_system_id`).
|
||||
@@ -85,7 +87,7 @@ If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` re
|
||||
|
||||
#### Example Request
|
||||
```
|
||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/system?id=<REDACTED_NUMBER>&slug=<REDACTED_SLUG>"
|
||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/map/system?id=<REDACTED_NUMBER>&slug=<REDACTED_SLUG>"
|
||||
```
|
||||
#### Example Response
|
||||
```
|
||||
@@ -111,17 +113,63 @@ If the API key is missing or incorrect, you’ll receive a `401 Unauthorized` re
|
||||
```
|
||||
---
|
||||
|
||||
### 2. Show Single System Static Info
|
||||
|
||||
GET /api/common/static-system-info?id=<SOLAR_SYSTEM_ID>
|
||||
|
||||
- **Description:** Retrieves the static information for a specific system.
|
||||
|
||||
- **Authentication:** No API token required
|
||||
|
||||
#### Example Request
|
||||
```
|
||||
curl "https://wanderer.example.com/api/common/static-system-info?id=31002229
|
||||
```
|
||||
#### Example Response
|
||||
```
|
||||
{
|
||||
"data": {
|
||||
"solar_system_id": 31002229,
|
||||
"triglavian_invasion_status": "Normal",
|
||||
"solar_system_name": "J132946",
|
||||
"system_class": 5,
|
||||
"region_id": 11000028,
|
||||
"constellation_id": 21000278,
|
||||
"solar_system_name_lc": "j132946",
|
||||
"constellation_name": "E-C00278",
|
||||
"region_name": "E-R00028",
|
||||
"security": "-1.0",
|
||||
"type_description": "Class 5",
|
||||
"class_title": "C5",
|
||||
"is_shattered": false,
|
||||
"effect_name": null,
|
||||
"effect_power": 5,
|
||||
"statics": [
|
||||
"H296"
|
||||
],
|
||||
"wandering": [
|
||||
"D792",
|
||||
"C140",
|
||||
"Z142"
|
||||
],
|
||||
"sun_type_id": 38
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
---
|
||||
|
||||
### 3. List Tracked Characters
|
||||
|
||||
GET /api/characters?map_id=<UUID>
|
||||
GET /api/characters?slug=<map-slug>
|
||||
GET /api/map/characters?map_id=<UUID>
|
||||
GET /api/map/characters?slug=<map-slug>
|
||||
|
||||
- **Description:** Retrieves a list of tracked characters for the specified map (by `map_id` or `slug`), including metadata such as corporation/alliance details.
|
||||
- **Authentication:** Required via `Authorization` header.
|
||||
|
||||
#### Example Request
|
||||
```
|
||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/characters?slug=some-slug"
|
||||
curl -H "Authorization: Bearer <REDACTED_TOKEN>" "https://wanderer.example.com/api/map/characters?slug=some-slug"
|
||||
```
|
||||
#### Example Response
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user