Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
050cef92e4 | |||
de20cb5001 |
3 changed files with 13 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
||||||
name = "spacetraders_sdk"
|
name = "spacetraders_sdk"
|
||||||
version = "1.5.4"
|
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"]
|
||||||
|
|
|
@ -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) ->
|
||||||
|
|
Loading…
Reference in a new issue