Skip to content

Commit

Permalink
Temp failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruhlmann committed Apr 8, 2024
1 parent 4ee6d35 commit e8e6571
Show file tree
Hide file tree
Showing 8 changed files with 664 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/api/community/leaderboard.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,33 @@ let get_avatar ?(profile_ids = []) game domain send =
Lwt.return @@ Some model
| None -> Lwt.return None)
;;

let get_leaderboard_2
?(sortby = Models.Stub.Leaderboard_sorting.ByRating)
?(platform = "PC_STEAM")
?(leaderboard_id = 3)
?(start = 0)
?(count = 100)
game
domain
send
=
let base_url = Uri.make ~scheme:"https" ~host:domain ~path:"/community/leaderboard/getLeaderboard2" () in
let url =
Uri.with_query'
base_url
[ "title", Data.Game.to_str game
; "sortBy", string_of_int @@ Models.Stub.Leaderboard_sorting.to_int sortby
; "platform", platform
; "leaderboard_id", string_of_int leaderboard_id
; "start", string_of_int start
; "count", string_of_int count
]
in
let* json = send url in
match json with
| Some j ->
let model = Models.Response.Community.Leaderboard2.from_json j in
Lwt.return @@ Some model
| None -> Lwt.return None
;;
24 changes: 24 additions & 0 deletions lib/models/response/community/leaderboard2.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type t =
{ result : Stub.Response.t
; stat_groups : Stub.Stat_group.t list
; leaderboard_stats : Stub.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)
; "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
; rank_total = json |> member "rankTotal" |> to_int
}
;;
12 changes: 12 additions & 0 deletions lib/models/stub/leaderboard_sorting.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type t =
| NumberOfWins
| ByRating

let from_int i =
match i with
| 0 -> NumberOfWins
| 1 -> ByRating
| _ -> failwith (Printf.sprintf "Invalid join policy integer: %d" i)
;;

let to_int = function NumberOfWins -> 0 | ByRating -> 1
63 changes: 63 additions & 0 deletions lib/models/stub/leaderboard_stat.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
type t =
{ statgroup_id : int
; leaderboard_id : int
; wins : int
; losses : int
; streak : int
; disputes : int
; drops : int
; rank : int
; ranktotal : int
; ranklevel : int
; rating : int
; regionrank : int
; regionranktotal : int
; lastmatchdate : int
; highestrank : int
; highestranklevel : int
; highestrating : int
}

let to_json sg =
`Assoc
[ "statgroup_id", `Int sg.statgroup_id
; "leaderboard_id", `Int sg.leaderboard_id
; "wins", `Int sg.wins
; "losses", `Int sg.losses
; "streak", `Int sg.streak
; "disputes", `Int sg.disputes
; "drops", `Int sg.drops
; "rank", `Int sg.rank
; "ranktotal", `Int sg.ranktotal
; "ranklevel", `Int sg.ranklevel
; "rating", `Int sg.rating
; "regionrank", `Int sg.regionrank
; "regionranktotal", `Int sg.regionranktotal
; "lastmatchdate", `Int sg.lastmatchdate
; "highestrank", `Int sg.highestrank
; "highestranklevel", `Int sg.highestranklevel
; "highestrating", `Int sg.highestrating
]
;;

let from_json json =
let open Yojson.Basic.Util in
{ statgroup_id = json |> member "statgroup_id" |> to_int
; leaderboard_id = json |> member "leaderboard_id" |> to_int
; wins = json |> member "wins" |> to_int
; losses = json |> member "losses" |> to_int
; streak = json |> member "streak" |> to_int
; disputes = json |> member "disputes" |> to_int
; drops = json |> member "drops" |> to_int
; rank = json |> member "rank" |> to_int
; ranktotal = json |> member "ranktotal" |> to_int
; ranklevel = json |> member "ranklevel" |> to_int
; rating = json |> member "rating" |> to_int
; regionrank = json |> member "regionrank" |> to_int
; regionranktotal = json |> member "regionranktotal" |> to_int
; lastmatchdate = json |> member "lastmatchdate" |> to_int
; highestrank = json |> member "highestrank" |> to_int
; highestranklevel = json |> member "highestranklevel" |> to_int
; highestrating = json |> member "highestrating" |> to_int
}
;;
24 changes: 24 additions & 0 deletions lib/models/stub/stat_group.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
type t =
{ id : int
; name : string
; type_ : int
; members : Avatar.t list
}

let to_json s =
`Assoc
[ "id", `Int s.id
; "name", `String s.name
; "type", `Int s.type_
; "members", `List (List.map Avatar.to_json s.members)
]
;;

let from_json json =
let open Yojson.Basic.Util in
{ id = json |> member "id" |> to_int
; name = json |> member "name" |> to_string
; type_ = json |> member "type" |> to_int
; members = json |> member "members" |> to_list |> List.map Avatar.from_json
}
;;
Loading

0 comments on commit e8e6571

Please sign in to comment.