1240 lines
36 KiB
Gleam
1240 lines
36 KiB
Gleam
import gleam/dynamic/decode.{type Decoder}
|
|
import gleam/json
|
|
import gleam/option.{type Option}
|
|
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 type ListShipsResponse {
|
|
ListShipsResponse(ships: List(Ship))
|
|
}
|
|
|
|
pub fn list_ships_decoder() -> Decoder(ListShipsResponse) {
|
|
use ships <- decode.then(decode.list(ship.decoder()))
|
|
decode.success(ListShipsResponse(ships:))
|
|
}
|
|
|
|
pub fn list_ships(
|
|
token: AgentToken,
|
|
page: Option(Int),
|
|
limit: Option(Int),
|
|
) -> ApiResponse(PagedData(ListShipsResponse)) {
|
|
let request = api.get_page(AgentAuth(token), "/my/ships", page, limit)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_paged_data_response(response, list_ships_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type PurchaseShipResponse {
|
|
PurchaseShipResponse(
|
|
ship: Ship,
|
|
agent: Agent,
|
|
transaction: ShipyardTransaction,
|
|
)
|
|
}
|
|
|
|
pub fn purchase_ship_decoder() -> Decoder(PurchaseShipResponse) {
|
|
use ship <- decode.field("ship", ship.decoder())
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
use transaction <- decode.field("transaction", shipyard_transaction.decoder())
|
|
decode.success(PurchaseShipResponse(ship:, agent:, transaction:))
|
|
}
|
|
|
|
pub fn purchase_ship(
|
|
token: AgentToken,
|
|
ship_type: ShipType,
|
|
waypoint_symbol: WaypointSymbol,
|
|
) -> ApiResponse(PurchaseShipResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships",
|
|
json.object([
|
|
#("shipType", ship_type.encode(ship_type)),
|
|
#("waypointSymbol", waypoint_symbol.encode(waypoint_symbol)),
|
|
]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, purchase_ship_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type GetShipResponse {
|
|
GetShipResponse(ship: Ship)
|
|
}
|
|
|
|
pub fn get_ship_decoder() -> Decoder(GetShipResponse) {
|
|
use ship <- decode.then(ship.decoder())
|
|
decode.success(GetShipResponse(ship:))
|
|
}
|
|
|
|
pub fn get_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(GetShipResponse) {
|
|
let request =
|
|
api.get(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, get_ship_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type CreateChartResponse {
|
|
CreateChartResponse(
|
|
chart: Chart,
|
|
waypoint: Waypoint,
|
|
transaction: ChartTransaction,
|
|
agent: Agent,
|
|
)
|
|
}
|
|
|
|
pub fn create_chart_response_decoder() -> Decoder(CreateChartResponse) {
|
|
use chart <- decode.field("chart", chart.decoder())
|
|
use waypoint <- decode.field("waypoint", waypoint.decoder())
|
|
use transaction <- decode.field("transaction", chart_transaction.decoder())
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
decode.success(CreateChartResponse(chart:, waypoint:, transaction:, agent:))
|
|
}
|
|
|
|
pub fn create_chart(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(CreateChartResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/chart",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, create_chart_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type NegotiateContractResponse {
|
|
NegotiateContractResponse(contract: Contract)
|
|
}
|
|
|
|
fn negotiate_contract_response_decoder() -> Decoder(NegotiateContractResponse) {
|
|
use contract <- decode.field("contract", contract.decoder())
|
|
decode.success(NegotiateContractResponse(contract:))
|
|
}
|
|
|
|
pub fn negotiate_contract(
|
|
token: AgentToken,
|
|
ship_symbol: String,
|
|
) -> ApiResponse(NegotiateContractResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol <> "/negotiate/contract",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 ->
|
|
api.parse_data_response(response, negotiate_contract_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type GetShipCooldownResponse {
|
|
GetShipCooldownResponse(cooldown: Option(Cooldown))
|
|
}
|
|
|
|
fn get_ship_cooldown_response_decoder() -> Decoder(GetShipCooldownResponse) {
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
let cooldown = option.Some(cooldown)
|
|
decode.success(GetShipCooldownResponse(cooldown:))
|
|
}
|
|
|
|
pub fn get_ship_cooldown(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(GetShipCooldownResponse) {
|
|
let request =
|
|
api.get(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/cooldown",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 ->
|
|
api.parse_data_response(response, get_ship_cooldown_response_decoder())
|
|
204 -> Ok(GetShipCooldownResponse(option.None))
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type DockShipResponse {
|
|
DockShipResponse(nav: ShipNav)
|
|
}
|
|
|
|
fn dock_ship_response_decoder() -> Decoder(DockShipResponse) {
|
|
use nav <- decode.field("nav", ship_nav.decoder())
|
|
decode.success(DockShipResponse(nav:))
|
|
}
|
|
|
|
pub fn dock_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(DockShipResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/dock",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, dock_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type ExtractResourcesResponse {
|
|
ExtractResourcesResponse(
|
|
extraction: Extraction,
|
|
cooldown: Cooldown,
|
|
cargo: ShipCargo,
|
|
modifiers: List(WaypointModifier),
|
|
events: List(ShipConditionEvent),
|
|
)
|
|
}
|
|
|
|
fn extract_resources_response_decoder() -> Decoder(ExtractResourcesResponse) {
|
|
use extraction <- decode.field("extraction", extraction.decoder())
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use modifiers <- decode.field(
|
|
"modifiers",
|
|
decode.list(waypoint_modifier.decoder()),
|
|
)
|
|
use events <- decode.field(
|
|
"events",
|
|
decode.list(ship_condition_event.decoder()),
|
|
)
|
|
decode.success(ExtractResourcesResponse(
|
|
extraction:,
|
|
cooldown:,
|
|
cargo:,
|
|
modifiers:,
|
|
events:,
|
|
))
|
|
}
|
|
|
|
pub fn extract_resources(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(ExtractResourcesResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/extract",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 ->
|
|
api.parse_data_response(response, extract_resources_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type ExtractResourcesWithSurveyResponse {
|
|
ExtractResourcesWithSurveyResponse(
|
|
extraction: Extraction,
|
|
cooldown: Cooldown,
|
|
cargo: ShipCargo,
|
|
modifiers: List(WaypointModifier),
|
|
events: List(ShipConditionEvent),
|
|
)
|
|
}
|
|
|
|
fn extract_resources_with_survey_response_decoder() -> Decoder(
|
|
ExtractResourcesWithSurveyResponse,
|
|
) {
|
|
use extraction <- decode.field("extraction", extraction.decoder())
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use modifiers <- decode.field(
|
|
"modifiers",
|
|
decode.list(waypoint_modifier.decoder()),
|
|
)
|
|
use events <- decode.field(
|
|
"events",
|
|
decode.list(ship_condition_event.decoder()),
|
|
)
|
|
decode.success(ExtractResourcesWithSurveyResponse(
|
|
extraction:,
|
|
cooldown:,
|
|
cargo:,
|
|
modifiers:,
|
|
events:,
|
|
))
|
|
}
|
|
|
|
pub fn extract_resources_with_survey(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
survey: Survey,
|
|
) -> ApiResponse(ExtractResourcesWithSurveyResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/extract/survey",
|
|
survey.encode(survey),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 ->
|
|
api.parse_data_response(
|
|
response,
|
|
extract_resources_with_survey_response_decoder(),
|
|
)
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type JettisonCargoResponse {
|
|
JettisonCargoResponse(cargo: ShipCargo)
|
|
}
|
|
|
|
fn jettison_cargo_response_decoder() -> Decoder(JettisonCargoResponse) {
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
decode.success(JettisonCargoResponse(cargo:))
|
|
}
|
|
|
|
pub fn jettison_cargo(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
trade_symbol: TradeSymbol,
|
|
units: Int,
|
|
) -> ApiResponse(JettisonCargoResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/jettison",
|
|
json.object([
|
|
#("symbol", trade_symbol.encode(trade_symbol)),
|
|
#("units", json.int(units)),
|
|
]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, jettison_cargo_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type JumpShipResponse {
|
|
JumpShipResponse(
|
|
nav: ShipNav,
|
|
cooldown: Cooldown,
|
|
transaction: MarketTransaction,
|
|
agent: Agent,
|
|
)
|
|
}
|
|
|
|
fn jump_ship_response_decoder() -> Decoder(JumpShipResponse) {
|
|
use nav <- decode.field("nav", ship_nav.decoder())
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use transaction <- decode.field("transaction", market_transaction.decoder())
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
decode.success(JumpShipResponse(nav:, cooldown:, transaction:, agent:))
|
|
}
|
|
|
|
pub fn jump_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
waypoint_symbol: WaypointSymbol,
|
|
) -> ApiResponse(JumpShipResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/jump",
|
|
json.object([#("waypointSymbol", waypoint_symbol.encode(waypoint_symbol))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, jump_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type ScanSystemsResponse {
|
|
ScanSystemsResponse(cooldown: Cooldown, systems: List(ScannedSystem))
|
|
}
|
|
|
|
fn scan_systems_response_decoder() -> Decoder(ScanSystemsResponse) {
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use systems <- decode.field("systems", decode.list(scanned_system.decoder()))
|
|
decode.success(ScanSystemsResponse(cooldown:, systems:))
|
|
}
|
|
|
|
pub fn scan_systems(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(ScanSystemsResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/scan/systems",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, scan_systems_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type ScanWaypointsResponse {
|
|
ScanWaypointsResponse(cooldown: Cooldown, waypoints: List(ScannedWaypoint))
|
|
}
|
|
|
|
fn scan_waypoints_response_decoder() -> Decoder(ScanWaypointsResponse) {
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use waypoints <- decode.field(
|
|
"waypoints",
|
|
decode.list(scanned_waypoint.decoder()),
|
|
)
|
|
decode.success(ScanWaypointsResponse(cooldown:, waypoints:))
|
|
}
|
|
|
|
pub fn scan_waypoints(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(ScanWaypointsResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/scan/waypoints",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, scan_waypoints_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type ScanShipsResponse {
|
|
ScanShipsResponse(cooldown: Cooldown, ships: List(ScannedShip))
|
|
}
|
|
|
|
fn scan_ships_response_decoder() -> Decoder(ScanShipsResponse) {
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use ships <- decode.field("ships", decode.list(scanned_ship.decoder()))
|
|
decode.success(ScanShipsResponse(cooldown:, ships:))
|
|
}
|
|
|
|
pub fn scan_ships(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(ScanShipsResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/scan/ships",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, scan_ships_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type ScrapShipResponse {
|
|
ScrapShipResponse(agent: Agent, transaction: ScrapTransaction)
|
|
}
|
|
|
|
fn scrap_ship_response_decoder() -> Decoder(ScrapShipResponse) {
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
use transaction <- decode.field("transaction", scrap_transaction.decoder())
|
|
decode.success(ScrapShipResponse(agent:, transaction:))
|
|
}
|
|
|
|
pub fn scrap_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(ScrapShipResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/scrap",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, scrap_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type GetScrapShipResponse {
|
|
GetScrapShipResponse(transaction: ScrapTransaction)
|
|
}
|
|
|
|
fn get_scrap_ship_response_decoder() -> Decoder(GetScrapShipResponse) {
|
|
use transaction <- decode.field("transaction", scrap_transaction.decoder())
|
|
decode.success(GetScrapShipResponse(transaction:))
|
|
}
|
|
|
|
pub fn get_scrap_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(GetScrapShipResponse) {
|
|
let request =
|
|
api.get(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/scrap",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, get_scrap_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type NavigateShipResponse {
|
|
NavigateShipResponse(
|
|
nav: ShipNav,
|
|
fuel: ShipFuel,
|
|
events: List(ShipConditionEvent),
|
|
)
|
|
}
|
|
|
|
fn navigate_ship_response_decoder() -> Decoder(NavigateShipResponse) {
|
|
use nav <- decode.field("nav", ship_nav.decoder())
|
|
use fuel <- decode.field("fuel", ship_fuel.decoder())
|
|
use events <- decode.field(
|
|
"events",
|
|
decode.list(ship_condition_event.decoder()),
|
|
)
|
|
decode.success(NavigateShipResponse(nav:, fuel:, events:))
|
|
}
|
|
|
|
pub fn navigate_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
waypoint_symbol: WaypointSymbol,
|
|
) -> ApiResponse(NavigateShipResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/navigate",
|
|
json.object([#("waypointSymbol", waypoint_symbol.encode(waypoint_symbol))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, navigate_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type WarpShipResponse {
|
|
WarpShipResponse(
|
|
nav: ShipNav,
|
|
fuel: ShipFuel,
|
|
events: List(ShipConditionEvent),
|
|
)
|
|
}
|
|
|
|
fn warp_ship_response_decoder() -> Decoder(WarpShipResponse) {
|
|
use nav <- decode.field("nav", ship_nav.decoder())
|
|
use fuel <- decode.field("fuel", ship_fuel.decoder())
|
|
use events <- decode.field(
|
|
"events",
|
|
decode.list(ship_condition_event.decoder()),
|
|
)
|
|
decode.success(WarpShipResponse(nav:, fuel:, events:))
|
|
}
|
|
|
|
pub fn warp_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
waypoint_symbol: WaypointSymbol,
|
|
) -> ApiResponse(WarpShipResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/warp",
|
|
json.object([#("waypointSymbol", waypoint_symbol.encode(waypoint_symbol))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, warp_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type OrbitShipResponse {
|
|
OrbitShipResponse(nav: ShipNav)
|
|
}
|
|
|
|
fn orbit_ship_response_decoder() -> Decoder(OrbitShipResponse) {
|
|
use nav <- decode.field("nav", ship_nav.decoder())
|
|
decode.success(OrbitShipResponse(nav:))
|
|
}
|
|
|
|
pub fn orbit_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(OrbitShipResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/orbit",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, orbit_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type PurchaseCargoResponse {
|
|
PurchaseCargoResponse(
|
|
cargo: ShipCargo,
|
|
transaction: MarketTransaction,
|
|
agent: Agent,
|
|
)
|
|
}
|
|
|
|
fn purchase_cargo_response_decoder() -> Decoder(PurchaseCargoResponse) {
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use transaction <- decode.field("transaction", market_transaction.decoder())
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
decode.success(PurchaseCargoResponse(cargo:, transaction:, agent:))
|
|
}
|
|
|
|
pub fn purchase_cargo(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
trade_symbol: TradeSymbol,
|
|
) -> ApiResponse(PurchaseCargoResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/purchase",
|
|
json.object([#("symbol", trade_symbol.encode(trade_symbol))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, purchase_cargo_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type RefineShipResponse {
|
|
RefineShipResponse(
|
|
cargo: ShipCargo,
|
|
cooldown: Cooldown,
|
|
produced: List(RefinementYield),
|
|
consumed: List(RefinementYield),
|
|
)
|
|
}
|
|
|
|
fn refine_ship_response_decoder() -> Decoder(RefineShipResponse) {
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use produced <- decode.field(
|
|
"produced",
|
|
decode.list(refinement_yield.decoder()),
|
|
)
|
|
use consumed <- decode.field(
|
|
"consumed",
|
|
decode.list(refinement_yield.decoder()),
|
|
)
|
|
decode.success(RefineShipResponse(cargo:, cooldown:, produced:, consumed:))
|
|
}
|
|
|
|
pub fn refine_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
produce: RefinementProduce,
|
|
) -> ApiResponse(RefineShipResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/refine",
|
|
json.object([#("produce", refinement_produce.encode(produce))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, refine_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type RefuelShipResponse {
|
|
RefuelShipResponse(
|
|
agent: Agent,
|
|
fuel: ShipFuel,
|
|
cargo: ShipCargo,
|
|
transaction: MarketTransaction,
|
|
)
|
|
}
|
|
|
|
pub fn refuel_ship_response_decoder() -> Decoder(RefuelShipResponse) {
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
use fuel <- decode.field("fuel", ship_fuel.decoder())
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use transaction <- decode.field("transaction", market_transaction.decoder())
|
|
decode.success(RefuelShipResponse(agent:, fuel:, cargo:, transaction:))
|
|
}
|
|
|
|
pub fn refuel_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
units: Option(Int),
|
|
from_cargo: Option(Bool),
|
|
) -> ApiResponse(RefuelShipResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/refuel",
|
|
json.object([
|
|
#("units", json.nullable(units, json.int)),
|
|
#("fromCargo", json.nullable(from_cargo, json.bool)),
|
|
]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, refuel_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type RepairShipResponse {
|
|
RepairShipResponse(agent: Agent, ship: Ship, transaction: RepairTransaction)
|
|
}
|
|
|
|
pub fn repair_ship_response_decoder() -> Decoder(RepairShipResponse) {
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
use ship <- decode.field("ship", ship.decoder())
|
|
use transaction <- decode.field("transaction", repair_transaction.decoder())
|
|
decode.success(RepairShipResponse(agent:, ship:, transaction:))
|
|
}
|
|
|
|
pub fn repair_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(RepairShipResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/repair",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, repair_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type GetRepairShipResponse {
|
|
GetRepairShipResponse(transaction: RepairTransaction)
|
|
}
|
|
|
|
pub fn get_repair_ship_response_decoder() -> Decoder(GetRepairShipResponse) {
|
|
use transaction <- decode.field("transaction", repair_transaction.decoder())
|
|
decode.success(GetRepairShipResponse(transaction:))
|
|
}
|
|
|
|
pub fn get_repair_ship(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(GetRepairShipResponse) {
|
|
let request =
|
|
api.get(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/repair",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, get_repair_ship_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type SellCargoResponse {
|
|
SellCargoResponse(
|
|
cargo: ShipCargo,
|
|
transaction: MarketTransaction,
|
|
agent: Agent,
|
|
)
|
|
}
|
|
|
|
pub fn sell_cargo_response_decoder() -> Decoder(SellCargoResponse) {
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use transaction <- decode.field("transaction", market_transaction.decoder())
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
decode.success(SellCargoResponse(cargo:, transaction:, agent:))
|
|
}
|
|
|
|
pub fn sell_cargo(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
trade_symbol: TradeSymbol,
|
|
units: Int,
|
|
) -> ApiResponse(SellCargoResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/sell",
|
|
json.object([
|
|
#("symbol", trade_symbol.encode(trade_symbol)),
|
|
#("units", json.int(units)),
|
|
]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, sell_cargo_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type SiphonResourcesResponse {
|
|
SiphonResourcesResponse(
|
|
siphon: Siphon,
|
|
cooldown: Cooldown,
|
|
cargo: ShipCargo,
|
|
events: List(ShipConditionEvent),
|
|
)
|
|
}
|
|
|
|
pub fn siphon_resources_response_decoder() -> Decoder(SiphonResourcesResponse) {
|
|
use siphon <- decode.field("siphon", siphon.decoder())
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use events <- decode.field(
|
|
"events",
|
|
decode.list(ship_condition_event.decoder()),
|
|
)
|
|
decode.success(SiphonResourcesResponse(siphon:, cooldown:, cargo:, events:))
|
|
}
|
|
|
|
pub fn siphon_resources(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(SiphonResourcesResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/siphon",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 ->
|
|
api.parse_data_response(response, siphon_resources_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type CreateSurveyResponse {
|
|
CreateSurveyResponse(cooldown: Cooldown, surveys: List(Survey))
|
|
}
|
|
|
|
pub fn create_survey_response_decoder() -> Decoder(CreateSurveyResponse) {
|
|
use cooldown <- decode.field("cooldown", cooldown.decoder())
|
|
use surveys <- decode.field("surveys", decode.list(survey.decoder()))
|
|
decode.success(CreateSurveyResponse(cooldown:, surveys:))
|
|
}
|
|
|
|
pub fn create_survey(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(CreateSurveyResponse) {
|
|
let request =
|
|
api.post(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/survey",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 -> api.parse_data_response(response, create_survey_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type TransferCargoResponse {
|
|
TransferCargoResponse(cargo: ShipCargo, target_cargo: ShipCargo)
|
|
}
|
|
|
|
pub fn transfer_cargo_response_decoder() -> Decoder(TransferCargoResponse) {
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use target_cargo <- decode.field("targetCargo", ship_cargo.decoder())
|
|
decode.success(TransferCargoResponse(cargo:, target_cargo:))
|
|
}
|
|
|
|
pub fn transfer_cargo(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
trade_symbol: TradeSymbol,
|
|
units: Int,
|
|
target_ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(TransferCargoResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/transfer",
|
|
json.object([
|
|
#("tradeSymbol", trade_symbol.encode(trade_symbol)),
|
|
#("units", json.int(units)),
|
|
#("shipSymbol", ship_symbol.encode(target_ship_symbol)),
|
|
]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, transfer_cargo_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type GetShipCargoResponse {
|
|
GetShipCargoResponse(cargo: ShipCargo)
|
|
}
|
|
|
|
pub fn get_ship_cargo_response_decoder() -> Decoder(GetShipCargoResponse) {
|
|
use cargo <- decode.then(ship_cargo.decoder())
|
|
decode.success(GetShipCargoResponse(cargo:))
|
|
}
|
|
|
|
pub fn get_ship_cargo(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(GetShipCargoResponse) {
|
|
let request =
|
|
api.get(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/cargo",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, get_ship_cargo_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type GetShipModulesResponse {
|
|
GetShipModulesResponse(modules: List(ShipModule))
|
|
}
|
|
|
|
pub fn get_ship_modules_response_decoder() -> Decoder(GetShipModulesResponse) {
|
|
use modules <- decode.then(decode.list(ship_module.decoder()))
|
|
decode.success(GetShipModulesResponse(modules:))
|
|
}
|
|
|
|
pub fn get_ship_modules(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(GetShipModulesResponse) {
|
|
let request =
|
|
api.get(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/modules",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 ->
|
|
api.parse_data_response(response, get_ship_modules_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type InstallShipModuleResponse {
|
|
InstallShipModuleResponse(
|
|
agent: Agent,
|
|
modules: List(ShipModule),
|
|
cargo: ShipCargo,
|
|
transaction: ShipModificationTransaction,
|
|
)
|
|
}
|
|
|
|
pub fn install_ship_module_response_decoder() -> Decoder(
|
|
InstallShipModuleResponse,
|
|
) {
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
use modules <- decode.field("modules", decode.list(ship_module.decoder()))
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use transaction <- decode.field(
|
|
"transaction",
|
|
ship_modification_transaction.decoder(),
|
|
)
|
|
decode.success(InstallShipModuleResponse(
|
|
agent:,
|
|
modules:,
|
|
cargo:,
|
|
transaction:,
|
|
))
|
|
}
|
|
|
|
pub fn install_ship_module(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
module_symbol: ModuleSymbol,
|
|
) -> ApiResponse(InstallShipModuleResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/modules/install",
|
|
json.object([#("symbol", module_symbol.encode(module_symbol))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 ->
|
|
api.parse_data_response(response, install_ship_module_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type RemoveShipModuleResponse {
|
|
RemoveShipModuleResponse(
|
|
agent: Agent,
|
|
modules: List(ShipModule),
|
|
cargo: ShipCargo,
|
|
transaction: ShipModificationTransaction,
|
|
)
|
|
}
|
|
|
|
pub fn remove_ship_module_response_decoder() -> Decoder(
|
|
RemoveShipModuleResponse,
|
|
) {
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
use modules <- decode.field("modules", decode.list(ship_module.decoder()))
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use transaction <- decode.field(
|
|
"transaction",
|
|
ship_modification_transaction.decoder(),
|
|
)
|
|
decode.success(RemoveShipModuleResponse(
|
|
agent:,
|
|
modules:,
|
|
cargo:,
|
|
transaction:,
|
|
))
|
|
}
|
|
|
|
pub fn remove_ship_module(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
module_symbol: ModuleSymbol,
|
|
) -> ApiResponse(RemoveShipModuleResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/modules/remove",
|
|
json.object([#("symbol", module_symbol.encode(module_symbol))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 ->
|
|
api.parse_data_response(response, remove_ship_module_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type GetShipMountsResponse {
|
|
GetShipMountsResponse(mounts: List(ShipMount))
|
|
}
|
|
|
|
pub fn get_ship_mounts_response_decoder() -> Decoder(GetShipMountsResponse) {
|
|
use mounts <- decode.then(decode.list(ship_mount.decoder()))
|
|
decode.success(GetShipMountsResponse(mounts:))
|
|
}
|
|
|
|
pub fn get_ship_mounts(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(GetShipMountsResponse) {
|
|
let request =
|
|
api.get(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/mounts",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, get_ship_mounts_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type InstallShipMountResponse {
|
|
InstallShipMountResponse(
|
|
agent: Agent,
|
|
mounts: List(ShipMount),
|
|
cargo: ShipCargo,
|
|
transaction: ShipModificationTransaction,
|
|
)
|
|
}
|
|
|
|
pub fn install_ship_mount_response_decoder() -> Decoder(
|
|
InstallShipMountResponse,
|
|
) {
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
use mounts <- decode.field("mounts", decode.list(ship_mount.decoder()))
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use transaction <- decode.field(
|
|
"transaction",
|
|
ship_modification_transaction.decoder(),
|
|
)
|
|
decode.success(InstallShipMountResponse(agent:, mounts:, cargo:, transaction:))
|
|
}
|
|
|
|
pub fn install_ship_mount(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
mount_symbol: MountSymbol,
|
|
) -> ApiResponse(InstallShipMountResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/mounts/install",
|
|
json.object([#("symbol", mount_symbol.encode(mount_symbol))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 ->
|
|
api.parse_data_response(response, install_ship_mount_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type RemoveShipMountResponse {
|
|
RemoveShipMountResponse(
|
|
agent: Agent,
|
|
mounts: List(ShipMount),
|
|
cargo: ShipCargo,
|
|
transaction: ShipModificationTransaction,
|
|
)
|
|
}
|
|
|
|
pub fn remove_ship_mount_response_decoder() -> Decoder(RemoveShipMountResponse) {
|
|
use agent <- decode.field("agent", agent.decoder())
|
|
use mounts <- decode.field("mounts", decode.list(ship_mount.decoder()))
|
|
use cargo <- decode.field("cargo", ship_cargo.decoder())
|
|
use transaction <- decode.field(
|
|
"transaction",
|
|
ship_modification_transaction.decoder(),
|
|
)
|
|
decode.success(RemoveShipMountResponse(agent:, mounts:, cargo:, transaction:))
|
|
}
|
|
|
|
pub fn remove_ship_mount(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
mount_symbol: MountSymbol,
|
|
) -> ApiResponse(RemoveShipMountResponse) {
|
|
let request =
|
|
api.post_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/mounts/remove",
|
|
json.object([#("symbol", mount_symbol.encode(mount_symbol))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
201 ->
|
|
api.parse_data_response(response, remove_ship_mount_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type GetShipNavResponse {
|
|
GetShipNavResponse(nav: ShipNav)
|
|
}
|
|
|
|
pub fn get_ship_nav_response_decoder() -> Decoder(GetShipNavResponse) {
|
|
use nav <- decode.then(ship_nav.decoder())
|
|
decode.success(GetShipNavResponse(nav:))
|
|
}
|
|
|
|
pub fn get_ship_nav(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
) -> ApiResponse(GetShipNavResponse) {
|
|
let request =
|
|
api.get(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/nav",
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, get_ship_nav_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|
|
|
|
pub type PatchShipNavResponse {
|
|
PatchShipNavResponse(
|
|
nav: ShipNav,
|
|
fuel: ShipFuel,
|
|
events: List(ShipConditionEvent),
|
|
)
|
|
}
|
|
|
|
pub fn patch_ship_nav_response_decoder() -> Decoder(PatchShipNavResponse) {
|
|
use nav <- decode.field("nav", ship_nav.decoder())
|
|
use fuel <- decode.field("fuel", ship_fuel.decoder())
|
|
use events <- decode.field(
|
|
"events",
|
|
decode.list(ship_condition_event.decoder()),
|
|
)
|
|
decode.success(PatchShipNavResponse(nav:, fuel:, events:))
|
|
}
|
|
|
|
pub fn patch_ship_nav(
|
|
token: AgentToken,
|
|
ship_symbol: ShipSymbol,
|
|
flight_mode: ShipNavFlightMode,
|
|
) -> ApiResponse(PatchShipNavResponse) {
|
|
let request =
|
|
api.patch_json(
|
|
AgentAuth(token),
|
|
"/my/ships/" <> ship_symbol.to_string(ship_symbol) <> "/nav",
|
|
json.object([#("flightMode", ship_nav_flight_mode.encode(flight_mode))]),
|
|
)
|
|
use response <- api.try_send(request)
|
|
case response.status {
|
|
200 -> api.parse_data_response(response, patch_ship_nav_response_decoder())
|
|
_ -> api.parse_error_response(response)
|
|
}
|
|
}
|