From e4ee8035edab8fd0619c953c9dbc3b885190077f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Oszcz=C4=99da?= Date: Sun, 9 Jun 2024 13:41:10 +0100 Subject: [PATCH] fix: Issues with parsing. --- src/tatoeba/search.gleam | 16 +++++++++------- src/tatoeba/sentence.gleam | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/tatoeba/search.gleam b/src/tatoeba/search.gleam index 9af7fb4..7ef7e02 100644 --- a/src/tatoeba/search.gleam +++ b/src/tatoeba/search.gleam @@ -251,26 +251,28 @@ fn complete_sort( /// data if it does. /// fn paging(from data: Dynamic) -> Result(Paging, List(dynamic.DecodeError)) { + use data <- result.try(data |> field("Sentences", dynamic.dynamic)) + use finder <- result.try(data |> field("finder", finder)) use page <- result.try(data |> field("page", int)) use results_on_current_page <- result.try(data |> field("current", int)) use result_count <- result.try(data |> field("count", int)) - use results_per_page <- result.try(data |> field("per_page", int)) + use results_per_page <- result.try(data |> field("perPage", int)) use start <- result.try(data |> field("start", int)) use end <- result.try(data |> field("end", int)) - use previous_page <- result.try(data |> field("previous_page", bool)) - use next_page <- result.try(data |> field("next_page", bool)) - use page_count <- result.try(data |> field("page_count", int)) + use previous_page <- result.try(data |> field("prevPage", bool)) + use next_page <- result.try(data |> field("nextPage", bool)) + use page_count <- result.try(data |> field("pageCount", int)) use sort_strategy <- result.try( data |> field("sort", optional(sort_strategy)), ) use direction <- result.try(data |> field("direction", optional(bool))) use limit <- result.try(data |> field("limit", optional(limit))) - use sort_default <- result.try(data |> field("sort_default", bool)) - use direction_default <- result.try(data |> field("direction_default", bool)) + use sort_default <- result.try(data |> field("sortDefault", bool)) + use direction_default <- result.try(data |> field("directionDefault", bool)) use scope <- result.try(data |> field("scope", optional(scope))) use complete_sort <- result.try( - data |> field("complete_sort", list(complete_sort)), + data |> field("completeSort", list(complete_sort)), ) Ok(Paging( diff --git a/src/tatoeba/sentence.gleam b/src/tatoeba/sentence.gleam index c00f1c0..d72d576 100644 --- a/src/tatoeba/sentence.gleam +++ b/src/tatoeba/sentence.gleam @@ -475,7 +475,9 @@ pub fn sentence( use language_name <- result.try(data |> field("lang_name", string)) use script <- result.try(data |> field("script", optional(string))) use license <- result.try(data |> field("license", string)) - use based_on_id <- result.try(data |> field("based_on_id", optional(int))) + use based_on_id <- result.try( + data |> optional_field("based_on_id", optional(int)), + ) // use base <- result.try(data |> field("base", optional(sentence))) use correctness <- result.try(data |> field("correctness", int)) use translations <- result.try(data |> field("translations", translations)) @@ -513,7 +515,7 @@ pub fn sentence( language_name: language_name, script: script, license: license, - based_on_id: based_on_id, + based_on_id: based_on_id |> option.flatten(), // base: base, correctness: correctness, translations: translations,