Compare commits
21 commits
Author | SHA1 | Date | |
---|---|---|---|
050cef92e4 | |||
de20cb5001 | |||
aed9b6413f | |||
a4edaa71e1 | |||
89ff1b3520 | |||
59ecc25dc7 | |||
35b1d0c1fc | |||
f9944d6878 | |||
70a30ff132 | |||
bc25e15faf | |||
c1a7debb84 | |||
c41a0c5dba | |||
6236a6f11f | |||
54f09d7635 | |||
d7fb43b292 | |||
97dc0228ea | |||
00fdca952f | |||
5d8599a33d | |||
bf4a2eef53 | |||
17631a1a0c | |||
2c607f64bc |
128 changed files with 2150 additions and 2654 deletions
|
@ -7,12 +7,11 @@
|
|||
gleam add spacetraders_sdk@1
|
||||
```
|
||||
```gleam
|
||||
import spacetraders_sdk
|
||||
import spacetraders_api
|
||||
|
||||
pub fn main() -> Nil {
|
||||
let assert Ok(server_status) = get_server_status()
|
||||
echo server_status
|
||||
Nil
|
||||
let assert Ok(server_status) = spacetraders_api.get_server_status()
|
||||
io.println(server_status.status)
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name = "spacetraders_sdk"
|
||||
version = "1.0.1"
|
||||
version = "1.5.5"
|
||||
gleam = ">= 1.11.0"
|
||||
description = "A Gleam SDK for the spacetraders.io game API"
|
||||
licences = ["MIT"]
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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 type GetAccountResponse {
|
||||
GetAccountResponse(account: Account)
|
||||
}
|
||||
|
||||
fn get_account_response_decoder() -> Decoder(GetAccountResponse) {
|
||||
use account <- decode.field("account", account.decoder())
|
||||
decode.success(GetAccountResponse(account:))
|
||||
}
|
||||
|
||||
pub fn get_account(token: AgentToken) -> ApiResponse(GetAccountResponse) {
|
||||
let request = api.get(AgentAuth(token), "/my/account")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, get_account_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type RegisterNewAgentResponse {
|
||||
RegisterNewAgentResponse(
|
||||
token: AgentToken,
|
||||
agent: Agent,
|
||||
faction: Faction,
|
||||
contract: Contract,
|
||||
ships: List(Ship),
|
||||
)
|
||||
}
|
||||
|
||||
fn register_new_agent_response_decoder() -> Decoder(RegisterNewAgentResponse) {
|
||||
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(RegisterNewAgentResponse(
|
||||
token:,
|
||||
agent:,
|
||||
faction:,
|
||||
contract:,
|
||||
ships:,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn register_new_agent(
|
||||
token: AccountToken,
|
||||
agent_symbol: AgentSymbol,
|
||||
faction_symbol: FactionSymbol,
|
||||
) -> ApiResponse(RegisterNewAgentResponse) {
|
||||
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, register_new_agent_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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 type ListPublicAgentsResponse {
|
||||
ListPublicAgentsResponse(agents: List(PublicAgent))
|
||||
}
|
||||
|
||||
fn list_public_agents_response_decoder() -> Decoder(ListPublicAgentsResponse) {
|
||||
use agents <- decode.then(decode.list(public_agent.decoder()))
|
||||
decode.success(ListPublicAgentsResponse(agents:))
|
||||
}
|
||||
|
||||
pub fn list_public_agents(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(ListPublicAgentsResponse)) {
|
||||
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,
|
||||
list_public_agents_response_decoder(),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetPublicAgentResponse {
|
||||
GetPublicAgentResponse(agent: PublicAgent)
|
||||
}
|
||||
|
||||
fn get_public_agent_response_decoder() -> Decoder(GetPublicAgentResponse) {
|
||||
use agent <- decode.then(public_agent.decoder())
|
||||
decode.success(GetPublicAgentResponse(agent:))
|
||||
}
|
||||
|
||||
pub fn get_public_agent(
|
||||
token: AgentToken,
|
||||
agent_symbol: AgentSymbol,
|
||||
) -> ApiResponse(GetPublicAgentResponse) {
|
||||
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, get_public_agent_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetAgentResponse {
|
||||
GetAgentResponse(agent: Agent)
|
||||
}
|
||||
|
||||
fn get_agent_response_decoder() -> decode.Decoder(GetAgentResponse) {
|
||||
use agent <- decode.then(agent.decoder())
|
||||
decode.success(GetAgentResponse(agent:))
|
||||
}
|
||||
|
||||
pub fn get_agent(token: AgentToken) -> ApiResponse(GetAgentResponse) {
|
||||
let request = api.get(AgentAuth(token), "/my/agent")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_data_response(response, get_agent_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetAgentEventsResponse {
|
||||
GetAgentEventsResponse(events: List(AgentEvent))
|
||||
}
|
||||
|
||||
fn get_agent_events_response_decoder() -> Decoder(GetAgentEventsResponse) {
|
||||
use events <- decode.then(decode.list(agent_event.decoder()))
|
||||
decode.success(GetAgentEventsResponse(events:))
|
||||
}
|
||||
|
||||
pub fn get_agent_events(
|
||||
token: AgentToken,
|
||||
) -> ApiResponse(GetAgentEventsResponse) {
|
||||
let request = api.get(AgentAuth(token), "/my/agent/events")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, get_agent_events_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
import endpoints/fleet
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
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 type ListContractsResponse {
|
||||
ListContractsResponse(contracts: List(Contract))
|
||||
}
|
||||
|
||||
fn list_contracts_response_decoder() -> Decoder(ListContractsResponse) {
|
||||
use contracts <- decode.then(decode.list(contract.decoder()))
|
||||
decode.success(ListContractsResponse(contracts:))
|
||||
}
|
||||
|
||||
pub fn list_contracts(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(ListContractsResponse)) {
|
||||
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, list_contracts_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetContractResponse {
|
||||
GetContractResponse(contract: Contract)
|
||||
}
|
||||
|
||||
fn get_contract_response_decoder() -> Decoder(GetContractResponse) {
|
||||
use contract <- decode.then(contract.decoder())
|
||||
decode.success(GetContractResponse(contract:))
|
||||
}
|
||||
|
||||
pub fn get_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(GetContractResponse) {
|
||||
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, get_contract_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type AcceptContractResponse {
|
||||
AcceptContractResponse(contract: Contract, agent: Agent)
|
||||
}
|
||||
|
||||
fn accept_contract_response_decoder() -> Decoder(AcceptContractResponse) {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use agent <- decode.field("agent", agent.decoder())
|
||||
decode.success(AcceptContractResponse(contract:, agent:))
|
||||
}
|
||||
|
||||
pub fn accept_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(AcceptContractResponse) {
|
||||
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, accept_contract_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type FulfillContractResponse {
|
||||
FulfillContractResponse(contract: Contract, agent: Agent)
|
||||
}
|
||||
|
||||
fn fulfill_contract_response_decoder() -> Decoder(FulfillContractResponse) {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use agent <- decode.field("agent", agent.decoder())
|
||||
decode.success(FulfillContractResponse(contract:, agent:))
|
||||
}
|
||||
|
||||
pub fn fulfill_contract(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
) -> ApiResponse(FulfillContractResponse) {
|
||||
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, fulfill_contract_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type DeliverContractCargoResponse {
|
||||
DeliverContractCargoResponse(contract: Contract, cargo: ShipCargo)
|
||||
}
|
||||
|
||||
fn deliver_contract_cargo_response_decoder() -> Decoder(
|
||||
DeliverContractCargoResponse,
|
||||
) {
|
||||
use contract <- decode.field("contract", contract.decoder())
|
||||
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
||||
decode.success(DeliverContractCargoResponse(contract:, cargo:))
|
||||
}
|
||||
|
||||
pub fn deliver_contract_cargo(
|
||||
token: AgentToken,
|
||||
contract_id: ContractId,
|
||||
ship_symbol: ShipSymbol,
|
||||
trade_symbol: TradeSymbol,
|
||||
units: Int,
|
||||
) -> ApiResponse(DeliverContractCargoResponse) {
|
||||
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,
|
||||
deliver_contract_cargo_response_decoder(),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub const negotiate_contract = fleet.negotiate_contract
|
|
@ -1,28 +0,0 @@
|
|||
import gleam/dict.{type Dict}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import utils/api.{type ApiResponse}
|
||||
import utils/auth.{type AgentToken, AgentAuth}
|
||||
|
||||
pub type GetSupplyChainResponse {
|
||||
GetSupplyChainResponse(export_to_import_map: Dict(String, String))
|
||||
}
|
||||
|
||||
fn get_supply_chain_response_decoder() -> Decoder(GetSupplyChainResponse) {
|
||||
use export_to_import_map <- decode.field(
|
||||
"exportToImportMap",
|
||||
decode.dict(decode.string, decode.string),
|
||||
)
|
||||
decode.success(GetSupplyChainResponse(export_to_import_map:))
|
||||
}
|
||||
|
||||
pub fn get_supply_chain(
|
||||
token: AgentToken,
|
||||
) -> ApiResponse(GetSupplyChainResponse) {
|
||||
let request = api.get(AgentAuth(token), "/market/supply-chain")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 ->
|
||||
api.parse_data_response(response, get_supply_chain_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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 type ListFactionsResponse {
|
||||
ListFactionsResponse(factions: List(Faction))
|
||||
}
|
||||
|
||||
fn list_factions_response_decoder() -> Decoder(ListFactionsResponse) {
|
||||
use factions <- decode.then(decode.list(faction.decoder()))
|
||||
decode.success(ListFactionsResponse(factions:))
|
||||
}
|
||||
|
||||
pub fn list_factions(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(ListFactionsResponse)) {
|
||||
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, list_factions_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetFactionResponse {
|
||||
GetFactionResponse(faction: Faction)
|
||||
}
|
||||
|
||||
fn get_faction_response_decoder() -> Decoder(GetFactionResponse) {
|
||||
use faction <- decode.then(faction.decoder())
|
||||
decode.success(GetFactionResponse(faction:))
|
||||
}
|
||||
|
||||
pub fn get_faction(
|
||||
token: AgentToken,
|
||||
symbol: FactionSymbol,
|
||||
) -> ApiResponse(GetFactionResponse) {
|
||||
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, get_faction_response_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 type GetMyFactionsResponse {
|
||||
GetMyFactionsResponse(faction_reputations: List(FactionReputation))
|
||||
}
|
||||
|
||||
fn get_my_factions_response_decoder() -> Decoder(GetMyFactionsResponse) {
|
||||
use faction_reputations <- decode.then(
|
||||
decode.list(faction_reputation_decoder()),
|
||||
)
|
||||
decode.success(GetMyFactionsResponse(faction_reputations:))
|
||||
}
|
||||
|
||||
pub fn get_my_factions(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(GetMyFactionsResponse)) {
|
||||
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,
|
||||
get_my_factions_response_decoder(),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,192 +0,0 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
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(String))
|
||||
}
|
||||
|
||||
fn health_decoder() -> Decoder(Health) {
|
||||
use last_market_update <- decode.optional_field(
|
||||
"lastMarketUpdate",
|
||||
option.None,
|
||||
decode.optional(decode.string),
|
||||
)
|
||||
decode.success(Health(last_market_update:))
|
||||
}
|
||||
|
||||
pub type CreditLeaderboardEntry {
|
||||
CreditLeaderboardEntry(agent_symbol: String, credits: Int)
|
||||
}
|
||||
|
||||
fn credit_leaderboard_entry_decoder() -> Decoder(CreditLeaderboardEntry) {
|
||||
use agent_symbol <- decode.field("agentSymbol", decode.string)
|
||||
use credits <- decode.field("credits", decode.int)
|
||||
decode.success(CreditLeaderboardEntry(agent_symbol:, credits:))
|
||||
}
|
||||
|
||||
pub type ChartLeaderboardEntry {
|
||||
ChartLeaderboardEntry(agent_symbol: String, chart_count: Int)
|
||||
}
|
||||
|
||||
fn chart_leaderboard_entry_decoder() -> Decoder(ChartLeaderboardEntry) {
|
||||
use agent_symbol <- decode.field("agentSymbol", decode.string)
|
||||
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: String, frequency: String)
|
||||
}
|
||||
|
||||
fn server_resets_decoder() -> Decoder(ServerResets) {
|
||||
use next <- decode.field("next", decode.string)
|
||||
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: String)
|
||||
}
|
||||
|
||||
fn link_decoder() -> Decoder(Link) {
|
||||
use name <- decode.field("name", decode.string)
|
||||
use url <- decode.field("url", decode.string)
|
||||
decode.success(Link(name:, url:))
|
||||
}
|
||||
|
||||
pub type GetServerStatusResponse {
|
||||
GetServerStatusResponse(
|
||||
status: String,
|
||||
version: String,
|
||||
reset_date: String,
|
||||
description: String,
|
||||
stats: Stats,
|
||||
health: Health,
|
||||
leaderboards: Leaderboards,
|
||||
server_resets: ServerResets,
|
||||
announcements: List(Announcement),
|
||||
links: List(Link),
|
||||
)
|
||||
}
|
||||
|
||||
fn get_server_status_response_decoder() -> Decoder(GetServerStatusResponse) {
|
||||
use status <- decode.field("status", decode.string)
|
||||
use version <- decode.field("version", decode.string)
|
||||
use reset_date <- decode.field("resetDate", decode.string)
|
||||
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(GetServerStatusResponse(
|
||||
status:,
|
||||
version:,
|
||||
reset_date:,
|
||||
description:,
|
||||
stats:,
|
||||
health:,
|
||||
leaderboards:,
|
||||
server_resets:,
|
||||
announcements:,
|
||||
links:,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn get_server_status() -> ApiResponse(GetServerStatusResponse) {
|
||||
let request = api.get(NoAuth, "/")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_response(response, get_server_status_response_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 type ListErrorCodesResponse {
|
||||
ListErrorCodesResponse(error_codes: List(ErrorCode))
|
||||
}
|
||||
|
||||
fn list_error_codes_response_decoder() -> Decoder(ListErrorCodesResponse) {
|
||||
use error_codes <- decode.field(
|
||||
"errorCodes",
|
||||
decode.list(error_code_decoder()),
|
||||
)
|
||||
decode.success(ListErrorCodesResponse(error_codes:))
|
||||
}
|
||||
|
||||
pub fn list_error_codes() -> ApiResponse(ListErrorCodesResponse) {
|
||||
let request = api.get(NoAuth, "/error-codes")
|
||||
use response <- api.try_send(request)
|
||||
case response.status {
|
||||
200 -> api.parse_response(response, list_error_codes_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
|
@ -1,313 +0,0 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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 type ListSystemsResponse {
|
||||
ListSystemsResponse(systems: List(System))
|
||||
}
|
||||
|
||||
fn list_systems_response_decoder() -> Decoder(ListSystemsResponse) {
|
||||
use systems <- decode.then(decode.list(system.decoder()))
|
||||
decode.success(ListSystemsResponse(systems:))
|
||||
}
|
||||
|
||||
pub fn list_systems(
|
||||
token: AgentToken,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
) -> ApiResponse(PagedData(ListSystemsResponse)) {
|
||||
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, list_systems_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetSystemResponse {
|
||||
GetSystemResponse(system: System)
|
||||
}
|
||||
|
||||
fn get_system_response_decoder() -> Decoder(GetSystemResponse) {
|
||||
use system <- decode.then(system.decoder())
|
||||
decode.success(GetSystemResponse(system:))
|
||||
}
|
||||
|
||||
pub fn get_system(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
) -> ApiResponse(GetSystemResponse) {
|
||||
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, get_system_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type ListSystemWaypointsResponse {
|
||||
ListSystemWaypointsResponse(waypoints: List(Waypoint))
|
||||
}
|
||||
|
||||
fn list_system_waypoints_response_decoder() -> Decoder(
|
||||
ListSystemWaypointsResponse,
|
||||
) {
|
||||
use waypoints <- decode.then(decode.list(waypoint.decoder()))
|
||||
decode.success(ListSystemWaypointsResponse(waypoints:))
|
||||
}
|
||||
|
||||
pub fn list_system_waypoints(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
page: Option(Int),
|
||||
limit: Option(Int),
|
||||
type_: Option(WaypointType),
|
||||
traits: List(WaypointTraitSymbol),
|
||||
) -> ApiResponse(PagedData(ListSystemWaypointsResponse)) {
|
||||
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_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,
|
||||
list_system_waypoints_response_decoder(),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetWaypointResponse {
|
||||
GetWaypointResponse(waypoint: Waypoint)
|
||||
}
|
||||
|
||||
fn get_waypoint_response_decoder() -> Decoder(GetWaypointResponse) {
|
||||
use waypoint <- decode.then(waypoint.decoder())
|
||||
decode.success(GetWaypointResponse(waypoint:))
|
||||
}
|
||||
|
||||
pub fn get_waypoint(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(GetWaypointResponse) {
|
||||
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, get_waypoint_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetConstructionSiteResponse {
|
||||
GetConstructionSiteResponse(construction: Construction)
|
||||
}
|
||||
|
||||
fn get_construction_site_response_decoder() -> Decoder(
|
||||
GetConstructionSiteResponse,
|
||||
) {
|
||||
use construction <- decode.then(construction.decoder())
|
||||
decode.success(GetConstructionSiteResponse(construction:))
|
||||
}
|
||||
|
||||
pub fn get_construction_site(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(GetConstructionSiteResponse) {
|
||||
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,
|
||||
get_construction_site_response_decoder(),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type SupplyConstructionSiteResponse {
|
||||
SupplyConstructionSiteResponse(construction: Construction, cargo: ShipCargo)
|
||||
}
|
||||
|
||||
fn supply_construction_site_response_decoder() -> Decoder(
|
||||
SupplyConstructionSiteResponse,
|
||||
) {
|
||||
use construction <- decode.field("construction", construction.decoder())
|
||||
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
||||
decode.success(SupplyConstructionSiteResponse(construction:, cargo:))
|
||||
}
|
||||
|
||||
pub fn supply_construction_site(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
ship_symbol: ShipSymbol,
|
||||
trade_symbol: TradeSymbol,
|
||||
units: Int,
|
||||
) -> ApiResponse(SupplyConstructionSiteResponse) {
|
||||
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,
|
||||
supply_construction_site_response_decoder(),
|
||||
)
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetMarketResponse {
|
||||
GetMarketResponse(market: Market)
|
||||
}
|
||||
|
||||
fn get_market_response_decoder() -> Decoder(GetMarketResponse) {
|
||||
use market <- decode.then(market.decoder())
|
||||
decode.success(GetMarketResponse(market:))
|
||||
}
|
||||
|
||||
pub fn get_market(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(GetMarketResponse) {
|
||||
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, get_market_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetJumpGateResponse {
|
||||
GetJumpGateResponse(jump_gate: JumpGate)
|
||||
}
|
||||
|
||||
fn get_jump_gate_response_decoder() -> Decoder(GetJumpGateResponse) {
|
||||
use jump_gate <- decode.then(jump_gate.decoder())
|
||||
decode.success(GetJumpGateResponse(jump_gate:))
|
||||
}
|
||||
|
||||
pub fn get_jump_gate(
|
||||
token: AgentToken,
|
||||
system_symbol: SystemSymbol,
|
||||
waypoint_symbol: WaypointSymbol,
|
||||
) -> ApiResponse(GetJumpGateResponse) {
|
||||
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, get_jump_gate_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
||||
|
||||
pub type GetShipyardResponse {
|
||||
GetShipyardResponse(shipyard: Shipyard)
|
||||
}
|
||||
|
||||
fn get_shipyard_response_decoder() -> Decoder(GetShipyardResponse) {
|
||||
use shipyard <- decode.then(shipyard.decoder())
|
||||
decode.success(GetShipyardResponse(shipyard:))
|
||||
}
|
||||
|
||||
pub fn get_shipyard(
|
||||
token,
|
||||
system_symbol,
|
||||
waypoint_symbol,
|
||||
) -> ApiResponse(GetShipyardResponse) {
|
||||
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, get_shipyard_response_decoder())
|
||||
_ -> api.parse_error_response(response)
|
||||
}
|
||||
}
|
1767
src/spacetraders_api.gleam
Normal file
1767
src/spacetraders_api.gleam
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,8 +1,8 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import models/account_id.{type AccountId}
|
||||
import utils/api
|
||||
import spacetraders_models/account_id.{type AccountId}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
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", api.time_decoder())
|
||||
use created_at <- decode.field("createdAt", time.datetime_decoder())
|
||||
decode.success(Account(id:, email:, token:, created_at:))
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/account_id.{type AccountId}
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
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}
|
||||
|
||||
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 models/agent_event_id.{type AgentEventId}
|
||||
import utils/api
|
||||
import spacetraders_models/agent_event_id.{type AgentEventId}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
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", api.time_decoder())
|
||||
use created_at <- decode.field("createdAt", time.datetime_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 models/agent_symbol.{type AgentSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
import spacetraders_models/agent_symbol.{type AgentSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
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", api.time_decoder())
|
||||
use submitted_on <- decode.field("submittedOn", time.datetime_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 models/ship_symbol.{type ShipSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
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", api.time_decoder())
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
decode.success(ChartTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/construction_material.{type ConstructionMaterial}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_models/construction_material.{type ConstructionMaterial}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type Construction {
|
||||
Construction(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_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 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
|
||||
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
|
||||
|
||||
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(api.time_decoder()),
|
||||
decode.optional(time.datetime_decoder()),
|
||||
)
|
||||
decode.success(Contract(
|
||||
id:,
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_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 models/contract_deliver_good.{type ContractDeliverGood}
|
||||
import models/contract_payment.{type ContractPayment}
|
||||
import utils/api
|
||||
import spacetraders_models/contract_deliver_good.{type ContractDeliverGood}
|
||||
import spacetraders_models/contract_payment.{type ContractPayment}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
pub type ContractTerms {
|
||||
ContractTerms(
|
||||
|
@ -14,7 +14,7 @@ pub type ContractTerms {
|
|||
}
|
||||
|
||||
pub fn decoder() -> Decoder(ContractTerms) {
|
||||
use deadline <- decode.field("deadline", api.time_decoder())
|
||||
use deadline <- decode.field("deadline", time.datetime_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 models/ship_symbol.{type ShipSymbol}
|
||||
import utils/api
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
pub type Cooldown {
|
||||
Cooldown(
|
||||
|
@ -20,7 +20,7 @@ pub fn decoder() -> Decoder(Cooldown) {
|
|||
use expiration <- decode.optional_field(
|
||||
"expiration",
|
||||
option.None,
|
||||
decode.optional(api.time_decoder()),
|
||||
decode.optional(time.datetime_decoder()),
|
||||
)
|
||||
decode.success(Cooldown(
|
||||
ship_symbol:,
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/extraction_yield.{type ExtractionYield}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/extraction_yield.{type ExtractionYield}
|
||||
import spacetraders_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 models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_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 models/faction_symbol.{type FactionSymbol}
|
||||
import models/faction_trait.{type FactionTrait}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_models/faction_trait.{type FactionTrait}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type Faction {
|
||||
Faction(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/faction_trait_symbol.{type FactionTraitSymbol}
|
||||
import spacetraders_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 models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_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 models/market_symbol.{type MarketSymbol}
|
||||
import models/market_trade_good.{type MarketTradeGood}
|
||||
import models/market_transaction.{type MarketTransaction}
|
||||
import models/trade_good.{type TradeGood}
|
||||
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}
|
||||
|
||||
pub type Market {
|
||||
Market(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
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}
|
||||
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}
|
||||
|
||||
pub type MarketTradeGood {
|
||||
MarketTradeGood(
|
|
@ -1,10 +1,10 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
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
|
||||
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
|
||||
|
||||
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", api.time_decoder())
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
decode.success(MarketTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,7 +1,7 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_models/agent_symbol.{type AgentSymbol}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
|
||||
pub type PublicAgent {
|
||||
PublicAgent(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_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 models/ship_symbol.{type ShipSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
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", api.time_decoder())
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
decode.success(RepairTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,12 +1,12 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
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}
|
||||
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}
|
||||
|
||||
pub type ScannedShip {
|
||||
ScannedShip(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/engine_symbol.{type EngineSymbol}
|
||||
import spacetraders_models/engine_symbol.{type EngineSymbol}
|
||||
|
||||
pub type ScannedShipEngine {
|
||||
ScannedShipEngine(symbol: EngineSymbol)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/frame_symbol.{type FrameSymbol}
|
||||
import spacetraders_models/frame_symbol.{type FrameSymbol}
|
||||
|
||||
pub type ScannedShipFrame {
|
||||
ScannedShipFrame(symbol: FrameSymbol)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/mount_symbol.{type MountSymbol}
|
||||
import spacetraders_models/mount_symbol.{type MountSymbol}
|
||||
|
||||
pub type ScannedShipMount {
|
||||
ScannedShipMount(symbol: MountSymbol)
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/reactor_symbol.{type ReactorSymbol}
|
||||
import spacetraders_models/reactor_symbol.{type ReactorSymbol}
|
||||
|
||||
pub type ScannedShipReactor {
|
||||
ScannedShipReactor(symbol: ReactorSymbol)
|
|
@ -1,7 +1,7 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/sector_symbol.{type SectorSymbol}
|
||||
import models/system_symbol.{type SystemSymbol}
|
||||
import models/system_type.{type SystemType}
|
||||
import spacetraders_models/sector_symbol.{type SectorSymbol}
|
||||
import spacetraders_models/system_symbol.{type SystemSymbol}
|
||||
import spacetraders_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 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}
|
||||
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}
|
||||
|
||||
pub type ScannedWaypoint {
|
||||
ScannedWaypoint(
|
|
@ -1,8 +1,8 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
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", api.time_decoder())
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
decode.success(ScrapTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,16 +1,16 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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}
|
||||
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}
|
||||
|
||||
pub type Ship {
|
||||
Ship(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/ship_cargo_item.{type ShipCargoItem}
|
||||
import spacetraders_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 models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_models/trade_symbol.{type TradeSymbol}
|
||||
|
||||
pub type ShipCargoItem {
|
||||
ShipCargoItem(
|
|
@ -1,4 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/int
|
||||
import gleam/json.{type Json}
|
||||
|
||||
pub opaque type ShipComponentCondition {
|
||||
|
@ -17,7 +18,11 @@ pub fn parse(value: Float) -> Result(ShipComponentCondition, Nil) {
|
|||
}
|
||||
|
||||
pub fn decoder() -> Decoder(ShipComponentCondition) {
|
||||
use value <- decode.then(decode.float)
|
||||
use value <- decode.then(
|
||||
decode.one_of(decode.float, [
|
||||
decode.then(decode.int, fn(i) { decode.success(int.to_float(i)) }),
|
||||
]),
|
||||
)
|
||||
case parse(value) {
|
||||
Ok(ship_component_condition) -> decode.success(ship_component_condition)
|
||||
Error(Nil) ->
|
|
@ -1,4 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/int
|
||||
import gleam/json.{type Json}
|
||||
|
||||
pub opaque type ShipComponentIntegrity {
|
||||
|
@ -17,7 +18,11 @@ pub fn parse(value: Float) -> Result(ShipComponentIntegrity, Nil) {
|
|||
}
|
||||
|
||||
pub fn decoder() -> Decoder(ShipComponentIntegrity) {
|
||||
use value <- decode.then(decode.float)
|
||||
use value <- decode.then(
|
||||
decode.one_of(decode.float, [
|
||||
decode.then(decode.int, fn(i) { decode.success(int.to_float(i)) }),
|
||||
]),
|
||||
)
|
||||
case parse(value) {
|
||||
Ok(ship_component_integrity) -> decode.success(ship_component_integrity)
|
||||
Error(Nil) ->
|
|
@ -1,6 +1,8 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/ship_component.{type ShipComponent}
|
||||
import models/ship_condition_event_symbol.{type ShipConditionEventSymbol}
|
||||
import spacetraders_models/ship_component.{type ShipComponent}
|
||||
import spacetraders_models/ship_condition_event_symbol.{
|
||||
type ShipConditionEventSymbol,
|
||||
}
|
||||
|
||||
pub type ShipConditionEvent {
|
||||
ShipConditionEvent(
|
|
@ -1,5 +1,5 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/crew_rotation.{type CrewRotation}
|
||||
import spacetraders_models/crew_rotation.{type CrewRotation}
|
||||
|
||||
pub type ShipCrew {
|
||||
ShipCrew(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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}
|
||||
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}
|
||||
|
||||
pub type ShipEngine {
|
||||
ShipEngine(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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}
|
||||
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}
|
||||
|
||||
pub type ShipFrame {
|
||||
ShipFrame(
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import models/ship_fuel_consumed.{type ShipFuelConsumed}
|
||||
import spacetraders_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 utils/api
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
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", api.time_decoder())
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
decode.success(ShipFuelConsumed(amount:, timestamp:))
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/trade_symbol.{type TradeSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
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
|
||||
|
||||
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", api.time_decoder())
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
decode.success(ShipModificationTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_symbol:,
|
|
@ -1,7 +1,7 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
import models/module_symbol.{type ModuleSymbol}
|
||||
import models/ship_requirements.{type ShipRequirements}
|
||||
import spacetraders_models/module_symbol.{type ModuleSymbol}
|
||||
import spacetraders_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 models/mount_deposit.{type MountDeposit}
|
||||
import models/mount_symbol.{type MountSymbol}
|
||||
import models/ship_requirements.{type ShipRequirements}
|
||||
import spacetraders_models/mount_deposit.{type MountDeposit}
|
||||
import spacetraders_models/mount_symbol.{type MountSymbol}
|
||||
import spacetraders_models/ship_requirements.{type ShipRequirements}
|
||||
|
||||
pub type ShipMount {
|
||||
ShipMount(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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}
|
||||
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}
|
||||
|
||||
pub type ShipNav {
|
||||
ShipNav(
|
|
@ -1,7 +1,7 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/ship_nav_route_waypoint.{type ShipNavRouteWaypoint}
|
||||
import utils/api
|
||||
import spacetraders_models/ship_nav_route_waypoint.{type ShipNavRouteWaypoint}
|
||||
import spacetraders_sdk/internal/time
|
||||
|
||||
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", api.time_decoder())
|
||||
use arrival <- decode.field("arrival", api.time_decoder())
|
||||
use departure_time <- decode.field("departureTime", time.datetime_decoder())
|
||||
use arrival <- decode.field("arrival", time.datetime_decoder())
|
||||
decode.success(ShipNavRoute(destination:, origin:, departure_time:, arrival:))
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/system_symbol.{type SystemSymbol}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import models/waypoint_type.{type WaypointType}
|
||||
import spacetraders_models/system_symbol.{type SystemSymbol}
|
||||
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
||||
import spacetraders_models/waypoint_type.{type WaypointType}
|
||||
|
||||
pub type ShipNavRouteWaypoint {
|
||||
ShipNavRouteWaypoint(
|
|
@ -1,9 +1,9 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
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}
|
||||
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}
|
||||
|
||||
pub type ShipReactor {
|
||||
ShipReactor(
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/faction_symbol.{type FactionSymbol}
|
||||
import models/ship_role.{type ShipRole}
|
||||
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
||||
import spacetraders_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 models/ship_type.{type ShipType}
|
||||
import models/shipyard_ship.{type ShipyardShip}
|
||||
import models/shipyard_symbol.{type ShipyardSymbol}
|
||||
import models/shipyard_transaction.{type ShipyardTransaction}
|
||||
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}
|
||||
|
||||
pub type Shipyard {
|
||||
Shipyard(
|
|
@ -1,14 +1,14 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import gleam/option.{type Option}
|
||||
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}
|
||||
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}
|
||||
|
||||
pub type ShipyardShip {
|
||||
ShipyardShip(
|
|
@ -1,9 +1,9 @@
|
|||
import birl.{type Time}
|
||||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/agent_symbol.{type AgentSymbol}
|
||||
import models/ship_type.{type ShipType}
|
||||
import models/waypoint_symbol.{type WaypointSymbol}
|
||||
import utils/api
|
||||
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
|
||||
|
||||
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", api.time_decoder())
|
||||
use timestamp <- decode.field("timestamp", time.datetime_decoder())
|
||||
decode.success(ShipyardTransaction(
|
||||
waypoint_symbol:,
|
||||
ship_type:,
|
|
@ -1,6 +1,6 @@
|
|||
import gleam/dynamic/decode.{type Decoder}
|
||||
import models/ship_symbol.{type ShipSymbol}
|
||||
import models/siphon_yield.{type SiphonYield}
|
||||
import spacetraders_models/ship_symbol.{type ShipSymbol}
|
||||
import spacetraders_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 models/trade_symbol.{type TradeSymbol}
|
||||
import spacetraders_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 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
|
||||
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
|
||||
|
||||
pub type Survey {
|
||||
Survey(
|
||||
|
@ -24,7 +24,7 @@ pub fn decoder() -> Decoder(Survey) {
|
|||
"deposits",
|
||||
decode.list(survey_deposit.decoder()),
|
||||
)
|
||||
use expiration <- decode.field("expiration", api.time_decoder())
|
||||
use expiration <- decode.field("expiration", time.datetime_decoder())
|
||||
use size <- decode.field("size", survey_size.decoder())
|
||||
decode.success(Survey(signature:, symbol:, deposits:, expiration:, size:))
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue