Remove unnecessary authentication for unauthenticated endpoints
This commit is contained in:
parent
bf4a2eef53
commit
5d8599a33d
3 changed files with 28 additions and 55 deletions
|
@ -5,14 +5,13 @@ import models/agent_event.{type AgentEvent}
|
||||||
import models/agent_symbol.{type AgentSymbol}
|
import models/agent_symbol.{type AgentSymbol}
|
||||||
import models/public_agent.{type PublicAgent}
|
import models/public_agent.{type PublicAgent}
|
||||||
import utils/api.{type ApiResponse, type PagedData}
|
import utils/api.{type ApiResponse, type PagedData}
|
||||||
import utils/auth.{type AgentToken, AgentAuth}
|
import utils/auth.{type AgentToken, AgentAuth, NoAuth}
|
||||||
|
|
||||||
pub fn list_public_agents(
|
pub fn list_public_agents(
|
||||||
token: AgentToken,
|
|
||||||
page: Option(Int),
|
page: Option(Int),
|
||||||
limit: Option(Int),
|
limit: Option(Int),
|
||||||
) -> ApiResponse(PagedData(List(PublicAgent))) {
|
) -> ApiResponse(PagedData(List(PublicAgent))) {
|
||||||
let request = api.get_page(AgentAuth(token), "/agents", page, limit)
|
let request = api.get_page(NoAuth, "/agents", page, limit)
|
||||||
use response <- api.try_send(request)
|
use response <- api.try_send(request)
|
||||||
case response.status {
|
case response.status {
|
||||||
200 ->
|
200 ->
|
||||||
|
@ -24,15 +23,9 @@ pub fn list_public_agents(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_public_agent(
|
pub fn get_public_agent(agent_symbol: AgentSymbol) -> ApiResponse(PublicAgent) {
|
||||||
token: AgentToken,
|
|
||||||
agent_symbol: AgentSymbol,
|
|
||||||
) -> ApiResponse(PublicAgent) {
|
|
||||||
let request =
|
let request =
|
||||||
api.get(
|
api.get(NoAuth, "/agents/" <> agent_symbol.to_string(agent_symbol))
|
||||||
AgentAuth(token),
|
|
||||||
"/agents/" <> agent_symbol.to_string(agent_symbol),
|
|
||||||
)
|
|
||||||
use response <- api.try_send(request)
|
use response <- api.try_send(request)
|
||||||
case response.status {
|
case response.status {
|
||||||
200 -> api.parse_data_response(response, public_agent.decoder())
|
200 -> api.parse_data_response(response, public_agent.decoder())
|
||||||
|
|
|
@ -3,14 +3,13 @@ import gleam/option.{type Option}
|
||||||
import models/faction.{type Faction}
|
import models/faction.{type Faction}
|
||||||
import models/faction_symbol.{type FactionSymbol}
|
import models/faction_symbol.{type FactionSymbol}
|
||||||
import utils/api.{type ApiResponse, type PagedData}
|
import utils/api.{type ApiResponse, type PagedData}
|
||||||
import utils/auth.{type AgentToken, AgentAuth}
|
import utils/auth.{type AgentToken, AgentAuth, NoAuth}
|
||||||
|
|
||||||
pub fn list_factions(
|
pub fn list_factions(
|
||||||
token: AgentToken,
|
|
||||||
page: Option(Int),
|
page: Option(Int),
|
||||||
limit: Option(Int),
|
limit: Option(Int),
|
||||||
) -> ApiResponse(PagedData(List(Faction))) {
|
) -> ApiResponse(PagedData(List(Faction))) {
|
||||||
let request = api.get_page(AgentAuth(token), "/factions", page, limit)
|
let request = api.get_page(NoAuth, "/factions", page, limit)
|
||||||
use response <- api.try_send(request)
|
use response <- api.try_send(request)
|
||||||
case response.status {
|
case response.status {
|
||||||
200 ->
|
200 ->
|
||||||
|
@ -19,12 +18,9 @@ pub fn list_factions(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_faction(
|
pub fn get_faction(symbol: FactionSymbol) -> ApiResponse(Faction) {
|
||||||
token: AgentToken,
|
|
||||||
symbol: FactionSymbol,
|
|
||||||
) -> ApiResponse(Faction) {
|
|
||||||
let request =
|
let request =
|
||||||
api.get(AgentAuth(token), "/factions/" <> faction_symbol.to_string(symbol))
|
api.get(NoAuth, "/factions/" <> faction_symbol.to_string(symbol))
|
||||||
use response <- api.try_send(request)
|
use response <- api.try_send(request)
|
||||||
case response.status {
|
case response.status {
|
||||||
200 -> api.parse_data_response(response, faction.decoder())
|
200 -> api.parse_data_response(response, faction.decoder())
|
||||||
|
@ -36,12 +32,6 @@ pub type FactionReputation {
|
||||||
FactionReputation(symbol: FactionSymbol, reputation: Int)
|
FactionReputation(symbol: FactionSymbol, reputation: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn faction_reputation_decoder() {
|
|
||||||
use symbol <- decode.field("symbol", faction_symbol.decoder())
|
|
||||||
use reputation <- decode.field("reputation", decode.int)
|
|
||||||
decode.success(FactionReputation(symbol:, reputation:))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_my_factions(
|
pub fn get_my_factions(
|
||||||
token: AgentToken,
|
token: AgentToken,
|
||||||
page: Option(Int),
|
page: Option(Int),
|
||||||
|
@ -53,7 +43,11 @@ pub fn get_my_factions(
|
||||||
200 ->
|
200 ->
|
||||||
api.parse_paged_data_response(
|
api.parse_paged_data_response(
|
||||||
response,
|
response,
|
||||||
decode.list(faction_reputation_decoder()),
|
decode.list({
|
||||||
|
use symbol <- decode.field("symbol", faction_symbol.decoder())
|
||||||
|
use reputation <- decode.field("reputation", decode.int)
|
||||||
|
decode.success(FactionReputation(symbol:, reputation:))
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
_ -> api.parse_error_response(response)
|
_ -> api.parse_error_response(response)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,13 @@ import models/waypoint_symbol.{type WaypointSymbol}
|
||||||
import models/waypoint_trait_symbol.{type WaypointTraitSymbol}
|
import models/waypoint_trait_symbol.{type WaypointTraitSymbol}
|
||||||
import models/waypoint_type.{type WaypointType}
|
import models/waypoint_type.{type WaypointType}
|
||||||
import utils/api.{type ApiResponse, type PagedData}
|
import utils/api.{type ApiResponse, type PagedData}
|
||||||
import utils/auth.{type AgentToken, AgentAuth}
|
import utils/auth.{NoAuth}
|
||||||
|
|
||||||
pub fn list_systems(
|
pub fn list_systems(
|
||||||
token: AgentToken,
|
|
||||||
page: Option(Int),
|
page: Option(Int),
|
||||||
limit: Option(Int),
|
limit: Option(Int),
|
||||||
) -> ApiResponse(PagedData(List(System))) {
|
) -> ApiResponse(PagedData(List(System))) {
|
||||||
let request = api.get_page(AgentAuth(token), "/systems", page, limit)
|
let request = api.get_page(NoAuth, "/systems", page, limit)
|
||||||
use response <- api.try_send(request)
|
use response <- api.try_send(request)
|
||||||
case response.status {
|
case response.status {
|
||||||
200 ->
|
200 ->
|
||||||
|
@ -32,15 +31,9 @@ pub fn list_systems(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_system(
|
pub fn get_system(system_symbol: SystemSymbol) -> ApiResponse(System) {
|
||||||
token: AgentToken,
|
|
||||||
system_symbol: SystemSymbol,
|
|
||||||
) -> ApiResponse(System) {
|
|
||||||
let request =
|
let request =
|
||||||
api.get(
|
api.get(NoAuth, "/systems/" <> system_symbol.to_string(system_symbol))
|
||||||
AgentAuth(token),
|
|
||||||
"/systems/" <> system_symbol.to_string(system_symbol),
|
|
||||||
)
|
|
||||||
use response <- api.try_send(request)
|
use response <- api.try_send(request)
|
||||||
case response.status {
|
case response.status {
|
||||||
200 -> api.parse_data_response(response, system.decoder())
|
200 -> api.parse_data_response(response, system.decoder())
|
||||||
|
@ -49,7 +42,6 @@ pub fn get_system(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_system_waypoints(
|
pub fn list_system_waypoints(
|
||||||
token: AgentToken,
|
|
||||||
system_symbol: SystemSymbol,
|
system_symbol: SystemSymbol,
|
||||||
page: Option(Int),
|
page: Option(Int),
|
||||||
limit: Option(Int),
|
limit: Option(Int),
|
||||||
|
@ -66,7 +58,7 @@ pub fn list_system_waypoints(
|
||||||
}
|
}
|
||||||
let request =
|
let request =
|
||||||
api.get_page_with_query(
|
api.get_page_with_query(
|
||||||
AgentAuth(token),
|
NoAuth,
|
||||||
"/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints",
|
"/systems/" <> system_symbol.to_string(system_symbol) <> "/waypoints",
|
||||||
page,
|
page,
|
||||||
limit,
|
limit,
|
||||||
|
@ -81,13 +73,12 @@ pub fn list_system_waypoints(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_waypoint(
|
pub fn get_waypoint(
|
||||||
token: AgentToken,
|
|
||||||
system_symbol: SystemSymbol,
|
system_symbol: SystemSymbol,
|
||||||
waypoint_symbol: WaypointSymbol,
|
waypoint_symbol: WaypointSymbol,
|
||||||
) -> ApiResponse(Waypoint) {
|
) -> ApiResponse(Waypoint) {
|
||||||
let request =
|
let request =
|
||||||
api.get(
|
api.get(
|
||||||
AgentAuth(token),
|
NoAuth,
|
||||||
"/systems/"
|
"/systems/"
|
||||||
<> system_symbol.to_string(system_symbol)
|
<> system_symbol.to_string(system_symbol)
|
||||||
<> "/waypoints/"
|
<> "/waypoints/"
|
||||||
|
@ -101,13 +92,12 @@ pub fn get_waypoint(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_construction_site(
|
pub fn get_construction_site(
|
||||||
token: AgentToken,
|
|
||||||
system_symbol: SystemSymbol,
|
system_symbol: SystemSymbol,
|
||||||
waypoint_symbol: WaypointSymbol,
|
waypoint_symbol: WaypointSymbol,
|
||||||
) -> ApiResponse(Construction) {
|
) -> ApiResponse(Construction) {
|
||||||
let request =
|
let request =
|
||||||
api.get(
|
api.get(
|
||||||
AgentAuth(token),
|
NoAuth,
|
||||||
"/systems/"
|
"/systems/"
|
||||||
<> system_symbol.to_string(system_symbol)
|
<> system_symbol.to_string(system_symbol)
|
||||||
<> "/waypoints/"
|
<> "/waypoints/"
|
||||||
|
@ -126,7 +116,6 @@ pub type ConstructionSiteSupplied {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn supply_construction_site(
|
pub fn supply_construction_site(
|
||||||
token: AgentToken,
|
|
||||||
system_symbol: SystemSymbol,
|
system_symbol: SystemSymbol,
|
||||||
waypoint_symbol: WaypointSymbol,
|
waypoint_symbol: WaypointSymbol,
|
||||||
ship_symbol: ShipSymbol,
|
ship_symbol: ShipSymbol,
|
||||||
|
@ -135,7 +124,7 @@ pub fn supply_construction_site(
|
||||||
) -> ApiResponse(ConstructionSiteSupplied) {
|
) -> ApiResponse(ConstructionSiteSupplied) {
|
||||||
let request =
|
let request =
|
||||||
api.post_json(
|
api.post_json(
|
||||||
AgentAuth(token),
|
NoAuth,
|
||||||
"/systems/"
|
"/systems/"
|
||||||
<> system_symbol.to_string(system_symbol)
|
<> system_symbol.to_string(system_symbol)
|
||||||
<> "/waypoints/"
|
<> "/waypoints/"
|
||||||
|
@ -160,13 +149,12 @@ pub fn supply_construction_site(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_market(
|
pub fn get_market(
|
||||||
token: AgentToken,
|
|
||||||
system_symbol: SystemSymbol,
|
system_symbol: SystemSymbol,
|
||||||
waypoint_symbol: WaypointSymbol,
|
waypoint_symbol: WaypointSymbol,
|
||||||
) -> ApiResponse(Market) {
|
) -> ApiResponse(Market) {
|
||||||
let request =
|
let request =
|
||||||
api.get(
|
api.get(
|
||||||
AgentAuth(token),
|
NoAuth,
|
||||||
"/systems/"
|
"/systems/"
|
||||||
<> system_symbol.to_string(system_symbol)
|
<> system_symbol.to_string(system_symbol)
|
||||||
<> "/waypoints/"
|
<> "/waypoints/"
|
||||||
|
@ -181,13 +169,12 @@ pub fn get_market(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_jump_gate(
|
pub fn get_jump_gate(
|
||||||
token: AgentToken,
|
|
||||||
system_symbol: SystemSymbol,
|
system_symbol: SystemSymbol,
|
||||||
waypoint_symbol: WaypointSymbol,
|
waypoint_symbol: WaypointSymbol,
|
||||||
) -> ApiResponse(JumpGate) {
|
) -> ApiResponse(JumpGate) {
|
||||||
let request =
|
let request =
|
||||||
api.get(
|
api.get(
|
||||||
AgentAuth(token),
|
NoAuth,
|
||||||
"/systems/"
|
"/systems/"
|
||||||
<> system_symbol.to_string(system_symbol)
|
<> system_symbol.to_string(system_symbol)
|
||||||
<> "/waypoints/"
|
<> "/waypoints/"
|
||||||
|
@ -202,17 +189,16 @@ pub fn get_jump_gate(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_shipyard(
|
pub fn get_shipyard(
|
||||||
token,
|
system_symbol: SystemSymbol,
|
||||||
system_symbol,
|
waypoint_symbol: WaypointSymbol,
|
||||||
waypoint_symbol,
|
|
||||||
) -> ApiResponse(Shipyard) {
|
) -> ApiResponse(Shipyard) {
|
||||||
let request =
|
let request =
|
||||||
api.get(
|
api.get(
|
||||||
AgentAuth(token),
|
NoAuth,
|
||||||
"/systems/"
|
"/systems/"
|
||||||
<> system_symbol
|
<> system_symbol.to_string(system_symbol)
|
||||||
<> "/waypoints/"
|
<> "/waypoints/"
|
||||||
<> waypoint_symbol
|
<> waypoint_symbol.to_string(waypoint_symbol)
|
||||||
<> "/shipyard",
|
<> "/shipyard",
|
||||||
)
|
)
|
||||||
use response <- api.try_send(request)
|
use response <- api.try_send(request)
|
||||||
|
|
Loading…
Reference in a new issue