From 6c878e6731ad49bf44f605a70bb4b95260a5400a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Kr=C3=BChlmann?= Date: Mon, 27 May 2024 10:23:20 +0200 Subject: [PATCH] Refactor stubs --- README.md | 4 + lib/api/community/advertisement.mli | 2 +- lib/api/community/clan.ml | 2 +- lib/api/community/clan.mli | 2 +- lib/api/community/leaderboard.ml | 4 +- lib/api/game/login.ml | 12 -- lib/models/response/community/achievement.ml | 12 +- lib/models/response/community/achievement.mli | 4 +- .../community/achievement_attainment.ml | 13 +- .../response/community/advertisement.ml | 18 +- lib/models/response/community/avatar_stat.ml | 12 +- lib/models/response/community/clan.ml | 13 +- lib/models/response/community/clan_info.ml | 12 +- .../response/community/community_event.ml | 13 +- lib/models/response/community/inventory.ml | 13 +- lib/models/response/community/leaderboard.ml | 31 ++-- lib/models/response/community/leaderboard2.ml | 19 +- lib/models/response/community/news.ml | 13 +- lib/models/response/platform_login.ml | 165 ------------------ .../stub/{ => community}/achievement.ml | 0 .../{ => community}/achievement_attainment.ml | 0 .../stub/{ => community}/advertisement.ml | 0 .../{ => community}/advertisement_options.ml | 0 lib/models/stub/{ => community}/avatar.ml | 0 .../stub/{ => community}/avatar_stat.ml | 0 lib/models/stub/{ => community}/clan.ml | 0 lib/models/stub/{ => community}/clan_info.ml | 0 .../stub/{ => community}/clan_member.ml | 0 .../{ => community}/clan_member_avatar.ml | 0 .../stub/{ => community}/clan_permissions.ml | 0 .../stub/{ => community}/community_event.ml | 0 lib/models/stub/{ => community}/inventory.ml | 0 .../{ => community}/inventory_metadata.ml | 0 .../stub/{ => community}/join_policy.ml | 0 .../stub/{ => community}/leaderboard.ml | 0 .../stub/{ => community}/leaderboard_map.ml | 0 .../{ => community}/leaderboard_region.ml | 0 .../{ => community}/leaderboard_sorting.ml | 0 .../stub/{ => community}/leaderboard_stat.ml | 0 .../stub/{ => community}/match_member.ml | 0 lib/models/stub/{ => community}/match_type.ml | 0 lib/models/stub/{ => community}/news.ml | 0 lib/models/stub/{ => community}/race.ml | 0 lib/models/stub/{ => community}/response.ml | 0 lib/models/stub/{ => community}/slot.ml | 0 lib/models/stub/{ => community}/slot_info.ml | 0 lib/models/stub/{ => community}/stat_group.ml | 0 shell.nix | 1 + tests/integration/test_state/community.ml | 2 +- 49 files changed, 104 insertions(+), 263 deletions(-) delete mode 100644 lib/api/game/login.ml delete mode 100644 lib/models/response/platform_login.ml rename lib/models/stub/{ => community}/achievement.ml (100%) rename lib/models/stub/{ => community}/achievement_attainment.ml (100%) rename lib/models/stub/{ => community}/advertisement.ml (100%) rename lib/models/stub/{ => community}/advertisement_options.ml (100%) rename lib/models/stub/{ => community}/avatar.ml (100%) rename lib/models/stub/{ => community}/avatar_stat.ml (100%) rename lib/models/stub/{ => community}/clan.ml (100%) rename lib/models/stub/{ => community}/clan_info.ml (100%) rename lib/models/stub/{ => community}/clan_member.ml (100%) rename lib/models/stub/{ => community}/clan_member_avatar.ml (100%) rename lib/models/stub/{ => community}/clan_permissions.ml (100%) rename lib/models/stub/{ => community}/community_event.ml (100%) rename lib/models/stub/{ => community}/inventory.ml (100%) rename lib/models/stub/{ => community}/inventory_metadata.ml (100%) rename lib/models/stub/{ => community}/join_policy.ml (100%) rename lib/models/stub/{ => community}/leaderboard.ml (100%) rename lib/models/stub/{ => community}/leaderboard_map.ml (100%) rename lib/models/stub/{ => community}/leaderboard_region.ml (100%) rename lib/models/stub/{ => community}/leaderboard_sorting.ml (100%) rename lib/models/stub/{ => community}/leaderboard_stat.ml (100%) rename lib/models/stub/{ => community}/match_member.ml (100%) rename lib/models/stub/{ => community}/match_type.ml (100%) rename lib/models/stub/{ => community}/news.ml (100%) rename lib/models/stub/{ => community}/race.ml (100%) rename lib/models/stub/{ => community}/response.ml (100%) rename lib/models/stub/{ => community}/slot.ml (100%) rename lib/models/stub/{ => community}/slot_info.ml (100%) rename lib/models/stub/{ => community}/stat_group.ml (100%) diff --git a/README.md b/README.md index d5847d4..23135ec 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,7 @@ relic OCaml SDK for the relic-link API provided by [World's Edge Studio](https://www.ageofempires.com) for the Age of Empires franchise. + +## Acknowledgements + +A big thank you to Christopher Zimmermann for his zlib related c stubs and to the librematch team for their helpful research and advice. diff --git a/lib/api/community/advertisement.mli b/lib/api/community/advertisement.mli index 9ef1544..6032079 100644 --- a/lib/api/community/advertisement.mli +++ b/lib/api/community/advertisement.mli @@ -3,7 +3,7 @@ Represents all endpoints in [/community/advertisement/*] - [GET /community/advertisement/findAdvertisements] - "Advertisements" is the name for custom game lobby entries in the AoE franchise multiplayer system. *) + "Advertisements" is the name for lobby entries in the ranked ladder, quick play and custom lobby browser. *) (** [get s c g d s] retrieves a paginated list of currently open lobbies in the game [g] on domain [d] in range [s] to [s] + [c]. The request is sent with diff --git a/lib/api/community/clan.ml b/lib/api/community/clan.ml index 6594241..2d9da9e 100644 --- a/lib/api/community/clan.ml +++ b/lib/api/community/clan.ml @@ -8,7 +8,7 @@ let find ?(name = "") ?(tags = []) ?(join_policies = []) ?(start = 1) ?(count = [ "title", Data.Game.to_str game ; "name", name ; "tags", Data.Query.encode_lst_s tags - ; "joinPolicies", Data.Query.encode_lst_i @@ List.map Models.Stub.Join_policy.to_int join_policies + ; "joinPolicies", Data.Query.encode_lst_i @@ List.map Models.Stub.Community.Join_policy.to_int join_policies ; "start", string_of_int start ; "count", string_of_int count ] diff --git a/lib/api/community/clan.mli b/lib/api/community/clan.mli index 6067dbe..342747e 100644 --- a/lib/api/community/clan.mli +++ b/lib/api/community/clan.mli @@ -9,7 +9,7 @@ val find : ?name:string -> ?tags:string list - -> ?join_policies:Models.Stub.Join_policy.t list + -> ?join_policies:Models.Stub.Community.Join_policy.t list -> ?start:int -> ?count:int -> Data.Game.t diff --git a/lib/api/community/leaderboard.ml b/lib/api/community/leaderboard.ml index eb805e4..8d86b35 100644 --- a/lib/api/community/leaderboard.ml +++ b/lib/api/community/leaderboard.ml @@ -28,7 +28,7 @@ let get_avatar ?(profile_ids = []) game domain send = ;; let get_leaderboard_2 - ?(sortby = Models.Stub.Leaderboard_sorting.ByRating) + ?(sortby = Models.Stub.Community.Leaderboard_sorting.ByRating) ?(platform = "PC_STEAM") ?(leaderboard_id = 3) ?(start = 1) @@ -42,7 +42,7 @@ let get_leaderboard_2 Uri.with_query' base_url [ "title", Data.Game.to_str game - ; "sortBy", string_of_int @@ Models.Stub.Leaderboard_sorting.to_int sortby + ; "sortBy", string_of_int @@ Models.Stub.Community.Leaderboard_sorting.to_int sortby ; "platform", platform ; "leaderboard_id", string_of_int leaderboard_id ; "start", string_of_int start diff --git a/lib/api/game/login.ml b/lib/api/game/login.ml deleted file mode 100644 index 592a647..0000000 --- a/lib/api/game/login.ml +++ /dev/null @@ -1,12 +0,0 @@ -open Lwt.Syntax -open Data.Platform.Credentials - -let platform_login credentials game domain send = - let url = Uri.make ~scheme:"https" ~host:domain ~path:"/game/login/platformlogin" () in - let* json = send url in - match json with - | Some j -> - let model = Models.Response.Game.Platform_login.from_json j in - Lwt.return @@ Some model - | None -> Lwt.return None -;; diff --git a/lib/models/response/community/achievement.ml b/lib/models/response/community/achievement.ml index 2b59555..50939c7 100644 --- a/lib/models/response/community/achievement.ml +++ b/lib/models/response/community/achievement.ml @@ -1,18 +1,18 @@ type t = - { result : Stub.Response.t - ; achievement_defs : Stub.Achievement.t list + { result : Stub.Community.Response.t + ; achievement_defs : Stub.Community.Achievement.t list } let to_json r = `Assoc - [ "result", Stub.Response.to_json r.result - ; "achievementDefs", `List (List.map Stub.Achievement.to_json r.achievement_defs) + [ "result", Stub.Community.Response.to_json r.result + ; "achievementDefs", `List (List.map Stub.Community.Achievement.to_json r.achievement_defs) ] ;; let from_json 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 + { result = json |> member "result" |> Stub.Community.Response.from_json + ; achievement_defs = json |> member "achievementDefs" |> to_list |> List.map Stub.Community.Achievement.from_json } ;; diff --git a/lib/models/response/community/achievement.mli b/lib/models/response/community/achievement.mli index 7c3e720..78cc7df 100644 --- a/lib/models/response/community/achievement.mli +++ b/lib/models/response/community/achievement.mli @@ -5,8 +5,8 @@ (** Raw reponse type, which corresponds to the model returned by the API endpoint *) type t = - { result : Stub.Response.t (** Result header containing result code and message *) - ; achievement_defs : Stub.Achievement.t list (** List of achievement definitions *) + { result : Stub.Community.Response.t (** Result header containing result code and message *) + ; achievement_defs : Stub.Community.Achievement.t list (** List of achievement definitions *) } (** [to_json r] converts an achivement defitnion response [r] into its JSON diff --git a/lib/models/response/community/achievement_attainment.ml b/lib/models/response/community/achievement_attainment.ml index 5e33e1d..a3e8d18 100644 --- a/lib/models/response/community/achievement_attainment.ml +++ b/lib/models/response/community/achievement_attainment.ml @@ -1,21 +1,22 @@ type t = - { result : Stub.Response.t - ; user_achievements_map : (string * Stub.Achievement_attainment.t list) list + { result : Stub.Community.Response.t + ; user_achievements_map : (string * Stub.Community.Achievement_attainment.t list) list } let to_json r = let user_achievement_map_json = List.map (fun (user_id, achievements) -> - `Assoc [ user_id, `List (List.map Stub.Achievement_attainment.to_json achievements) ]) + `Assoc [ user_id, `List (List.map Stub.Community.Achievement_attainment.to_json achievements) ]) r.user_achievements_map in - `Assoc [ "result", Stub.Response.to_json r.result; "userAchievementsMap", `List user_achievement_map_json ] + `Assoc + [ "result", Stub.Community.Response.to_json r.result; "userAchievementsMap", `List user_achievement_map_json ] ;; let from_json json = let open Yojson.Basic.Util in - let result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json) in + let result = Yojson.Basic.Util.(json |> member "result" |> Stub.Community.Response.from_json) in let user_achievements_map = json |> member "userAchievementsMap" @@ -24,7 +25,7 @@ let from_json json = (fun acc user_achievement_json -> match user_achievement_json with | `Assoc [ (user_id, `List achievements) ] -> - (user_id, List.map Stub.Achievement_attainment.from_json achievements) :: acc + (user_id, List.map Stub.Community.Achievement_attainment.from_json achievements) :: acc | _ -> acc) [] in diff --git a/lib/models/response/community/advertisement.ml b/lib/models/response/community/advertisement.ml index 652d218..f1fc58b 100644 --- a/lib/models/response/community/advertisement.ml +++ b/lib/models/response/community/advertisement.ml @@ -1,21 +1,21 @@ type t = - { result : Stub.Response.t - ; matches : Stub.Advertisement.t list - ; avatars : Stub.Avatar.t list + { result : Stub.Community.Response.t + ; matches : Stub.Community.Advertisement.t list + ; avatars : Stub.Community.Avatar.t list } let to_json r = `Assoc - [ "result", Stub.Response.to_json r.result - ; "avatars", `List (List.map Stub.Avatar.to_json r.avatars) - ; "matches", `List (List.map Stub.Advertisement.to_json r.matches) + [ "result", Stub.Community.Response.to_json r.result + ; "avatars", `List (List.map Stub.Community.Avatar.to_json r.avatars) + ; "matches", `List (List.map Stub.Community.Advertisement.to_json r.matches) ] ;; let from_json 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 + { result = json |> member "result" |> Stub.Community.Response.from_json + ; matches = json |> member "matches" |> to_list |> List.map Stub.Community.Advertisement.from_json + ; avatars = json |> member "avatars" |> to_list |> List.map Stub.Community.Avatar.from_json } ;; diff --git a/lib/models/response/community/avatar_stat.ml b/lib/models/response/community/avatar_stat.ml index cbdac12..90284ea 100644 --- a/lib/models/response/community/avatar_stat.ml +++ b/lib/models/response/community/avatar_stat.ml @@ -1,19 +1,19 @@ type t = - { result : Stub.Response.t - ; avatar_stats_for_profile : Stub.Avatar_stat.t list + { result : Stub.Community.Response.t + ; avatar_stats_for_profile : Stub.Community.Avatar_stat.t list } let to_json r = `Assoc - [ "result", Stub.Response.to_json r.result - ; "avatarStatsForProfile", `List (List.map Stub.Avatar_stat.to_json r.avatar_stats_for_profile) + [ "result", Stub.Community.Response.to_json r.result + ; "avatarStatsForProfile", `List (List.map Stub.Community.Avatar_stat.to_json r.avatar_stats_for_profile) ] ;; let from_json json = let open Yojson.Basic.Util in - { result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json) + { result = Yojson.Basic.Util.(json |> member "result" |> Stub.Community.Response.from_json) ; avatar_stats_for_profile = - json |> member "avatarStatsForProfile" |> to_list |> List.map Stub.Avatar_stat.from_json + json |> member "avatarStatsForProfile" |> to_list |> List.map Stub.Community.Avatar_stat.from_json } ;; diff --git a/lib/models/response/community/clan.ml b/lib/models/response/community/clan.ml index a2e3422..1496c26 100644 --- a/lib/models/response/community/clan.ml +++ b/lib/models/response/community/clan.ml @@ -1,15 +1,18 @@ type t = - { result : Stub.Response.t - ; clans : Stub.Clan.t list + { result : Stub.Community.Response.t + ; clans : Stub.Community.Clan.t list } let to_json r = - `Assoc [ "result", Stub.Response.to_json r.result; "clans", `List (List.map Stub.Clan.to_json r.clans) ] + `Assoc + [ "result", Stub.Community.Response.to_json r.result + ; "clans", `List (List.map Stub.Community.Clan.to_json r.clans) + ] ;; let from_json 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 + { result = json |> member "result" |> Stub.Community.Response.from_json + ; clans = json |> member "clans" |> to_list |> List.map Stub.Community.Clan.from_json } ;; diff --git a/lib/models/response/community/clan_info.ml b/lib/models/response/community/clan_info.ml index a4d2400..ce1dd7f 100644 --- a/lib/models/response/community/clan_info.ml +++ b/lib/models/response/community/clan_info.ml @@ -1,13 +1,15 @@ type t = - { result : Stub.Response.t - ; clan : Stub.Clan_info.t + { result : Stub.Community.Response.t + ; clan : Stub.Community.Clan_info.t } -let to_json r = `Assoc [ "result", Stub.Response.to_json r.result; "clan", Stub.Clan_info.to_json r.clan ] +let to_json r = + `Assoc [ "result", Stub.Community.Response.to_json r.result; "clan", Stub.Community.Clan_info.to_json r.clan ] +;; let from_json json = let open Yojson.Basic.Util in - { result = json |> member "result" |> Stub.Response.from_json - ; clan = json |> member "clan" |> Stub.Clan_info.from_json + { result = json |> member "result" |> Stub.Community.Response.from_json + ; clan = json |> member "clan" |> Stub.Community.Clan_info.from_json } ;; diff --git a/lib/models/response/community/community_event.ml b/lib/models/response/community/community_event.ml index 912534d..3ad137d 100644 --- a/lib/models/response/community/community_event.ml +++ b/lib/models/response/community/community_event.ml @@ -1,18 +1,19 @@ type t = - { result : Stub.Response.t - ; communityEvents : Stub.Community_event.t list + { result : Stub.Community.Response.t + ; communityEvents : Stub.Community.Community_event.t list } let to_json r = `Assoc - [ "result", Stub.Response.to_json r.result - ; "communityEvents", `List (List.map Stub.Community_event.to_json r.communityEvents) + [ "result", Stub.Community.Response.to_json r.result + ; "communityEvents", `List (List.map Stub.Community.Community_event.to_json r.communityEvents) ] ;; let from_json 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 + { result = json |> member "result" |> Stub.Community.Response.from_json + ; communityEvents = + json |> member "communityEvents" |> to_list |> List.map Stub.Community.Community_event.from_json } ;; diff --git a/lib/models/response/community/inventory.ml b/lib/models/response/community/inventory.ml index d7baf6d..fa44ff9 100644 --- a/lib/models/response/community/inventory.ml +++ b/lib/models/response/community/inventory.ml @@ -1,29 +1,30 @@ type t = - { result : Stub.Response.t - ; item_instances_by_profile_id : (string * Stub.Inventory.t list) list + { result : Stub.Community.Response.t + ; item_instances_by_profile_id : (string * Stub.Community.Inventory.t list) list } let to_json r = `Assoc - [ "result", Stub.Response.to_json r.result + [ "result", Stub.Community.Response.to_json r.result ; ( "itemInstancesByProfileID" , `List (List.map - (fun (profile_id, items) -> `Assoc [ profile_id, `List (List.map Stub.Inventory.to_json items) ]) + (fun (profile_id, items) -> + `Assoc [ profile_id, `List (List.map Stub.Community.Inventory.to_json items) ]) r.item_instances_by_profile_id) ) ] ;; let from_json json = let open Yojson.Basic.Util in - { result = json |> member "result" |> Stub.Response.from_json + { result = json |> member "result" |> Stub.Community.Response.from_json ; item_instances_by_profile_id = json |> member "itemInstancesByProfileID" |> to_list |> List.map (fun json -> match json with - | `Assoc [ (profile_id, `List items) ] -> profile_id, List.map Stub.Inventory.from_json items + | `Assoc [ (profile_id, `List items) ] -> profile_id, List.map Stub.Community.Inventory.from_json items | _ -> failwith "JSON structure mismatch") } ;; diff --git a/lib/models/response/community/leaderboard.ml b/lib/models/response/community/leaderboard.ml index 7e58253..ce160e3 100644 --- a/lib/models/response/community/leaderboard.ml +++ b/lib/models/response/community/leaderboard.ml @@ -1,31 +1,32 @@ type t = - { result : Stub.Response.t - ; leaderboards : Stub.Leaderboard.t list - ; match_types : Stub.Match_type.t list - ; races : Stub.Race.t list - ; leaderboard_regions : Stub.Leaderboard_region.t list + { result : Stub.Community.Response.t + ; leaderboards : Stub.Community.Leaderboard.t list + ; match_types : Stub.Community.Match_type.t list + ; races : Stub.Community.Race.t list + ; leaderboard_regions : Stub.Community.Leaderboard_region.t list (*; factions : string list (* Theres no docs for this so i have to disable it for now. It's been empty for every game. *) *) } let to_json r = `Assoc - [ "result", Stub.Response.to_json r.result - ; "leaderboards", `List (List.map Stub.Leaderboard.to_json r.leaderboards) - ; "matchTypes", `List (List.map Stub.Match_type.to_json r.match_types) - ; "races", `List (List.map Stub.Race.to_json r.races) - ; "leaderboardRegions", `List (List.map Stub.Leaderboard_region.to_json r.leaderboard_regions) + [ "result", Stub.Community.Response.to_json r.result + ; "leaderboards", `List (List.map Stub.Community.Leaderboard.to_json r.leaderboards) + ; "matchTypes", `List (List.map Stub.Community.Match_type.to_json r.match_types) + ; "races", `List (List.map Stub.Community.Race.to_json r.races) + ; "leaderboardRegions", `List (List.map Stub.Community.Leaderboard_region.to_json r.leaderboard_regions) ] ;; let from_json json = - { result = Yojson.Basic.Util.(json |> member "result" |> Stub.Response.from_json) + { result = Yojson.Basic.Util.(json |> member "result" |> Stub.Community.Response.from_json) ; leaderboards = - Yojson.Basic.Util.(json |> member "leaderboards" |> to_list |> List.map Stub.Leaderboard.from_json) - ; match_types = Yojson.Basic.Util.(json |> member "matchTypes" |> to_list |> List.map Stub.Match_type.from_json) - ; races = Yojson.Basic.Util.(json |> member "races" |> to_list |> List.map Stub.Race.from_json) + Yojson.Basic.Util.(json |> member "leaderboards" |> to_list |> List.map Stub.Community.Leaderboard.from_json) + ; match_types = + Yojson.Basic.Util.(json |> member "matchTypes" |> to_list |> List.map Stub.Community.Match_type.from_json) + ; races = Yojson.Basic.Util.(json |> member "races" |> to_list |> List.map Stub.Community.Race.from_json) ; leaderboard_regions = Yojson.Basic.Util.( - json |> member "leaderboardRegions" |> to_list |> List.map Stub.Leaderboard_region.from_json) + json |> member "leaderboardRegions" |> to_list |> List.map Stub.Community.Leaderboard_region.from_json) } ;; diff --git a/lib/models/response/community/leaderboard2.ml b/lib/models/response/community/leaderboard2.ml index 2c8f886..51b2bf0 100644 --- a/lib/models/response/community/leaderboard2.ml +++ b/lib/models/response/community/leaderboard2.ml @@ -1,24 +1,25 @@ type t = - { result : Stub.Response.t - ; stat_groups : Stub.Stat_group.t list - ; leaderboard_stats : Stub.Leaderboard_stat.t list + { result : Stub.Community.Response.t + ; stat_groups : Stub.Community.Stat_group.t list + ; leaderboard_stats : Stub.Community.Leaderboard_stat.t list ; rank_total : int } let to_json l = `Assoc - [ "result", Stub.Response.to_json l.result - ; "statGroups", `List (List.map Stub.Stat_group.to_json l.stat_groups) - ; "leaderboardStats", `List (List.map Stub.Leaderboard_stat.to_json l.leaderboard_stats) + [ "result", Stub.Community.Response.to_json l.result + ; "statGroups", `List (List.map Stub.Community.Stat_group.to_json l.stat_groups) + ; "leaderboardStats", `List (List.map Stub.Community.Leaderboard_stat.to_json l.leaderboard_stats) ; "rankTotal", `Int l.rank_total ] ;; let from_json json = let open Yojson.Basic.Util in - { result = json |> member "result" |> Stub.Response.from_json - ; stat_groups = json |> member "statGroups" |> to_list |> List.map Stub.Stat_group.from_json - ; leaderboard_stats = json |> member "leaderboardStats" |> to_list |> List.map Stub.Leaderboard_stat.from_json + { result = json |> member "result" |> Stub.Community.Response.from_json + ; stat_groups = json |> member "statGroups" |> to_list |> List.map Stub.Community.Stat_group.from_json + ; leaderboard_stats = + json |> member "leaderboardStats" |> to_list |> List.map Stub.Community.Leaderboard_stat.from_json ; rank_total = json |> member "rankTotal" |> to_int } ;; diff --git a/lib/models/response/community/news.ml b/lib/models/response/community/news.ml index 153d261..2385fae 100644 --- a/lib/models/response/community/news.ml +++ b/lib/models/response/community/news.ml @@ -1,15 +1,18 @@ type t = - { result : Stub.Response.t - ; news : Stub.News.t list + { result : Stub.Community.Response.t + ; news : Stub.Community.News.t list } let to_json r = - `Assoc [ "result", Stub.Response.to_json r.result; "news", `List (List.map Stub.News.to_json r.news) ] + `Assoc + [ "result", Stub.Community.Response.to_json r.result + ; "news", `List (List.map Stub.Community.News.to_json r.news) + ] ;; let from_json 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 + { result = json |> member "result" |> Stub.Community.Response.from_json + ; news = json |> member "news" |> to_list |> List.map Stub.Community.News.from_json } ;; diff --git a/lib/models/response/platform_login.ml b/lib/models/response/platform_login.ml deleted file mode 100644 index aaa5041..0000000 --- a/lib/models/response/platform_login.ml +++ /dev/null @@ -1,165 +0,0 @@ -type data_entry = - { id1 : string - ; id2 : string - ; url : string - ; icon : string - ; name : string - ; unknown1 : string - ; unknown2 : string - ; unknown3 : string - ; unknown4 : string - ; unknown5 : string option - ; unknown6 : string option - ; id3 : string - ; id4 : string - ; unknown7 : string list - } - -type config_entry = - { key : string - ; value : string - } - -type nested_entry = - { id1 : string - ; id2 : string - ; url : string - ; icon : string - ; name : string - ; clan : string - ; score1 : string - ; score2 : string - ; score3 : string - ; score4 : string - ; score5 : string option - ; id3 : string - ; id4 : string - ; unknown_list : string list - } - -type t = - { id1 : string - ; id2 : string - ; timestamp1 : string - ; timestamp2 : string - ; data_entries : data_entry list - ; unknown1 : string - ; unknown2 : string - ; unknown3 : string option - ; config : config_entry list - ; nested_entries : nested_entry list - } - -let from_json json = - let open Yojson.Basic.Util in - { id1 = json |> member "id1" |> to_string - ; id2 = json |> member "id2" |> to_string - ; timestamp1 = json |> member "timestamp1" |> to_string - ; timestamp2 = json |> member "timestamp2" |> to_string - ; data_entries = - json - |> member "data_entries" - |> to_list - |> List.map (fun entry -> - { id1 = entry |> member "id1" |> to_string - ; id2 = entry |> member "id2" |> to_string - ; url = entry |> member "url" |> to_string - ; icon = entry |> member "icon" |> to_string - ; name = entry |> member "name" |> to_string - ; unknown1 = entry |> member "unknown1" |> to_string - ; unknown2 = entry |> member "unknown2" |> to_string - ; unknown3 = entry |> member "unknown3" |> to_string - ; unknown4 = entry |> member "unknown4" |> to_string - ; unknown5 = entry |> member "unknown5" |> to_option to_string - ; unknown6 = entry |> member "unknown6" |> to_option to_string - ; id3 = entry |> member "id3" |> to_string - ; id4 = entry |> member "id4" |> to_string - ; unknown7 = entry |> member "unknown7" |> to_list |> List.map to_string - }) - ; unknown1 = json |> member "unknown1" |> to_string - ; unknown2 = json |> member "unknown2" |> to_string - ; unknown3 = json |> member "unknown3" |> to_option to_string - ; config = - json - |> member "config" - |> to_list - |> List.map (fun entry -> - { key = entry |> member "key" |> to_string; value = entry |> member "value" |> to_string }) - ; nested_entries = - json - |> member "nested_entries" - |> to_list - |> List.map (fun entry -> - { id1 = entry |> member "id1" |> to_string - ; id2 = entry |> member "id2" |> to_string - ; url = entry |> member "url" |> to_string - ; icon = entry |> member "icon" |> to_string - ; name = entry |> member "name" |> to_string - ; clan = entry |> member "clan" |> to_string - ; score1 = entry |> member "score1" |> to_string - ; score2 = entry |> member "score2" |> to_string - ; score3 = entry |> member "score3" |> to_string - ; score4 = entry |> member "score4" |> to_string - ; score5 = entry |> member "score5" |> to_option to_string - ; id3 = entry |> member "id3" |> to_string - ; id4 = entry |> member "id4" |> to_string - ; unknown_list = entry |> member "unknown_list" |> to_list |> List.map to_string - }) - } -;; - -let to_json a = - `Assoc - [ "id1", `String a.id1 - ; "id2", `String a.id2 - ; "timestamp1", `String a.timestamp1 - ; "timestamp2", `String a.timestamp2 - ; ( "data_entries" - , `List - (List.map - (fun entry -> - `Assoc - [ "id1", `String entry.id1 - ; "id2", `String entry.id2 - ; "url", `String entry.url - ; "icon", `String entry.icon - ; "name", `String entry.name - ; "unknown1", `String entry.unknown1 - ; "unknown2", `String entry.unknown2 - ; "unknown3", `String entry.unknown3 - ; "unknown4", `String entry.unknown4 - ; ("unknown5", match entry.unknown5 with Some v -> `String v | None -> `Null) - ; ("unknown6", match entry.unknown6 with Some v -> `String v | None -> `Null) - ; "id3", `String entry.id3 - ; "id4", `String entry.id4 - ; "unknown7", `List (List.map (fun i -> `String i) entry.unknown7) - ]) - a.data_entries) ) - ; "unknown1", `String a.unknown1 - ; "unknown2", `String a.unknown2 - ; ("unknown3", match a.unknown3 with Some v -> `String v | None -> `Null) - ; ( "config" - , `List (List.map (fun entry -> `Assoc [ "key", `String entry.key; "value", `String entry.value ]) a.config) ) - ; ( "nested_entries" - , `List - (List.map - (fun entry -> - `Assoc - [ "id1", `String entry.id1 - ; "id2", `String entry.id2 - ; "url", `String entry.url - ; "icon", `String entry.icon - ; "name", `String entry.name - ; "clan", `String entry.clan - ; "score1", `String entry.score1 - ; "score2", `String entry.score2 - ; "score3", `String entry.score3 - ; "score4", `String entry.score4 - ; ("score5", match entry.score5 with Some v -> `String v | None -> `Null) - ; "id3", `String entry.id3 - ; "id4", `String entry.id4 - ; "unknown_list", `List (List.map (fun i -> `String i) entry.unknown_list) - ]) - a.nested_entries) ) - ] -;; diff --git a/lib/models/stub/achievement.ml b/lib/models/stub/community/achievement.ml similarity index 100% rename from lib/models/stub/achievement.ml rename to lib/models/stub/community/achievement.ml diff --git a/lib/models/stub/achievement_attainment.ml b/lib/models/stub/community/achievement_attainment.ml similarity index 100% rename from lib/models/stub/achievement_attainment.ml rename to lib/models/stub/community/achievement_attainment.ml diff --git a/lib/models/stub/advertisement.ml b/lib/models/stub/community/advertisement.ml similarity index 100% rename from lib/models/stub/advertisement.ml rename to lib/models/stub/community/advertisement.ml diff --git a/lib/models/stub/advertisement_options.ml b/lib/models/stub/community/advertisement_options.ml similarity index 100% rename from lib/models/stub/advertisement_options.ml rename to lib/models/stub/community/advertisement_options.ml diff --git a/lib/models/stub/avatar.ml b/lib/models/stub/community/avatar.ml similarity index 100% rename from lib/models/stub/avatar.ml rename to lib/models/stub/community/avatar.ml diff --git a/lib/models/stub/avatar_stat.ml b/lib/models/stub/community/avatar_stat.ml similarity index 100% rename from lib/models/stub/avatar_stat.ml rename to lib/models/stub/community/avatar_stat.ml diff --git a/lib/models/stub/clan.ml b/lib/models/stub/community/clan.ml similarity index 100% rename from lib/models/stub/clan.ml rename to lib/models/stub/community/clan.ml diff --git a/lib/models/stub/clan_info.ml b/lib/models/stub/community/clan_info.ml similarity index 100% rename from lib/models/stub/clan_info.ml rename to lib/models/stub/community/clan_info.ml diff --git a/lib/models/stub/clan_member.ml b/lib/models/stub/community/clan_member.ml similarity index 100% rename from lib/models/stub/clan_member.ml rename to lib/models/stub/community/clan_member.ml diff --git a/lib/models/stub/clan_member_avatar.ml b/lib/models/stub/community/clan_member_avatar.ml similarity index 100% rename from lib/models/stub/clan_member_avatar.ml rename to lib/models/stub/community/clan_member_avatar.ml diff --git a/lib/models/stub/clan_permissions.ml b/lib/models/stub/community/clan_permissions.ml similarity index 100% rename from lib/models/stub/clan_permissions.ml rename to lib/models/stub/community/clan_permissions.ml diff --git a/lib/models/stub/community_event.ml b/lib/models/stub/community/community_event.ml similarity index 100% rename from lib/models/stub/community_event.ml rename to lib/models/stub/community/community_event.ml diff --git a/lib/models/stub/inventory.ml b/lib/models/stub/community/inventory.ml similarity index 100% rename from lib/models/stub/inventory.ml rename to lib/models/stub/community/inventory.ml diff --git a/lib/models/stub/inventory_metadata.ml b/lib/models/stub/community/inventory_metadata.ml similarity index 100% rename from lib/models/stub/inventory_metadata.ml rename to lib/models/stub/community/inventory_metadata.ml diff --git a/lib/models/stub/join_policy.ml b/lib/models/stub/community/join_policy.ml similarity index 100% rename from lib/models/stub/join_policy.ml rename to lib/models/stub/community/join_policy.ml diff --git a/lib/models/stub/leaderboard.ml b/lib/models/stub/community/leaderboard.ml similarity index 100% rename from lib/models/stub/leaderboard.ml rename to lib/models/stub/community/leaderboard.ml diff --git a/lib/models/stub/leaderboard_map.ml b/lib/models/stub/community/leaderboard_map.ml similarity index 100% rename from lib/models/stub/leaderboard_map.ml rename to lib/models/stub/community/leaderboard_map.ml diff --git a/lib/models/stub/leaderboard_region.ml b/lib/models/stub/community/leaderboard_region.ml similarity index 100% rename from lib/models/stub/leaderboard_region.ml rename to lib/models/stub/community/leaderboard_region.ml diff --git a/lib/models/stub/leaderboard_sorting.ml b/lib/models/stub/community/leaderboard_sorting.ml similarity index 100% rename from lib/models/stub/leaderboard_sorting.ml rename to lib/models/stub/community/leaderboard_sorting.ml diff --git a/lib/models/stub/leaderboard_stat.ml b/lib/models/stub/community/leaderboard_stat.ml similarity index 100% rename from lib/models/stub/leaderboard_stat.ml rename to lib/models/stub/community/leaderboard_stat.ml diff --git a/lib/models/stub/match_member.ml b/lib/models/stub/community/match_member.ml similarity index 100% rename from lib/models/stub/match_member.ml rename to lib/models/stub/community/match_member.ml diff --git a/lib/models/stub/match_type.ml b/lib/models/stub/community/match_type.ml similarity index 100% rename from lib/models/stub/match_type.ml rename to lib/models/stub/community/match_type.ml diff --git a/lib/models/stub/news.ml b/lib/models/stub/community/news.ml similarity index 100% rename from lib/models/stub/news.ml rename to lib/models/stub/community/news.ml diff --git a/lib/models/stub/race.ml b/lib/models/stub/community/race.ml similarity index 100% rename from lib/models/stub/race.ml rename to lib/models/stub/community/race.ml diff --git a/lib/models/stub/response.ml b/lib/models/stub/community/response.ml similarity index 100% rename from lib/models/stub/response.ml rename to lib/models/stub/community/response.ml diff --git a/lib/models/stub/slot.ml b/lib/models/stub/community/slot.ml similarity index 100% rename from lib/models/stub/slot.ml rename to lib/models/stub/community/slot.ml diff --git a/lib/models/stub/slot_info.ml b/lib/models/stub/community/slot_info.ml similarity index 100% rename from lib/models/stub/slot_info.ml rename to lib/models/stub/community/slot_info.ml diff --git a/lib/models/stub/stat_group.ml b/lib/models/stub/community/stat_group.ml similarity index 100% rename from lib/models/stub/stat_group.ml rename to lib/models/stub/community/stat_group.ml diff --git a/shell.nix b/shell.nix index cbb6437..5b77b32 100644 --- a/shell.nix +++ b/shell.nix @@ -19,5 +19,6 @@ pkgs.mkShell{ export C_INCLUDE_PATH=${pkgs.zlib.dev}/include:$C_INCLUDE_PATH export LIBRARY_PATH=${pkgs.zlib}/lib:$LIBRARY_PATH export OPAM_SWITCH_PREFIX=$HOME/.opam/5.2.0 + eval $(opam env) ''; } diff --git a/tests/integration/test_state/community.ml b/tests/integration/test_state/community.ml index e19afc8..ede9f68 100644 --- a/tests/integration/test_state/community.ml +++ b/tests/integration/test_state/community.ml @@ -2,5 +2,5 @@ open Relic_sdk type t = { client : Client.t - ; test_member : Models.Stub.Avatar.t + ; test_member : Models.Stub.Community.Avatar.t }