Skip to content

Commit

Permalink
Clean up json code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruhlmann committed Apr 8, 2024
1 parent 21ae382 commit ea32edc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/models/response/community/achievement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let to_json r =
;;

let from_json json =
{ result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json)
; achievement_defs =
Yojson.Basic.Util.(json |> member "achievementDefs" |> to_list |> List.map Stub.Achievement.from_json)
let open Yojson.Basic.Util in
{ result = json |> member "result" |> Stub.Response.from_json
; achievement_defs = json |> member "achievementDefs" |> to_list |> List.map Stub.Achievement.from_json
}
;;
5 changes: 4 additions & 1 deletion lib/models/response/community/achievement_attainment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ let to_json r =
;;

let from_json json =
let open Yojson.Basic.Util in
let result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json) in
let user_achievements_map =
Yojson.Basic.Util.(json |> member "userAchievementsMap" |> to_list)
json
|> member "userAchievementsMap"
|> to_list
|> List.fold_left
(fun acc user_achievement_json ->
match user_achievement_json with
Expand Down
7 changes: 4 additions & 3 deletions lib/models/response/community/advertisement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ let to_json r =
;;

let from_json json =
{ result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json)
; matches = Yojson.Basic.Util.(json |> member "matches" |> to_list |> List.map Stub.Advertisement.from_json)
; avatars = Yojson.Basic.Util.(json |> member "avatars" |> to_list |> List.map Stub.Avatar.from_json)
let open Yojson.Basic.Util in
{ result = json |> member "result" |> Stub.Response.from_json
; matches = json |> member "matches" |> to_list |> List.map Stub.Advertisement.from_json
; avatars = json |> member "avatars" |> to_list |> List.map Stub.Avatar.from_json
}
;;
5 changes: 3 additions & 2 deletions lib/models/response/community/clan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let to_json r =
;;

let from_json json =
{ result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json)
; clans = Yojson.Basic.Util.(json |> member "clans" |> to_list |> List.map Stub.Clan.from_json)
let open Yojson.Basic.Util in
{ result = json |> member "result" |> Stub.Response.from_json
; clans = json |> member "clans" |> to_list |> List.map Stub.Clan.from_json
}
;;
5 changes: 3 additions & 2 deletions lib/models/response/community/clan_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ type t =
let to_json r = `Assoc [ "result", Stub.Response.to_json r.result; "clan", Stub.Clan_info.to_json r.clan ]

let from_json json =
{ result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json)
; clan = Yojson.Basic.Util.(json |> member "clan" |> Stub.Clan_info.from_json)
let open Yojson.Basic.Util in
{ result = json |> member "result" |> Stub.Response.from_json
; clan = json |> member "clan" |> Stub.Clan_info.from_json
}
;;
6 changes: 3 additions & 3 deletions lib/models/response/community/community_event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let to_json r =
;;

let from_json json =
{ result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json)
; communityEvents =
Yojson.Basic.Util.(json |> member "communityEvents" |> to_list |> List.map Stub.Community_event.from_json)
let open Yojson.Basic.Util in
{ result = json |> member "result" |> Stub.Response.from_json
; communityEvents = json |> member "communityEvents" |> to_list |> List.map Stub.Community_event.from_json
}
;;
5 changes: 3 additions & 2 deletions lib/models/response/community/news.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let to_json r =
;;

let from_json json =
{ result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json)
; news = Yojson.Basic.Util.(json |> member "news" |> to_list |> List.map Stub.News.from_json)
let open Yojson.Basic.Util in
{ result = json |> member "result" |> Stub.Response.from_json
; news = json |> member "news" |> to_list |> List.map Stub.News.from_json
}
;;

0 comments on commit ea32edc

Please sign in to comment.