Compare commits
No commits in common. "main" and "v1.1.0" have entirely different histories.
127 changed files with 1266 additions and 1110 deletions
|
@ -7,11 +7,12 @@
|
|||
gleam add spacetraders_sdk@1
|
||||
```
|
||||
```gleam
|
||||
import spacetraders_api
|
||||
import spacetraders_sdk
|
||||
|
||||
pub fn main() -> Nil {
|
||||
let assert Ok(server_status) = spacetraders_api.get_server_status()
|
||||
io.println(server_status.status)
|
||||
let assert Ok(server_status) = get_server_status()
|
||||
echo server_status
|
||||
Nil
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name = "spacetraders_sdk"
|
||||
version = "1.5.5"
|
||||
version = "1.1.0"
|
||||
gleam = ">= 1.11.0"
|
||||
description = "A Gleam SDK for the spacetraders.io game API"
|
||||
licences = ["MIT"]
|
||||
|
|
69
src/endpoints/accounts.gleam
Normal file
69
src/endpoints/accounts.gleam
Normal file
|
@ -0,0 +1,69 @@
|
|||
import gleam/dynamic/decode
|
||||
import gleam/json
|
||||
import models/account.{type Account}
|
||||
import models/agent.{type Agent}
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/contract.{type Contract}
|
||||
import models/faction.{type Faction}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import models/ship.{type Ship}
|
||||
import utils/api.{type ApiResponse}
|
||||
import utils/auth.{type AccountToken, type AgentToken, AccountAuth, AgentAuth}
|
||||
|
||||
pub fn get_account(token: AgentToken) -> ApiResponse(Account) {
|
||||
let request = api.get(AgentAuth(token), "/my/account")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(
|
||||
response,
|
||||
decode.field("account", account.decoder(), decode.success),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type AgentRegistered {
|
||||
AgentRegistered(
|
||||
token: AgentToken,
|
||||
agent: Agent,
|
||||
faction: Faction,
|
||||
contract: Contract,
|
||||
ships: List(Ship),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn register_new_agent(
|
||||
token: AccountToken,
|
||||
agent_symbol: AgentSymbol,
|
||||
faction_symbol: FactionSymbol,
|
||||
) -> ApiResponse(AgentRegistered) {
|
||||
let request =
|
||||
api.post_json(
|
||||
AccountAuth(token),
|
||||
"/register",
|
||||
json.object([
|
||||
#("symbol", agent_symbol.encode(agent_symbol)),
|
||||
#("faction", faction_symbol.encode(faction_symbol)),
|
||||
]),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
201 ->
|
||||
api.parse_data_response(response, {
|
||||
use token <- decode.field("token", auth.agent_token_decoder())
|
||||
use agent <- decode.field("agent", agent.decoder())
|
||||
use faction <- decode.field("faction", faction.decoder())
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use ships <- decode.field("ships", decode.list(ship.decoder()))
|
||||
decode.success(AgentRegistered(
|
||||
token:,
|
||||
agent:,
|
||||
faction:,
|
||||
contract:,
|
||||
ships:,
|
||||
))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
59
src/endpoints/agents.gleam
Normal file
59
src/endpoints/agents.gleam
Normal file
|
@ -0,0 +1,59 @@
|
|||
import gleam/dynamic/decode
|
||||
import gleam/option.{type Option}
|
||||
import models/agent.{type Agent}
|
||||
import models/agent_event.{type AgentEvent}
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/public_agent.{type PublicAgent}
|
||||
import utils/api.{type ApiResponse, type PagedData}
|
||||
import utils/auth.{type AgentToken, AgentAuth}
|
||||
|
||||
pub fn list_public_agents(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(PublicAgent))) {
|
||||
let request = api.get_page(AgentAuth(token), "/agents", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(
|
||||
response,
|
||||
decode.list(public_agent.decoder()),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_public_agent(
|
||||
token: AgentToken,
|
||||
agent_symbol: AgentSymbol,
|
||||
) -> ApiResponse(PublicAgent) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/agents/" <> agent_symbol.to_string(agent_symbol),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, public_agent.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_agent(token: AgentToken) -> ApiResponse(Agent) {
|
||||
let request = api.get(AgentAuth(token), "/my/agent")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, agent.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_agent_events(token: AgentToken) -> ApiResponse(List(AgentEvent)) {
|
||||
let request = api.get(AgentAuth(token), "/my/agent/events")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, decode.list(agent_event.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
127
src/endpoints/contracts.gleam
Normal file
127
src/endpoints/contracts.gleam
Normal file
|
@ -0,0 +1,127 @@
|
|||
import endpoints/fleet
|
||||
import gleam/dynamic/decode
|
||||
import gleam/json
|
||||
import gleam/option.{type Option}
|
||||
import models/agent.{type Agent}
|
||||
import models/contract.{type Contract}
|
||||
import models/contract_id.{type ContractId}
|
||||
import models/ship_cargo.{type ShipCargo}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import utils/api.{type ApiResponse, type PagedData}
|
||||
import utils/auth.{type AgentToken, AgentAuth}
|
||||
|
||||
pub fn list_contracts(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(Contract))) {
|
||||
let request = api.get_page(AgentAuth(token), "/my/contracts", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(response, decode.list(contract.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(Contract) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/my/contracts/" <> contract_id.to_string(contract_id),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, contract.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ContractAccepted {
|
||||
ContractAccepted(contract: Contract, agent: Agent)
|
||||
}
|
||||
|
||||
pub fn accept_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(ContractAccepted) {
|
||||
let request =
|
||||
api.post(
|
||||
AgentAuth(token),
|
||||
"/my/contracts/" <> contract_id.to_string(contract_id) <> "/accept",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use agent <- decode.field("agent", agent.decoder())
|
||||
decode.success(ContractAccepted(contract:, agent:))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ContractFulfilled {
|
||||
ContractFulfilled(contract: Contract, agent: Agent)
|
||||
}
|
||||
|
||||
pub fn fulfill_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(ContractFulfilled) {
|
||||
let request =
|
||||
api.post(
|
||||
AgentAuth(token),
|
||||
"/my/contracts/" <> contract_id.to_string(contract_id) <> "/fulfill",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use agent <- decode.field("agent", agent.decoder())
|
||||
decode.success(ContractFulfilled(contract:, agent:))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ContractCargoDelivered {
|
||||
ContractCargoDelivered(contract: Contract, cargo: ShipCargo)
|
||||
}
|
||||
|
||||
pub fn deliver_contract_cargo(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
ship_symbol: ShipSymbol,
|
||||
trade_symbol: TradeSymbol,
|
||||
units: Int,
|
||||
) -> ApiResponse(ContractCargoDelivered) {
|
||||
let request =
|
||||
api.post_json(
|
||||
AgentAuth(token),
|
||||
"/my/contracts/" <> contract_id.to_string(contract_id) <> "/deliver",
|
||||
json.object([
|
||||
#("shipSymbol", ship_symbol.encode(ship_symbol)),
|
||||
#("tradeSymbol", trade_symbol.encode(trade_symbol)),
|
||||
#("units", json.int(units)),
|
||||
]),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
||||
decode.success(ContractCargoDelivered(contract:, cargo:))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub const negotiate_contract = fleet.negotiate_contract
|
28
src/endpoints/data.gleam
Normal file
28
src/endpoints/data.gleam
Normal file
|
@ -0,0 +1,28 @@
|
|||
import gleam/dict.{type Dict}
|
||||
import gleam/dynamic/decode
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import utils/api.{type ApiResponse}
|
||||
import utils/auth.{NoAuth}
|
||||
|
||||
pub type ExportToImportMap =
|
||||
Dict(TradeSymbol, List(TradeSymbol))
|
||||
|
||||
pub fn get_supply_chain() -> ApiResponse(ExportToImportMap) {
|
||||
let request = api.get(NoAuth, "/market/supply-chain")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(
|
||||
response,
|
||||
decode.field(
|
||||
"exportToImportMap",
|
||||
decode.dict(
|
||||
trade_symbol.decoder(),
|
||||
decode.list(trade_symbol.decoder()),
|
||||
),
|
||||
decode.success,
|
||||
),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
60
src/endpoints/factions.gleam
Normal file
60
src/endpoints/factions.gleam
Normal file
|
@ -0,0 +1,60 @@
|
|||
import gleam/dynamic/decode
|
||||
import gleam/option.{type Option}
|
||||
import models/faction.{type Faction}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import utils/api.{type ApiResponse, type PagedData}
|
||||
import utils/auth.{type AgentToken, AgentAuth}
|
||||
|
||||
pub fn list_factions(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(Faction))) {
|
||||
let request = api.get_page(AgentAuth(token), "/factions", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(response, decode.list(faction.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_faction(
|
||||
token: AgentToken,
|
||||
symbol: FactionSymbol,
|
||||
) -> ApiResponse(Faction) {
|
||||
let request =
|
||||
api.get(AgentAuth(token), "/factions/" <> faction_symbol.to_string(symbol))
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, faction.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type FactionReputation {
|
||||
FactionReputation(symbol: FactionSymbol, reputation: Int)
|
||||
}
|
||||
|
||||
fn faction_reputation_decoder() {
|
||||
use symbol <- decode.field("symbol", faction_symbol.decoder())
|
||||
use reputation <- decode.field("reputation", decode.int)
|
||||
decode.success(FactionReputation(symbol:, reputation:))
|
||||
}
|
||||
|
||||
pub fn get_my_factions(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(FactionReputation))) {
|
||||
let request = api.get_page(AgentAuth(token), "/my/factions", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(
|
||||
response,
|
||||
decode.list(faction_reputation_decoder()),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
|
@ -1,356 +1,42 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dict.{type Dict}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/json
|
||||
import gleam/list
|
||||
import gleam/option.{type Option}
|
||||
import gleam/uri.{type Uri}
|
||||
import spacetraders_models/account.{type Account}
|
||||
import spacetraders_models/agent.{type Agent}
|
||||
import spacetraders_models/agent_event.{type AgentEvent}
|
||||
import spacetraders_models/agent_symbol.{type AgentSymbol}
|
||||
import spacetraders_models/chart.{type Chart}
|
||||
import spacetraders_models/chart_transaction.{type ChartTransaction}
|
||||
import spacetraders_models/construction.{type Construction}
|
||||
import spacetraders_models/contract.{type Contract}
|
||||
import spacetraders_models/contract_id.{type ContractId}
|
||||
import spacetraders_models/cooldown.{type Cooldown}
|
||||
import spacetraders_models/extraction.{type Extraction}
|
||||
import spacetraders_models/faction.{type Faction}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_models/jump_gate.{type JumpGate}
|
||||
import spacetraders_models/market.{type Market}
|
||||
import spacetraders_models/market_transaction.{type MarketTransaction}
|
||||
import spacetraders_models/module_symbol.{type ModuleSymbol}
|
||||
import spacetraders_models/mount_symbol.{type MountSymbol}
|
||||
import spacetraders_models/public_agent.{type PublicAgent}
|
||||
import spacetraders_models/refinement_produce.{type RefinementProduce}
|
||||
import spacetraders_models/refinement_yield.{type RefinementYield}
|
||||
import spacetraders_models/repair_transaction.{type RepairTransaction}
|
||||
import spacetraders_models/scanned_ship.{type ScannedShip}
|
||||
import spacetraders_models/scanned_system.{type ScannedSystem}
|
||||
import spacetraders_models/scanned_waypoint.{type ScannedWaypoint}
|
||||
import spacetraders_models/scrap_transaction.{type ScrapTransaction}
|
||||
import spacetraders_models/ship.{type Ship}
|
||||
import spacetraders_models/ship_cargo.{type ShipCargo}
|
||||
import spacetraders_models/ship_condition_event.{type ShipConditionEvent}
|
||||
import spacetraders_models/ship_fuel.{type ShipFuel}
|
||||
import spacetraders_models/ship_modification_transaction.{
|
||||
type ShipModificationTransaction,
|
||||
}
|
||||
import spacetraders_models/ship_module.{type ShipModule}
|
||||
import spacetraders_models/ship_mount.{type ShipMount}
|
||||
import spacetraders_models/ship_nav.{type ShipNav}
|
||||
import spacetraders_models/ship_nav_flight_mode.{type ShipNavFlightMode}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/ship_type.{type ShipType}
|
||||
import spacetraders_models/shipyard.{type Shipyard}
|
||||
import spacetraders_models/shipyard_transaction.{type ShipyardTransaction}
|
||||
import spacetraders_models/siphon.{type Siphon}
|
||||
import spacetraders_models/survey.{type Survey}
|
||||
import spacetraders_models/system.{type System}
|
||||
import spacetraders_models/system_symbol.{type SystemSymbol}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_models/waypoint.{type Waypoint}
|
||||
import spacetraders_models/waypoint_modifier.{type WaypointModifier}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_models/waypoint_trait_symbol.{type WaypointTraitSymbol}
|
||||
import spacetraders_models/waypoint_type.{type WaypointType}
|
||||
import spacetraders_sdk.{
|
||||
type AccountToken, type AgentToken, type ApiResponse, type PagedData,
|
||||
AccountAuth, AgentAuth, NoAuth,
|
||||
}
|
||||
import spacetraders_sdk/internal/api
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
pub fn get_account(token: AgentToken) -> ApiResponse(Account) {
|
||||
let request = api.get(AgentAuth(token), "/my/account")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(
|
||||
response,
|
||||
decode.field("account", account.decoder(), decode.success),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type AgentRegistered {
|
||||
AgentRegistered(
|
||||
token: AgentToken,
|
||||
agent: Agent,
|
||||
faction: Faction,
|
||||
contract: Contract,
|
||||
ships: List(Ship),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn register_new_agent(
|
||||
token: AccountToken,
|
||||
agent_symbol: AgentSymbol,
|
||||
faction_symbol: FactionSymbol,
|
||||
) -> ApiResponse(AgentRegistered) {
|
||||
let request =
|
||||
api.post_json(
|
||||
AccountAuth(token),
|
||||
"/register",
|
||||
json.object([
|
||||
#("symbol", agent_symbol.encode(agent_symbol)),
|
||||
#("faction", faction_symbol.encode(faction_symbol)),
|
||||
]),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
201 ->
|
||||
api.parse_data_response(response, {
|
||||
use token <- decode.field(
|
||||
"token",
|
||||
spacetraders_sdk.agent_token_decoder(),
|
||||
)
|
||||
use agent <- decode.field("agent", agent.decoder())
|
||||
use faction <- decode.field("faction", faction.decoder())
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use ships <- decode.field("ships", decode.list(ship.decoder()))
|
||||
decode.success(AgentRegistered(
|
||||
token:,
|
||||
agent:,
|
||||
faction:,
|
||||
contract:,
|
||||
ships:,
|
||||
))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn list_public_agents(
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(PublicAgent))) {
|
||||
let request = api.get_page(NoAuth, "/agents", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(
|
||||
response,
|
||||
decode.list(public_agent.decoder()),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_public_agent(agent_symbol: AgentSymbol) -> ApiResponse(PublicAgent) {
|
||||
let request =
|
||||
api.get(NoAuth, "/agents/" <> agent_symbol.to_string(agent_symbol))
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, public_agent.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_agent(token: AgentToken) -> ApiResponse(Agent) {
|
||||
let request = api.get(AgentAuth(token), "/my/agent")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, agent.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_agent_events(token: AgentToken) -> ApiResponse(List(AgentEvent)) {
|
||||
let request = api.get(AgentAuth(token), "/my/agent/events")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, decode.list(agent_event.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn list_contracts(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(Contract))) {
|
||||
let request = api.get_page(AgentAuth(token), "/my/contracts", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(response, decode.list(contract.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(Contract) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/my/contracts/" <> contract_id.to_string(contract_id),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, contract.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ContractAccepted {
|
||||
ContractAccepted(contract: Contract, agent: Agent)
|
||||
}
|
||||
|
||||
pub fn accept_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(ContractAccepted) {
|
||||
let request =
|
||||
api.post(
|
||||
AgentAuth(token),
|
||||
"/my/contracts/" <> contract_id.to_string(contract_id) <> "/accept",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use agent <- decode.field("agent", agent.decoder())
|
||||
decode.success(ContractAccepted(contract:, agent:))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ContractFulfilled {
|
||||
ContractFulfilled(contract: Contract, agent: Agent)
|
||||
}
|
||||
|
||||
pub fn fulfill_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(ContractFulfilled) {
|
||||
let request =
|
||||
api.post(
|
||||
AgentAuth(token),
|
||||
"/my/contracts/" <> contract_id.to_string(contract_id) <> "/fulfill",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use agent <- decode.field("agent", agent.decoder())
|
||||
decode.success(ContractFulfilled(contract:, agent:))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ContractCargoDelivered {
|
||||
ContractCargoDelivered(contract: Contract, cargo: ShipCargo)
|
||||
}
|
||||
|
||||
pub fn deliver_contract_cargo(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
ship_symbol: ShipSymbol,
|
||||
trade_symbol: TradeSymbol,
|
||||
units: Int,
|
||||
) -> ApiResponse(ContractCargoDelivered) {
|
||||
let request =
|
||||
api.post_json(
|
||||
AgentAuth(token),
|
||||
"/my/contracts/" <> contract_id.to_string(contract_id) <> "/deliver",
|
||||
json.object([
|
||||
#("shipSymbol", ship_symbol.encode(ship_symbol)),
|
||||
#("tradeSymbol", trade_symbol.encode(trade_symbol)),
|
||||
#("units", json.int(units)),
|
||||
]),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
||||
decode.success(ContractCargoDelivered(contract:, cargo:))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ExportToImportMap =
|
||||
Dict(TradeSymbol, List(TradeSymbol))
|
||||
|
||||
pub fn get_supply_chain() -> ApiResponse(ExportToImportMap) {
|
||||
let request = api.get(NoAuth, "/market/supply-chain")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(
|
||||
response,
|
||||
decode.field(
|
||||
"exportToImportMap",
|
||||
decode.dict(
|
||||
trade_symbol.decoder(),
|
||||
decode.list(trade_symbol.decoder()),
|
||||
),
|
||||
decode.success,
|
||||
),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn list_factions(
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(Faction))) {
|
||||
let request = api.get_page(NoAuth, "/factions", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(response, decode.list(faction.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_faction(symbol: FactionSymbol) -> ApiResponse(Faction) {
|
||||
let request =
|
||||
api.get(NoAuth, "/factions/" <> faction_symbol.to_string(symbol))
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, faction.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type FactionReputation {
|
||||
FactionReputation(symbol: FactionSymbol, reputation: Int)
|
||||
}
|
||||
|
||||
pub fn get_my_factions(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(FactionReputation))) {
|
||||
let request = api.get_page(AgentAuth(token), "/my/factions", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(
|
||||
response,
|
||||
decode.list({
|
||||
use symbol <- decode.field("symbol", faction_symbol.decoder())
|
||||
use reputation <- decode.field("reputation", decode.int)
|
||||
decode.success(FactionReputation(symbol:, reputation:))
|
||||
}),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
import models/agent.{type Agent}
|
||||
import models/chart.{type Chart}
|
||||
import models/chart_transaction.{type ChartTransaction}
|
||||
import models/contract.{type Contract}
|
||||
import models/cooldown.{type Cooldown}
|
||||
import models/extraction.{type Extraction}
|
||||
import models/market_transaction.{type MarketTransaction}
|
||||
import models/module_symbol.{type ModuleSymbol}
|
||||
import models/mount_symbol.{type MountSymbol}
|
||||
import models/refinement_produce.{type RefinementProduce}
|
||||
import models/refinement_yield.{type RefinementYield}
|
||||
import models/repair_transaction.{type RepairTransaction}
|
||||
import models/scanned_ship.{type ScannedShip}
|
||||
import models/scanned_system.{type ScannedSystem}
|
||||
import models/scanned_waypoint.{type ScannedWaypoint}
|
||||
import models/scrap_transaction.{type ScrapTransaction}
|
||||
import models/ship.{type Ship}
|
||||
import models/ship_cargo.{type ShipCargo}
|
||||
import models/ship_condition_event.{type ShipConditionEvent}
|
||||
import models/ship_fuel.{type ShipFuel}
|
||||
import models/ship_modification_transaction.{type ShipModificationTransaction}
|
||||
import models/ship_module.{type ShipModule}
|
||||
import models/ship_mount.{type ShipMount}
|
||||
import models/ship_nav.{type ShipNav}
|
||||
import models/ship_nav_flight_mode.{type ShipNavFlightMode}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/ship_type.{type ShipType}
|
||||
import models/shipyard_transaction.{type ShipyardTransaction}
|
||||
import models/siphon.{type Siphon}
|
||||
import models/survey.{type Survey}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import models/waypoint.{type Waypoint}
|
||||
import models/waypoint_modifier.{type WaypointModifier}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api.{type ApiResponse, type PagedData}
|
||||
import utils/auth.{type AgentToken, AgentAuth}
|
||||
|
||||
pub fn list_ships(
|
||||
token: AgentToken,
|
||||
|
@ -1384,384 +1070,3 @@ pub fn patch_ship_nav(
|
|||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type Stats {
|
||||
Stats(
|
||||
accounts: Option(Int),
|
||||
agents: Int,
|
||||
ships: Int,
|
||||
systems: Int,
|
||||
waypoints: Int,
|
||||
)
|
||||
}
|
||||
|
||||
fn stats_decoder() -> Decoder(Stats) {
|
||||
use accounts <- decode.optional_field(
|
||||
"accounts",
|
||||
option.None,
|
||||
decode.optional(decode.int),
|
||||
)
|
||||
use agents <- decode.field("agents", decode.int)
|
||||
use ships <- decode.field("ships", decode.int)
|
||||
use systems <- decode.field("systems", decode.int)
|
||||
use waypoints <- decode.field("waypoints", decode.int)
|
||||
decode.success(Stats(accounts:, agents:, ships:, systems:, waypoints:))
|
||||
}
|
||||
|
||||
pub type Health {
|
||||
Health(last_market_update: Option(Time))
|
||||
}
|
||||
|
||||
fn health_decoder() -> Decoder(Health) {
|
||||
use last_market_update <- decode.optional_field(
|
||||
"lastMarketUpdate",
|
||||
option.None,
|
||||
decode.optional(time.datetime_decoder()),
|
||||
)
|
||||
decode.success(Health(last_market_update:))
|
||||
}
|
||||
|
||||
pub type CreditLeaderboardEntry {
|
||||
CreditLeaderboardEntry(agent_symbol: AgentSymbol, credits: Int)
|
||||
}
|
||||
|
||||
fn credit_leaderboard_entry_decoder() -> Decoder(CreditLeaderboardEntry) {
|
||||
use agent_symbol <- decode.field("agentSymbol", agent_symbol.decoder())
|
||||
use credits <- decode.field("credits", decode.int)
|
||||
decode.success(CreditLeaderboardEntry(agent_symbol:, credits:))
|
||||
}
|
||||
|
||||
pub type ChartLeaderboardEntry {
|
||||
ChartLeaderboardEntry(agent_symbol: AgentSymbol, chart_count: Int)
|
||||
}
|
||||
|
||||
fn chart_leaderboard_entry_decoder() -> Decoder(ChartLeaderboardEntry) {
|
||||
use agent_symbol <- decode.field("agentSymbol", agent_symbol.decoder())
|
||||
use chart_count <- decode.field("chartCount", decode.int)
|
||||
decode.success(ChartLeaderboardEntry(agent_symbol:, chart_count:))
|
||||
}
|
||||
|
||||
pub type Leaderboards {
|
||||
Leaderboards(
|
||||
most_credits: List(CreditLeaderboardEntry),
|
||||
most_submitted_charts: List(ChartLeaderboardEntry),
|
||||
)
|
||||
}
|
||||
|
||||
fn leaderboards_decoder() -> Decoder(Leaderboards) {
|
||||
use most_credits <- decode.field(
|
||||
"mostCredits",
|
||||
decode.list(credit_leaderboard_entry_decoder()),
|
||||
)
|
||||
use most_submitted_charts <- decode.field(
|
||||
"mostSubmittedCharts",
|
||||
decode.list(chart_leaderboard_entry_decoder()),
|
||||
)
|
||||
decode.success(Leaderboards(most_credits:, most_submitted_charts:))
|
||||
}
|
||||
|
||||
pub type ServerResets {
|
||||
ServerResets(next: Time, frequency: String)
|
||||
}
|
||||
|
||||
fn server_resets_decoder() -> Decoder(ServerResets) {
|
||||
use next <- decode.field("next", time.datetime_decoder())
|
||||
use frequency <- decode.field("frequency", decode.string)
|
||||
decode.success(ServerResets(next:, frequency:))
|
||||
}
|
||||
|
||||
pub type Announcement {
|
||||
Announcement(title: String, body: String)
|
||||
}
|
||||
|
||||
fn announcement_decoder() -> Decoder(Announcement) {
|
||||
use title <- decode.field("title", decode.string)
|
||||
use body <- decode.field("body", decode.string)
|
||||
decode.success(Announcement(title:, body:))
|
||||
}
|
||||
|
||||
pub type Link {
|
||||
Link(name: String, url: Uri)
|
||||
}
|
||||
|
||||
fn link_decoder() -> Decoder(Link) {
|
||||
use name <- decode.field("name", decode.string)
|
||||
use url <- decode.field("url", {
|
||||
use value <- decode.then(decode.string)
|
||||
case uri.parse(value) {
|
||||
Ok(time) -> decode.success(time)
|
||||
Error(Nil) -> decode.failure(uri.empty, "Uri")
|
||||
}
|
||||
})
|
||||
decode.success(Link(name:, url:))
|
||||
}
|
||||
|
||||
pub type ServerStatus {
|
||||
ServerStatus(
|
||||
status: String,
|
||||
version: String,
|
||||
reset_date: Time,
|
||||
description: String,
|
||||
stats: Stats,
|
||||
health: Health,
|
||||
leaderboards: Leaderboards,
|
||||
server_resets: ServerResets,
|
||||
announcements: List(Announcement),
|
||||
links: List(Link),
|
||||
)
|
||||
}
|
||||
|
||||
fn server_status_decoder() -> Decoder(ServerStatus) {
|
||||
use status <- decode.field("status", decode.string)
|
||||
use version <- decode.field("version", decode.string)
|
||||
use reset_date <- decode.field("resetDate", time.date_decoder())
|
||||
use description <- decode.field("description", decode.string)
|
||||
use stats <- decode.field("stats", stats_decoder())
|
||||
use health <- decode.field("health", health_decoder())
|
||||
use leaderboards <- decode.field("leaderboards", leaderboards_decoder())
|
||||
use server_resets <- decode.field("serverResets", server_resets_decoder())
|
||||
use announcements <- decode.field(
|
||||
"announcements",
|
||||
decode.list(announcement_decoder()),
|
||||
)
|
||||
use links <- decode.field("links", decode.list(link_decoder()))
|
||||
decode.success(ServerStatus(
|
||||
status:,
|
||||
version:,
|
||||
reset_date:,
|
||||
description:,
|
||||
stats:,
|
||||
health:,
|
||||
leaderboards:,
|
||||
server_resets:,
|
||||
announcements:,
|
||||
links:,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn get_server_status() -> ApiResponse(ServerStatus) {
|
||||
let request = api.get(NoAuth, "/")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_response(response, server_status_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ErrorCode {
|
||||
ErrorCode(code: Int, name: String)
|
||||
}
|
||||
|
||||
fn error_code_decoder() -> Decoder(ErrorCode) {
|
||||
use code <- decode.field("code", decode.int)
|
||||
use name <- decode.field("name", decode.string)
|
||||
decode.success(ErrorCode(code:, name:))
|
||||
}
|
||||
|
||||
pub fn list_error_codes() -> ApiResponse(List(ErrorCode)) {
|
||||
let request = api.get(NoAuth, "/error-codes")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_response(
|
||||
response,
|
||||
decode.field(
|
||||
"errorCodes",
|
||||
decode.list(error_code_decoder()),
|
||||
decode.success,
|
||||
),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn list_systems(
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(System))) {
|
||||
let request = api.get_page(NoAuth, "/systems", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(response, decode.list(system.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_system(system_symbol: SystemSymbol) -> ApiResponse(System) {
|
||||
let request =
|
||||
api.get(NoAuth, "/systems/" <> system_symbol.to_string(system_symbol))
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, system.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn list_system_waypoints(
|
||||
system_symbol: SystemSymbol,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
type_: Option(WaypointType),
|
||||
traits: List(WaypointTraitSymbol),
|
||||
) -> ApiResponse(PagedData(List(Waypoint))) {
|
||||
let query =
|
||||
list.map(traits, fn(trait) {
|
||||
#("traits", waypoint_trait_symbol.to_string(trait))
|
||||
})
|
||||
let query = case type_ {
|
||||
option.Some(type_) -> [#("type", waypoint_type.to_string(type_)), ..query]
|
||||
option.None -> query
|
||||
}
|
||||
let request =
|
||||
api.get_page_with_query(
|
||||
NoAuth,
|
||||
"/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints",
|
||||
page,
|
||||
limit,
|
||||
query,
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(response, decode.list(waypoint.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_waypoint(
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(Waypoint) {
|
||||
let request =
|
||||
api.get(
|
||||
NoAuth,
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, waypoint.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_construction_site(
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(Construction) {
|
||||
let request =
|
||||
api.get(
|
||||
NoAuth,
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/construction",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, construction.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ConstructionSiteSupplied {
|
||||
ConstructionSiteSupplied(construction: Construction, cargo: ShipCargo)
|
||||
}
|
||||
|
||||
pub fn supply_construction_site(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
ship_symbol: ShipSymbol,
|
||||
trade_symbol: TradeSymbol,
|
||||
units: Int,
|
||||
) -> ApiResponse(ConstructionSiteSupplied) {
|
||||
let request =
|
||||
api.post_json(
|
||||
AgentAuth(token),
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/construction/supply",
|
||||
json.object([
|
||||
#("shipSymbol", ship_symbol.encode(ship_symbol)),
|
||||
#("tradeSymbol", trade_symbol.encode(trade_symbol)),
|
||||
#("units", json.int(units)),
|
||||
]),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
201 ->
|
||||
api.parse_data_response(response, {
|
||||
use construction <- decode.field("construction", construction.decoder())
|
||||
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
||||
decode.success(ConstructionSiteSupplied(construction:, cargo:))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_market(
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(Market) {
|
||||
let request =
|
||||
api.get(
|
||||
NoAuth,
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/market",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, market.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_jump_gate(
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(JumpGate) {
|
||||
let request =
|
||||
api.get(
|
||||
NoAuth,
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/jump-gate",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, jump_gate.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_shipyard(
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(Shipyard) {
|
||||
let request =
|
||||
api.get(
|
||||
NoAuth,
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/shipyard",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, shipyard.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
203
src/endpoints/global.gleam
Normal file
203
src/endpoints/global.gleam
Normal file
|
@ -0,0 +1,203 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import gleam/uri.{type Uri}
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import utils/api.{type ApiResponse}
|
||||
import utils/auth.{NoAuth}
|
||||
|
||||
pub type Stats {
|
||||
Stats(
|
||||
accounts: Option(Int),
|
||||
agents: Int,
|
||||
ships: Int,
|
||||
systems: Int,
|
||||
waypoints: Int,
|
||||
)
|
||||
}
|
||||
|
||||
fn stats_decoder() -> Decoder(Stats) {
|
||||
use accounts <- decode.optional_field(
|
||||
"accounts",
|
||||
option.None,
|
||||
decode.optional(decode.int),
|
||||
)
|
||||
use agents <- decode.field("agents", decode.int)
|
||||
use ships <- decode.field("ships", decode.int)
|
||||
use systems <- decode.field("systems", decode.int)
|
||||
use waypoints <- decode.field("waypoints", decode.int)
|
||||
decode.success(Stats(accounts:, agents:, ships:, systems:, waypoints:))
|
||||
}
|
||||
|
||||
pub type Health {
|
||||
Health(last_market_update: Option(Time))
|
||||
}
|
||||
|
||||
fn health_decoder() -> Decoder(Health) {
|
||||
use last_market_update <- decode.optional_field(
|
||||
"lastMarketUpdate",
|
||||
option.None,
|
||||
decode.optional(api.time_decoder()),
|
||||
)
|
||||
decode.success(Health(last_market_update:))
|
||||
}
|
||||
|
||||
pub type CreditLeaderboardEntry {
|
||||
CreditLeaderboardEntry(agent_symbol: AgentSymbol, credits: Int)
|
||||
}
|
||||
|
||||
fn credit_leaderboard_entry_decoder() -> Decoder(CreditLeaderboardEntry) {
|
||||
use agent_symbol <- decode.field("agentSymbol", agent_symbol.decoder())
|
||||
use credits <- decode.field("credits", decode.int)
|
||||
decode.success(CreditLeaderboardEntry(agent_symbol:, credits:))
|
||||
}
|
||||
|
||||
pub type ChartLeaderboardEntry {
|
||||
ChartLeaderboardEntry(agent_symbol: AgentSymbol, chart_count: Int)
|
||||
}
|
||||
|
||||
fn chart_leaderboard_entry_decoder() -> Decoder(ChartLeaderboardEntry) {
|
||||
use agent_symbol <- decode.field("agentSymbol", agent_symbol.decoder())
|
||||
use chart_count <- decode.field("chartCount", decode.int)
|
||||
decode.success(ChartLeaderboardEntry(agent_symbol:, chart_count:))
|
||||
}
|
||||
|
||||
pub type Leaderboards {
|
||||
Leaderboards(
|
||||
most_credits: List(CreditLeaderboardEntry),
|
||||
most_submitted_charts: List(ChartLeaderboardEntry),
|
||||
)
|
||||
}
|
||||
|
||||
fn leaderboards_decoder() -> Decoder(Leaderboards) {
|
||||
use most_credits <- decode.field(
|
||||
"mostCredits",
|
||||
decode.list(credit_leaderboard_entry_decoder()),
|
||||
)
|
||||
use most_submitted_charts <- decode.field(
|
||||
"mostSubmittedCharts",
|
||||
decode.list(chart_leaderboard_entry_decoder()),
|
||||
)
|
||||
decode.success(Leaderboards(most_credits:, most_submitted_charts:))
|
||||
}
|
||||
|
||||
pub type ServerResets {
|
||||
ServerResets(next: Time, frequency: String)
|
||||
}
|
||||
|
||||
fn server_resets_decoder() -> Decoder(ServerResets) {
|
||||
use next <- decode.field("next", api.time_decoder())
|
||||
use frequency <- decode.field("frequency", decode.string)
|
||||
decode.success(ServerResets(next:, frequency:))
|
||||
}
|
||||
|
||||
pub type Announcement {
|
||||
Announcement(title: String, body: String)
|
||||
}
|
||||
|
||||
fn announcement_decoder() -> Decoder(Announcement) {
|
||||
use title <- decode.field("title", decode.string)
|
||||
use body <- decode.field("body", decode.string)
|
||||
decode.success(Announcement(title:, body:))
|
||||
}
|
||||
|
||||
pub type Link {
|
||||
Link(name: String, url: Uri)
|
||||
}
|
||||
|
||||
fn link_decoder() -> Decoder(Link) {
|
||||
use name <- decode.field("name", decode.string)
|
||||
use url <- decode.field("url", {
|
||||
use value <- decode.then(decode.string)
|
||||
case uri.parse(value) {
|
||||
Ok(time) -> decode.success(time)
|
||||
Error(Nil) -> decode.failure(uri.empty, "Uri")
|
||||
}
|
||||
})
|
||||
decode.success(Link(name:, url:))
|
||||
}
|
||||
|
||||
pub type ServerStatus {
|
||||
ServerStatus(
|
||||
status: String,
|
||||
version: String,
|
||||
reset_date: Time,
|
||||
description: String,
|
||||
stats: Stats,
|
||||
health: Health,
|
||||
leaderboards: Leaderboards,
|
||||
server_resets: ServerResets,
|
||||
announcements: List(Announcement),
|
||||
links: List(Link),
|
||||
)
|
||||
}
|
||||
|
||||
fn server_status_decoder() -> Decoder(ServerStatus) {
|
||||
use status <- decode.field("status", decode.string)
|
||||
use version <- decode.field("version", decode.string)
|
||||
use reset_date <- decode.field("resetDate", {
|
||||
use value <- decode.then(decode.string)
|
||||
case birl.from_naive(value) {
|
||||
Ok(time) -> decode.success(time)
|
||||
Error(Nil) -> decode.failure(birl.now(), "Time")
|
||||
}
|
||||
})
|
||||
use description <- decode.field("description", decode.string)
|
||||
use stats <- decode.field("stats", stats_decoder())
|
||||
use health <- decode.field("health", health_decoder())
|
||||
use leaderboards <- decode.field("leaderboards", leaderboards_decoder())
|
||||
use server_resets <- decode.field("serverResets", server_resets_decoder())
|
||||
use announcements <- decode.field(
|
||||
"announcements",
|
||||
decode.list(announcement_decoder()),
|
||||
)
|
||||
use links <- decode.field("links", decode.list(link_decoder()))
|
||||
decode.success(ServerStatus(
|
||||
status:,
|
||||
version:,
|
||||
reset_date:,
|
||||
description:,
|
||||
stats:,
|
||||
health:,
|
||||
leaderboards:,
|
||||
server_resets:,
|
||||
announcements:,
|
||||
links:,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn get_server_status() -> ApiResponse(ServerStatus) {
|
||||
let request = api.get(NoAuth, "/")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_response(response, server_status_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ErrorCode {
|
||||
ErrorCode(code: Int, name: String)
|
||||
}
|
||||
|
||||
fn error_code_decoder() -> Decoder(ErrorCode) {
|
||||
use code <- decode.field("code", decode.int)
|
||||
use name <- decode.field("name", decode.string)
|
||||
decode.success(ErrorCode(code:, name:))
|
||||
}
|
||||
|
||||
pub fn list_error_codes() -> ApiResponse(List(ErrorCode)) {
|
||||
let request = api.get(NoAuth, "/error-codes")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_response(
|
||||
response,
|
||||
decode.field(
|
||||
"errorCodes",
|
||||
decode.list(error_code_decoder()),
|
||||
decode.success,
|
||||
),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
223
src/endpoints/systems.gleam
Normal file
223
src/endpoints/systems.gleam
Normal file
|
@ -0,0 +1,223 @@
|
|||
import gleam/dynamic/decode
|
||||
import gleam/json
|
||||
import gleam/list
|
||||
import gleam/option.{type Option}
|
||||
import models/construction.{type Construction}
|
||||
import models/jump_gate.{type JumpGate}
|
||||
import models/market.{type Market}
|
||||
import models/ship_cargo.{type ShipCargo}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/shipyard.{type Shipyard}
|
||||
import models/system.{type System}
|
||||
import models/system_symbol.{type SystemSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import models/waypoint.{type Waypoint}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/waypoint_trait_symbol.{type WaypointTraitSymbol}
|
||||
import models/waypoint_type.{type WaypointType}
|
||||
import utils/api.{type ApiResponse, type PagedData}
|
||||
import utils/auth.{type AgentToken, AgentAuth}
|
||||
|
||||
pub fn list_systems(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(List(System))) {
|
||||
let request = api.get_page(AgentAuth(token), "/systems", page, limit)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(response, decode.list(system.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_system(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
) -> ApiResponse(System) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/systems/" <> system_symbol.to_string(system_symbol),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, system.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn list_system_waypoints(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
type_: Option(WaypointType),
|
||||
traits: List(WaypointTraitSymbol),
|
||||
) -> ApiResponse(PagedData(List(Waypoint))) {
|
||||
let query =
|
||||
list.map(traits, fn(trait) {
|
||||
#("traits", waypoint_trait_symbol.to_string(trait))
|
||||
})
|
||||
let query = case type_ {
|
||||
option.Some(type_) -> [#("type", waypoint_type.to_string(type_)), ..query]
|
||||
option.None -> query
|
||||
}
|
||||
let request =
|
||||
api.get_page_with_query(
|
||||
AgentAuth(token),
|
||||
"/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints",
|
||||
page,
|
||||
limit,
|
||||
query,
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_paged_data_response(response, decode.list(waypoint.decoder()))
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_waypoint(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(Waypoint) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, waypoint.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_construction_site(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(Construction) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/construction",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, construction.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ConstructionSiteSupplied {
|
||||
ConstructionSiteSupplied(construction: Construction, cargo: ShipCargo)
|
||||
}
|
||||
|
||||
pub fn supply_construction_site(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
ship_symbol: ShipSymbol,
|
||||
trade_symbol: TradeSymbol,
|
||||
units: Int,
|
||||
) -> ApiResponse(ConstructionSiteSupplied) {
|
||||
let request =
|
||||
api.post_json(
|
||||
AgentAuth(token),
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/construction/supply",
|
||||
json.object([
|
||||
#("shipSymbol", ship_symbol.encode(ship_symbol)),
|
||||
#("tradeSymbol", trade_symbol.encode(trade_symbol)),
|
||||
#("units", json.int(units)),
|
||||
]),
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
201 ->
|
||||
api.parse_data_response(response, {
|
||||
use construction <- decode.field("construction", construction.decoder())
|
||||
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
||||
decode.success(ConstructionSiteSupplied(construction:, cargo:))
|
||||
})
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_market(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(Market) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/market",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, market.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_jump_gate(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(JumpGate) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/systems/"
|
||||
<> system_symbol.to_string(system_symbol)
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||
<> "/jump-gate",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, jump_gate.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_shipyard(
|
||||
token,
|
||||
system_symbol,
|
||||
waypoint_symbol,
|
||||
) -> ApiResponse(Shipyard) {
|
||||
let request =
|
||||
api.get(
|
||||
AgentAuth(token),
|
||||
"/systems/"
|
||||
<> system_symbol
|
||||
<> "/waypoints/"
|
||||
<> waypoint_symbol
|
||||
<> "/shipyard",
|
||||
)
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, shipyard.decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/account_id.{type AccountId}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/account_id.{type AccountId}
|
||||
import utils/api
|
||||
|
||||
pub type Account {
|
||||
Account(
|
||||
|
@ -25,6 +25,6 @@ pub fn decoder() -> Decoder(Account) {
|
|||
option.None,
|
||||
decode.optional(decode.string),
|
||||
)
|
||||
use created_at <- decode.field("createdAt", time.datetime_decoder())
|
||||
use created_at <- decode.field("createdAt", api.time_decoder())
|
||||
decode.success(Account(id:, email:, token:, created_at:))
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/account_id.{type AccountId}
|
||||
import spacetraders_models/agent_symbol.{type AgentSymbol}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/account_id.{type AccountId}
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type Agent {
|
||||
Agent(
|
|
@ -2,8 +2,8 @@ import birl.{type Time}
|
|||
import gleam/dynamic.{type Dynamic}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/agent_event_id.{type AgentEventId}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/agent_event_id.{type AgentEventId}
|
||||
import utils/api
|
||||
|
||||
pub type AgentEvent {
|
||||
AgentEvent(
|
||||
|
@ -24,6 +24,6 @@ pub fn decoder() -> Decoder(AgentEvent) {
|
|||
option.None,
|
||||
decode.optional(decode.dynamic),
|
||||
)
|
||||
use created_at <- decode.field("createdAt", time.datetime_decoder())
|
||||
use created_at <- decode.field("createdAt", api.time_decoder())
|
||||
decode.success(AgentEvent(id:, type_:, message:, data:, created_at:))
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/agent_symbol.{type AgentSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type Chart {
|
||||
Chart(
|
||||
|
@ -18,6 +18,6 @@ pub fn decoder() -> Decoder(Chart) {
|
|||
waypoint_symbol.decoder(),
|
||||
)
|
||||
use submitted_by <- decode.field("submittedBy", agent_symbol.decoder())
|
||||
use submitted_on <- decode.field("submittedOn", time.datetime_decoder())
|
||||
use submitted_on <- decode.field("submittedOn", api.time_decoder())
|
||||
decode.success(Chart(waypoint_symbol:, submitted_by:, submitted_on:))
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type ChartTransaction {
|
||||
ChartTransaction(
|
||||
|
@ -20,7 +20,7 @@ pub fn decoder() -> Decoder(ChartTransaction) {
|
|||
)
|
||||
use ship_symbol <- decode.field("shipSymbol", ship_symbol.decoder())
|
||||
use total_price <- decode.field("totalPrice", decode.int)
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
use timestamp <- decode.field("timestamp", api.time_decoder())
|
||||
decode.success(ChartTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/construction_material.{type ConstructionMaterial}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/construction_material.{type ConstructionMaterial}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type Construction {
|
||||
Construction(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
|
||||
pub type ConstructionMaterial {
|
||||
ConstructionMaterial(trade_symbol: TradeSymbol, required: Int, fulfilled: Int)
|
|
@ -1,11 +1,11 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/contract_id.{type ContractId}
|
||||
import spacetraders_models/contract_terms.{type ContractTerms}
|
||||
import spacetraders_models/contract_type.{type ContractType}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/contract_id.{type ContractId}
|
||||
import models/contract_terms.{type ContractTerms}
|
||||
import models/contract_type.{type ContractType}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type Contract {
|
||||
Contract(
|
||||
|
@ -29,7 +29,7 @@ pub fn decoder() -> Decoder(Contract) {
|
|||
use deadline_to_accept <- decode.optional_field(
|
||||
"deadlineToAccept",
|
||||
option.None,
|
||||
decode.optional(time.datetime_decoder()),
|
||||
decode.optional(api.time_decoder()),
|
||||
)
|
||||
decode.success(Contract(
|
||||
id:,
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type ContractDeliverGood {
|
||||
ContractDeliverGood(
|
|
@ -1,9 +1,9 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/contract_deliver_good.{type ContractDeliverGood}
|
||||
import spacetraders_models/contract_payment.{type ContractPayment}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/contract_deliver_good.{type ContractDeliverGood}
|
||||
import models/contract_payment.{type ContractPayment}
|
||||
import utils/api
|
||||
|
||||
pub type ContractTerms {
|
||||
ContractTerms(
|
||||
|
@ -14,7 +14,7 @@ pub type ContractTerms {
|
|||
}
|
||||
|
||||
pub fn decoder() -> Decoder(ContractTerms) {
|
||||
use deadline <- decode.field("deadline", time.datetime_decoder())
|
||||
use deadline <- decode.field("deadline", api.time_decoder())
|
||||
use payment <- decode.field("payment", contract_payment.decoder())
|
||||
use deliver <- decode.optional_field(
|
||||
"deliver",
|
|
@ -1,8 +1,8 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type Cooldown {
|
||||
Cooldown(
|
||||
|
@ -20,7 +20,7 @@ pub fn decoder() -> Decoder(Cooldown) {
|
|||
use expiration <- decode.optional_field(
|
||||
"expiration",
|
||||
option.None,
|
||||
decode.optional(time.datetime_decoder()),
|
||||
decode.optional(api.time_decoder()),
|
||||
)
|
||||
decode.success(Cooldown(
|
||||
ship_symbol:,
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/extraction_yield.{type ExtractionYield}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import models/extraction_yield.{type ExtractionYield}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
|
||||
pub type Extraction {
|
||||
Extraction(ship_symbol: ShipSymbol, yield: ExtractionYield)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
|
||||
pub type ExtractionYield {
|
||||
ExtractionYield(symbol: TradeSymbol, units: Int)
|
|
@ -1,8 +1,8 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_models/faction_trait.{type FactionTrait}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import models/faction_trait.{type FactionTrait}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type Faction {
|
||||
Faction(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/faction_trait_symbol.{type FactionTraitSymbol}
|
||||
import models/faction_trait_symbol.{type FactionTraitSymbol}
|
||||
|
||||
pub type FactionTrait {
|
||||
FactionTrait(symbol: FactionTraitSymbol, name: String, description: String)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type JumpGate {
|
||||
JumpGate(symbol: WaypointSymbol, connections: List(WaypointSymbol))
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/market_symbol.{type MarketSymbol}
|
||||
import spacetraders_models/market_trade_good.{type MarketTradeGood}
|
||||
import spacetraders_models/market_transaction.{type MarketTransaction}
|
||||
import spacetraders_models/trade_good.{type TradeGood}
|
||||
import models/market_symbol.{type MarketSymbol}
|
||||
import models/market_trade_good.{type MarketTradeGood}
|
||||
import models/market_transaction.{type MarketTransaction}
|
||||
import models/trade_good.{type TradeGood}
|
||||
|
||||
pub type Market {
|
||||
Market(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/activity_level.{type ActivityLevel}
|
||||
import spacetraders_models/supply_level.{type SupplyLevel}
|
||||
import spacetraders_models/trade_good_type.{type TradeGoodType}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import models/activity_level.{type ActivityLevel}
|
||||
import models/supply_level.{type SupplyLevel}
|
||||
import models/trade_good_type.{type TradeGoodType}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
|
||||
pub type MarketTradeGood {
|
||||
MarketTradeGood(
|
|
@ -1,10 +1,10 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_models/transaction_type.{type TransactionType}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import models/transaction_type.{type TransactionType}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type MarketTransaction {
|
||||
MarketTransaction(
|
||||
|
@ -30,7 +30,7 @@ pub fn decoder() -> Decoder(MarketTransaction) {
|
|||
use units <- decode.field("units", decode.int)
|
||||
use price_per_unit <- decode.field("pricePerUnit", decode.int)
|
||||
use total_price <- decode.field("totalPrice", decode.int)
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
use timestamp <- decode.field("timestamp", api.time_decoder())
|
||||
decode.success(MarketTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,7 +1,7 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/agent_symbol.{type AgentSymbol}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type PublicAgent {
|
||||
PublicAgent(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
|
||||
pub type RefinementYield {
|
||||
RefinementYield(trade_symbol: TradeSymbol, units: Int)
|
|
@ -1,8 +1,8 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type RepairTransaction {
|
||||
RepairTransaction(
|
||||
|
@ -20,7 +20,7 @@ pub fn decoder() -> Decoder(RepairTransaction) {
|
|||
)
|
||||
use ship_symbol <- decode.field("shipSymbol", ship_symbol.decoder())
|
||||
use total_price <- decode.field("totalPrice", decode.int)
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
use timestamp <- decode.field("timestamp", api.time_decoder())
|
||||
decode.success(RepairTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,12 +1,12 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/scanned_ship_engine.{type ScannedShipEngine}
|
||||
import spacetraders_models/scanned_ship_frame.{type ScannedShipFrame}
|
||||
import spacetraders_models/scanned_ship_mount.{type ScannedShipMount}
|
||||
import spacetraders_models/scanned_ship_reactor.{type ScannedShipReactor}
|
||||
import spacetraders_models/ship_nav.{type ShipNav}
|
||||
import spacetraders_models/ship_registration.{type ShipRegistration}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import models/scanned_ship_engine.{type ScannedShipEngine}
|
||||
import models/scanned_ship_frame.{type ScannedShipFrame}
|
||||
import models/scanned_ship_mount.{type ScannedShipMount}
|
||||
import models/scanned_ship_reactor.{type ScannedShipReactor}
|
||||
import models/ship_nav.{type ShipNav}
|
||||
import models/ship_registration.{type ShipRegistration}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
|
||||
pub type ScannedShip {
|
||||
ScannedShip(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/engine_symbol.{type EngineSymbol}
|
||||
import models/engine_symbol.{type EngineSymbol}
|
||||
|
||||
pub type ScannedShipEngine {
|
||||
ScannedShipEngine(symbol: EngineSymbol)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/frame_symbol.{type FrameSymbol}
|
||||
import models/frame_symbol.{type FrameSymbol}
|
||||
|
||||
pub type ScannedShipFrame {
|
||||
ScannedShipFrame(symbol: FrameSymbol)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/mount_symbol.{type MountSymbol}
|
||||
import models/mount_symbol.{type MountSymbol}
|
||||
|
||||
pub type ScannedShipMount {
|
||||
ScannedShipMount(symbol: MountSymbol)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/reactor_symbol.{type ReactorSymbol}
|
||||
import models/reactor_symbol.{type ReactorSymbol}
|
||||
|
||||
pub type ScannedShipReactor {
|
||||
ScannedShipReactor(symbol: ReactorSymbol)
|
|
@ -1,7 +1,7 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/sector_symbol.{type SectorSymbol}
|
||||
import spacetraders_models/system_symbol.{type SystemSymbol}
|
||||
import spacetraders_models/system_type.{type SystemType}
|
||||
import models/sector_symbol.{type SectorSymbol}
|
||||
import models/system_symbol.{type SystemSymbol}
|
||||
import models/system_type.{type SystemType}
|
||||
|
||||
pub type ScannedSystem {
|
||||
ScannedSystem(
|
|
@ -1,12 +1,12 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/chart.{type Chart}
|
||||
import spacetraders_models/system_symbol.{type SystemSymbol}
|
||||
import spacetraders_models/waypoint_faction.{type WaypointFaction}
|
||||
import spacetraders_models/waypoint_orbital.{type WaypointOrbital}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_models/waypoint_trait.{type WaypointTrait}
|
||||
import spacetraders_models/waypoint_type.{type WaypointType}
|
||||
import models/chart.{type Chart}
|
||||
import models/system_symbol.{type SystemSymbol}
|
||||
import models/waypoint_faction.{type WaypointFaction}
|
||||
import models/waypoint_orbital.{type WaypointOrbital}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/waypoint_trait.{type WaypointTrait}
|
||||
import models/waypoint_type.{type WaypointType}
|
||||
|
||||
pub type ScannedWaypoint {
|
||||
ScannedWaypoint(
|
|
@ -1,8 +1,8 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type ScrapTransaction {
|
||||
ScrapTransaction(
|
||||
|
@ -20,7 +20,7 @@ pub fn decoder() -> Decoder(ScrapTransaction) {
|
|||
)
|
||||
use ship_symbol <- decode.field("shipSymbol", ship_symbol.decoder())
|
||||
use total_price <- decode.field("totalPrice", decode.int)
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
use timestamp <- decode.field("timestamp", api.time_decoder())
|
||||
decode.success(ScrapTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,16 +1,16 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/cooldown.{type Cooldown}
|
||||
import spacetraders_models/ship_cargo.{type ShipCargo}
|
||||
import spacetraders_models/ship_crew.{type ShipCrew}
|
||||
import spacetraders_models/ship_engine.{type ShipEngine}
|
||||
import spacetraders_models/ship_frame.{type ShipFrame}
|
||||
import spacetraders_models/ship_fuel.{type ShipFuel}
|
||||
import spacetraders_models/ship_module.{type ShipModule}
|
||||
import spacetraders_models/ship_mount.{type ShipMount}
|
||||
import spacetraders_models/ship_nav.{type ShipNav}
|
||||
import spacetraders_models/ship_reactor.{type ShipReactor}
|
||||
import spacetraders_models/ship_registration.{type ShipRegistration}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import models/cooldown.{type Cooldown}
|
||||
import models/ship_cargo.{type ShipCargo}
|
||||
import models/ship_crew.{type ShipCrew}
|
||||
import models/ship_engine.{type ShipEngine}
|
||||
import models/ship_frame.{type ShipFrame}
|
||||
import models/ship_fuel.{type ShipFuel}
|
||||
import models/ship_module.{type ShipModule}
|
||||
import models/ship_mount.{type ShipMount}
|
||||
import models/ship_nav.{type ShipNav}
|
||||
import models/ship_reactor.{type ShipReactor}
|
||||
import models/ship_registration.{type ShipRegistration}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
|
||||
pub type Ship {
|
||||
Ship(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_cargo_item.{type ShipCargoItem}
|
||||
import models/ship_cargo_item.{type ShipCargoItem}
|
||||
|
||||
pub type ShipCargo {
|
||||
ShipCargo(capacity: Int, units: Int, inventory: List(ShipCargoItem))
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
|
||||
pub type ShipCargoItem {
|
||||
ShipCargoItem(
|
|
@ -1,5 +1,4 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/int
|
||||
import gleam/json.{type Json}
|
||||
|
||||
pub opaque type ShipComponentCondition {
|
||||
|
@ -18,11 +17,7 @@ pub fn parse(value: Float) -> Result(ShipComponentCondition, Nil) {
|
|||
}
|
||||
|
||||
pub fn decoder() -> Decoder(ShipComponentCondition) {
|
||||
use value <- decode.then(
|
||||
decode.one_of(decode.float, [
|
||||
decode.then(decode.int, fn(i) { decode.success(int.to_float(i)) }),
|
||||
]),
|
||||
)
|
||||
use value <- decode.then(decode.float)
|
||||
case parse(value) {
|
||||
Ok(ship_component_condition) -> decode.success(ship_component_condition)
|
||||
Error(Nil) ->
|
|
@ -1,5 +1,4 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/int
|
||||
import gleam/json.{type Json}
|
||||
|
||||
pub opaque type ShipComponentIntegrity {
|
||||
|
@ -18,11 +17,7 @@ pub fn parse(value: Float) -> Result(ShipComponentIntegrity, Nil) {
|
|||
}
|
||||
|
||||
pub fn decoder() -> Decoder(ShipComponentIntegrity) {
|
||||
use value <- decode.then(
|
||||
decode.one_of(decode.float, [
|
||||
decode.then(decode.int, fn(i) { decode.success(int.to_float(i)) }),
|
||||
]),
|
||||
)
|
||||
use value <- decode.then(decode.float)
|
||||
case parse(value) {
|
||||
Ok(ship_component_integrity) -> decode.success(ship_component_integrity)
|
||||
Error(Nil) ->
|
|
@ -1,8 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_component.{type ShipComponent}
|
||||
import spacetraders_models/ship_condition_event_symbol.{
|
||||
type ShipConditionEventSymbol,
|
||||
}
|
||||
import models/ship_component.{type ShipComponent}
|
||||
import models/ship_condition_event_symbol.{type ShipConditionEventSymbol}
|
||||
|
||||
pub type ShipConditionEvent {
|
||||
ShipConditionEvent(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/crew_rotation.{type CrewRotation}
|
||||
import models/crew_rotation.{type CrewRotation}
|
||||
|
||||
pub type ShipCrew {
|
||||
ShipCrew(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/engine_symbol.{type EngineSymbol}
|
||||
import spacetraders_models/ship_component_condition.{type ShipComponentCondition}
|
||||
import spacetraders_models/ship_component_integrity.{type ShipComponentIntegrity}
|
||||
import spacetraders_models/ship_component_quality.{type ShipComponentQuality}
|
||||
import spacetraders_models/ship_requirements.{type ShipRequirements}
|
||||
import models/engine_symbol.{type EngineSymbol}
|
||||
import models/ship_component_condition.{type ShipComponentCondition}
|
||||
import models/ship_component_integrity.{type ShipComponentIntegrity}
|
||||
import models/ship_component_quality.{type ShipComponentQuality}
|
||||
import models/ship_requirements.{type ShipRequirements}
|
||||
|
||||
pub type ShipEngine {
|
||||
ShipEngine(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/frame_symbol.{type FrameSymbol}
|
||||
import spacetraders_models/ship_component_condition.{type ShipComponentCondition}
|
||||
import spacetraders_models/ship_component_integrity.{type ShipComponentIntegrity}
|
||||
import spacetraders_models/ship_component_quality.{type ShipComponentQuality}
|
||||
import spacetraders_models/ship_requirements.{type ShipRequirements}
|
||||
import models/frame_symbol.{type FrameSymbol}
|
||||
import models/ship_component_condition.{type ShipComponentCondition}
|
||||
import models/ship_component_integrity.{type ShipComponentIntegrity}
|
||||
import models/ship_component_quality.{type ShipComponentQuality}
|
||||
import models/ship_requirements.{type ShipRequirements}
|
||||
|
||||
pub type ShipFrame {
|
||||
ShipFrame(
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/ship_fuel_consumed.{type ShipFuelConsumed}
|
||||
import models/ship_fuel_consumed.{type ShipFuelConsumed}
|
||||
|
||||
pub type ShipFuel {
|
||||
ShipFuel(current: Int, capacity: Int, consumed: Option(ShipFuelConsumed))
|
|
@ -1,6 +1,6 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_sdk/internal/time
|
||||
import utils/api
|
||||
|
||||
pub type ShipFuelConsumed {
|
||||
ShipFuelConsumed(amount: Int, timestamp: Time)
|
||||
|
@ -8,6 +8,6 @@ pub type ShipFuelConsumed {
|
|||
|
||||
pub fn decoder() -> Decoder(ShipFuelConsumed) {
|
||||
use amount <- decode.field("amount", decode.int)
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
use timestamp <- decode.field("timestamp", api.time_decoder())
|
||||
decode.success(ShipFuelConsumed(amount:, timestamp:))
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type ShipModificationTransaction {
|
||||
ShipModificationTransaction(
|
||||
|
@ -23,7 +23,7 @@ pub fn decoder() -> Decoder(ShipModificationTransaction) {
|
|||
use ship_symbol <- decode.field("shipSymbol", ship_symbol.decoder())
|
||||
use trade_symbol <- decode.field("tradeSymbol", trade_symbol.decoder())
|
||||
use total_price <- decode.field("totalPrice", decode.int)
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
use timestamp <- decode.field("timestamp", api.time_decoder())
|
||||
decode.success(ShipModificationTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,7 +1,7 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/module_symbol.{type ModuleSymbol}
|
||||
import spacetraders_models/ship_requirements.{type ShipRequirements}
|
||||
import models/module_symbol.{type ModuleSymbol}
|
||||
import models/ship_requirements.{type ShipRequirements}
|
||||
|
||||
pub type ShipModule {
|
||||
ShipModule(
|
|
@ -1,8 +1,8 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/mount_deposit.{type MountDeposit}
|
||||
import spacetraders_models/mount_symbol.{type MountSymbol}
|
||||
import spacetraders_models/ship_requirements.{type ShipRequirements}
|
||||
import models/mount_deposit.{type MountDeposit}
|
||||
import models/mount_symbol.{type MountSymbol}
|
||||
import models/ship_requirements.{type ShipRequirements}
|
||||
|
||||
pub type ShipMount {
|
||||
ShipMount(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_nav_flight_mode.{type ShipNavFlightMode}
|
||||
import spacetraders_models/ship_nav_route.{type ShipNavRoute}
|
||||
import spacetraders_models/ship_nav_status.{type ShipNavStatus}
|
||||
import spacetraders_models/system_symbol.{type SystemSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/ship_nav_flight_mode.{type ShipNavFlightMode}
|
||||
import models/ship_nav_route.{type ShipNavRoute}
|
||||
import models/ship_nav_status.{type ShipNavStatus}
|
||||
import models/system_symbol.{type SystemSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type ShipNav {
|
||||
ShipNav(
|
|
@ -1,7 +1,7 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_nav_route_waypoint.{type ShipNavRouteWaypoint}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/ship_nav_route_waypoint.{type ShipNavRouteWaypoint}
|
||||
import utils/api
|
||||
|
||||
pub type ShipNavRoute {
|
||||
ShipNavRoute(
|
||||
|
@ -18,7 +18,7 @@ pub fn decoder() -> Decoder(ShipNavRoute) {
|
|||
ship_nav_route_waypoint.decoder(),
|
||||
)
|
||||
use origin <- decode.field("origin", ship_nav_route_waypoint.decoder())
|
||||
use departure_time <- decode.field("departureTime", time.datetime_decoder())
|
||||
use arrival <- decode.field("arrival", time.datetime_decoder())
|
||||
use departure_time <- decode.field("departureTime", api.time_decoder())
|
||||
use arrival <- decode.field("arrival", api.time_decoder())
|
||||
decode.success(ShipNavRoute(destination:, origin:, departure_time:, arrival:))
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/system_symbol.{type SystemSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_models/waypoint_type.{type WaypointType}
|
||||
import models/system_symbol.{type SystemSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/waypoint_type.{type WaypointType}
|
||||
|
||||
pub type ShipNavRouteWaypoint {
|
||||
ShipNavRouteWaypoint(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/reactor_symbol.{type ReactorSymbol}
|
||||
import spacetraders_models/ship_component_condition.{type ShipComponentCondition}
|
||||
import spacetraders_models/ship_component_integrity.{type ShipComponentIntegrity}
|
||||
import spacetraders_models/ship_component_quality.{type ShipComponentQuality}
|
||||
import spacetraders_models/ship_requirements.{type ShipRequirements}
|
||||
import models/reactor_symbol.{type ReactorSymbol}
|
||||
import models/ship_component_condition.{type ShipComponentCondition}
|
||||
import models/ship_component_integrity.{type ShipComponentIntegrity}
|
||||
import models/ship_component_quality.{type ShipComponentQuality}
|
||||
import models/ship_requirements.{type ShipRequirements}
|
||||
|
||||
pub type ShipReactor {
|
||||
ShipReactor(
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_models/ship_role.{type ShipRole}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import models/ship_role.{type ShipRole}
|
||||
|
||||
pub type ShipRegistration {
|
||||
ShipRegistration(name: String, faction_symbol: FactionSymbol, role: ShipRole)
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/ship_type.{type ShipType}
|
||||
import spacetraders_models/shipyard_ship.{type ShipyardShip}
|
||||
import spacetraders_models/shipyard_symbol.{type ShipyardSymbol}
|
||||
import spacetraders_models/shipyard_transaction.{type ShipyardTransaction}
|
||||
import models/ship_type.{type ShipType}
|
||||
import models/shipyard_ship.{type ShipyardShip}
|
||||
import models/shipyard_symbol.{type ShipyardSymbol}
|
||||
import models/shipyard_transaction.{type ShipyardTransaction}
|
||||
|
||||
pub type Shipyard {
|
||||
Shipyard(
|
|
@ -1,14 +1,14 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import spacetraders_models/activity_level.{type ActivityLevel}
|
||||
import spacetraders_models/ship_engine.{type ShipEngine}
|
||||
import spacetraders_models/ship_frame.{type ShipFrame}
|
||||
import spacetraders_models/ship_module.{type ShipModule}
|
||||
import spacetraders_models/ship_mount.{type ShipMount}
|
||||
import spacetraders_models/ship_reactor.{type ShipReactor}
|
||||
import spacetraders_models/ship_type.{type ShipType}
|
||||
import spacetraders_models/shipyard_ship_crew.{type ShipyardShipCrew}
|
||||
import spacetraders_models/supply_level.{type SupplyLevel}
|
||||
import models/activity_level.{type ActivityLevel}
|
||||
import models/ship_engine.{type ShipEngine}
|
||||
import models/ship_frame.{type ShipFrame}
|
||||
import models/ship_module.{type ShipModule}
|
||||
import models/ship_mount.{type ShipMount}
|
||||
import models/ship_reactor.{type ShipReactor}
|
||||
import models/ship_type.{type ShipType}
|
||||
import models/shipyard_ship_crew.{type ShipyardShipCrew}
|
||||
import models/supply_level.{type SupplyLevel}
|
||||
|
||||
pub type ShipyardShip {
|
||||
ShipyardShip(
|
|
@ -1,9 +1,9 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/agent_symbol.{type AgentSymbol}
|
||||
import spacetraders_models/ship_type.{type ShipType}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/ship_type.{type ShipType}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type ShipyardTransaction {
|
||||
ShipyardTransaction(
|
||||
|
@ -23,7 +23,7 @@ pub fn decoder() -> Decoder(ShipyardTransaction) {
|
|||
use ship_type <- decode.field("shipType", ship_type.decoder())
|
||||
use price <- decode.field("price", decode.int)
|
||||
use agent_symbol <- decode.field("agentSymbol", agent_symbol.decoder())
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
use timestamp <- decode.field("timestamp", api.time_decoder())
|
||||
decode.success(ShipyardTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_type:,
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/siphon_yield.{type SiphonYield}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/siphon_yield.{type SiphonYield}
|
||||
|
||||
pub type Siphon {
|
||||
Siphon(ship_symbol: ShipSymbol, yield: SiphonYield)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
|
||||
pub type SiphonYield {
|
||||
SiphonYield(symbol: TradeSymbol, units: Int)
|
|
@ -1,11 +1,11 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/json.{type Json}
|
||||
import spacetraders_models/survey_deposit.{type SurveyDeposit}
|
||||
import spacetraders_models/survey_signature.{type SurveySignature}
|
||||
import spacetraders_models/survey_size.{type SurveySize}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
import models/survey_deposit.{type SurveyDeposit}
|
||||
import models/survey_signature.{type SurveySignature}
|
||||
import models/survey_size.{type SurveySize}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
|
||||
pub type Survey {
|
||||
Survey(
|
||||
|
@ -24,7 +24,7 @@ pub fn decoder() -> Decoder(Survey) {
|
|||
"deposits",
|
||||
decode.list(survey_deposit.decoder()),
|
||||
)
|
||||
use expiration <- decode.field("expiration", time.datetime_decoder())
|
||||
use expiration <- decode.field("expiration", api.time_decoder())
|
||||
use size <- decode.field("size", survey_size.decoder())
|
||||
decode.success(Survey(signature:, symbol:, deposits:, expiration:, size:))
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/json.{type Json}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
|
||||
pub type SurveyDeposit {
|
||||
SurveyDeposit(symbol: TradeSymbol)
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue