Skip to content

Commit

Permalink
Refactor stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruhlmann committed May 27, 2024
1 parent 81a1c8b commit 6c878e6
Show file tree
Hide file tree
Showing 49 changed files with 104 additions and 263 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
<img alt="relic" align="right" src="doc/relic.webp">

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.
2 changes: 1 addition & 1 deletion lib/api/community/advertisement.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/api/community/clan.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
Expand Down
2 changes: 1 addition & 1 deletion lib/api/community/clan.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/api/community/leaderboard.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions lib/api/game/login.ml

This file was deleted.

12 changes: 6 additions & 6 deletions lib/models/response/community/achievement.ml
Original file line number Diff line number Diff line change
@@ -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
}
;;
4 changes: 2 additions & 2 deletions lib/models/response/community/achievement.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions lib/models/response/community/achievement_attainment.ml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions lib/models/response/community/advertisement.ml
Original file line number Diff line number Diff line change
@@ -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
}
;;
12 changes: 6 additions & 6 deletions lib/models/response/community/avatar_stat.ml
Original file line number Diff line number Diff line change
@@ -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
}
;;
13 changes: 8 additions & 5 deletions lib/models/response/community/clan.ml
Original file line number Diff line number Diff line change
@@ -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
}
;;
12 changes: 7 additions & 5 deletions lib/models/response/community/clan_info.ml
Original file line number Diff line number Diff line change
@@ -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
}
;;
13 changes: 7 additions & 6 deletions lib/models/response/community/community_event.ml
Original file line number Diff line number Diff line change
@@ -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
}
;;
13 changes: 7 additions & 6 deletions lib/models/response/community/inventory.ml
Original file line number Diff line number Diff line change
@@ -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")
}
;;
31 changes: 16 additions & 15 deletions lib/models/response/community/leaderboard.ml
Original file line number Diff line number Diff line change
@@ -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)
}
;;
19 changes: 10 additions & 9 deletions lib/models/response/community/leaderboard2.ml
Original file line number Diff line number Diff line change
@@ -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
}
;;
Loading

0 comments on commit 6c878e6

Please sign in to comment.