Compare commits
9 commits
Author | SHA1 | Date | |
---|---|---|---|
050cef92e4 | |||
de20cb5001 | |||
aed9b6413f | |||
a4edaa71e1 | |||
89ff1b3520 | |||
59ecc25dc7 | |||
35b1d0c1fc | |||
f9944d6878 | |||
70a30ff132 |
6 changed files with 30 additions and 10 deletions
|
@ -7,12 +7,11 @@
|
||||||
gleam add spacetraders_sdk@1
|
gleam add spacetraders_sdk@1
|
||||||
```
|
```
|
||||||
```gleam
|
```gleam
|
||||||
import spacetraders_sdk
|
import spacetraders_api
|
||||||
|
|
||||||
pub fn main() -> Nil {
|
pub fn main() -> Nil {
|
||||||
let assert Ok(server_status) = get_server_status()
|
let assert Ok(server_status) = spacetraders_api.get_server_status()
|
||||||
echo server_status
|
io.println(server_status.status)
|
||||||
Nil
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name = "spacetraders_sdk"
|
name = "spacetraders_sdk"
|
||||||
version = "1.5.0"
|
version = "1.5.5"
|
||||||
gleam = ">= 1.11.0"
|
gleam = ">= 1.11.0"
|
||||||
description = "A Gleam SDK for the spacetraders.io game API"
|
description = "A Gleam SDK for the spacetraders.io game API"
|
||||||
licences = ["MIT"]
|
licences = ["MIT"]
|
||||||
|
|
|
@ -1673,6 +1673,7 @@ 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,
|
||||||
|
@ -1681,7 +1682,7 @@ pub fn supply_construction_site(
|
||||||
) -> ApiResponse(ConstructionSiteSupplied) {
|
) -> ApiResponse(ConstructionSiteSupplied) {
|
||||||
let request =
|
let request =
|
||||||
api.post_json(
|
api.post_json(
|
||||||
NoAuth,
|
AgentAuth(token),
|
||||||
"/systems/"
|
"/systems/"
|
||||||
<> system_symbol.to_string(system_symbol)
|
<> system_symbol.to_string(system_symbol)
|
||||||
<> "/waypoints/"
|
<> "/waypoints/"
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import gleam/dynamic/decode.{type Decoder}
|
import gleam/dynamic/decode.{type Decoder}
|
||||||
|
import gleam/int
|
||||||
import gleam/json.{type Json}
|
import gleam/json.{type Json}
|
||||||
|
|
||||||
pub opaque type ShipComponentCondition {
|
pub opaque type ShipComponentCondition {
|
||||||
|
@ -17,7 +18,11 @@ pub fn parse(value: Float) -> Result(ShipComponentCondition, Nil) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decoder() -> Decoder(ShipComponentCondition) {
|
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) {
|
case parse(value) {
|
||||||
Ok(ship_component_condition) -> decode.success(ship_component_condition)
|
Ok(ship_component_condition) -> decode.success(ship_component_condition)
|
||||||
Error(Nil) ->
|
Error(Nil) ->
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import gleam/dynamic/decode.{type Decoder}
|
import gleam/dynamic/decode.{type Decoder}
|
||||||
|
import gleam/int
|
||||||
import gleam/json.{type Json}
|
import gleam/json.{type Json}
|
||||||
|
|
||||||
pub opaque type ShipComponentIntegrity {
|
pub opaque type ShipComponentIntegrity {
|
||||||
|
@ -17,7 +18,11 @@ pub fn parse(value: Float) -> Result(ShipComponentIntegrity, Nil) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decoder() -> Decoder(ShipComponentIntegrity) {
|
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) {
|
case parse(value) {
|
||||||
Ok(ship_component_integrity) -> decode.success(ship_component_integrity)
|
Ok(ship_component_integrity) -> decode.success(ship_component_integrity)
|
||||||
Error(Nil) ->
|
Error(Nil) ->
|
||||||
|
|
|
@ -31,11 +31,11 @@ pub type PagedData(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub opaque type AccountToken {
|
pub opaque type AccountToken {
|
||||||
AccountToken(token: String)
|
AccountToken(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub opaque type AgentToken {
|
pub opaque type AgentToken {
|
||||||
AgentToken(token: String)
|
AgentToken(String)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type TokenParseError {
|
pub type TokenParseError {
|
||||||
|
@ -67,6 +67,11 @@ pub fn account_token_decoder() -> Decoder(AccountToken) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn account_token_to_string(account_token: AccountToken) -> String {
|
||||||
|
let AccountToken(value) = account_token
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_agent_token(value: String) -> Result(AgentToken, TokenParseError) {
|
pub fn parse_agent_token(value: String) -> Result(AgentToken, TokenParseError) {
|
||||||
use jwt <- result.try(jwt.parse(value) |> result.replace_error(InvalidToken))
|
use jwt <- result.try(jwt.parse(value) |> result.replace_error(InvalidToken))
|
||||||
case jwt.payload.subject {
|
case jwt.payload.subject {
|
||||||
|
@ -83,6 +88,11 @@ pub fn agent_token_decoder() -> Decoder(AgentToken) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn agent_token_to_string(agent_token: AgentToken) -> String {
|
||||||
|
let AgentToken(value) = agent_token
|
||||||
|
value
|
||||||
|
}
|
||||||
|
|
||||||
@internal
|
@internal
|
||||||
pub fn set_request_auth(req: Request(a), auth_method: AuthMethod) -> Request(a) {
|
pub fn set_request_auth(req: Request(a), auth_method: AuthMethod) -> Request(a) {
|
||||||
case auth_method {
|
case auth_method {
|
||||||
|
|
Loading…
Reference in a new issue