Skip to content

Commit

Permalink
Begin advertismenet members
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruhlmann committed May 31, 2024
1 parent 585d4e4 commit 109429f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 51 deletions.
5 changes: 3 additions & 2 deletions lib/api/community/news.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ let get game domain send =
match json with
| Some j ->
Lwt.return
@@ Json.try_parse_as
(module Models.Response.Community.News : Json.JsonParsable with type t = Models.Response.Community.News.t)
@@ Data.Json.try_parse_as
(module Models.Response.Community.News : Data.Json.JsonParsable
with type t = Models.Response.Community.News.t)
j
| None -> Lwt.return None
;;
7 changes: 6 additions & 1 deletion lib/api/game/advertisement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ let find_observable ?(start = 1) ?(count = 100) ?(sort = Descending) game domain
in
let* json = send url in
match json with
| Some j -> Lwt.return @@ Some (Models.Response.Game.Observable_advertisements.from_json j)
| Some j ->
Lwt.return
@@ Data.Json.try_parse_as
(module Models.Response.Game.Observable_advertisements : Data.Json.JsonParsable
with type t = Models.Response.Game.Observable_advertisements.t)
j
| None -> Lwt.return None
;;
44 changes: 21 additions & 23 deletions lib/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ type t =
; cookie : Data.Platform.Cookie.t option
}

let create ?(login = None) domain game =
match login with
| Some l ->
let* cookie = Data.Platform.Cookie.create l domain in
Lwt.return { domain; game; cookie }
| None -> Lwt.return { domain; game; cookie = None }
let create ?(login = None) ?(cookie = None) domain game =
match cookie with
| Some c ->
let* _ = Lwt_io.printl "Creating client using existing cookie" in
Lwt.return { domain; game; cookie = Some c }
| None ->
(match login with
| Some l ->
let* _ = Lwt_io.printl "Creating client using steam credentials" in
let* cookie = Data.Platform.Cookie.create l domain in
let* _ =
match cookie with
| Some c ->
Lwt_io.printl
@@ Printf.sprintf "Cookie created successfully '%s'" (Data.Platform.Cookie.to_cookie_string c)
| None -> Lwt_io.printl "Unable to create cookie"
in
Lwt.return { domain; game; cookie }
| None -> Lwt.return { domain; game; cookie = None })
;;

let get_json ?(cookie = None) (url : Uri.t) =
Expand All @@ -24,30 +37,15 @@ let get_json ?(cookie = None) (url : Uri.t) =
let headers =
match cookie with
| None -> Cohttp.Header.init ()
| Some c ->
let cookies_string =
Printf.sprintf
"ApplicationGatewayAffinity=%s; ApplicationGatewayAffinityCORS=%s; reliclink=%s"
c.application_gateway_affinity
c.application_gateway_affinity_cors
c.reliclink
in
Cohttp.Header.add (Cohttp.Header.init ()) "Cookie" cookies_string
| Some c -> Cohttp.Header.add (Cohttp.Header.init ()) "Cookie" (Data.Platform.Cookie.to_cookie_string c)
in
let* resp, body = Cohttp_lwt_unix.Client.get ~headers url_with_params in
let status = Cohttp.Response.status resp in
let* body_str = Cohttp_lwt.Body.to_string body in
let curl_command =
Printf.sprintf
"curl -i -H 'Cookie: %s' '%s'"
(match cookie with
| Some c ->
Printf.sprintf
"ApplicationGatewayAffinity=%s; ApplicationGatewayAffinityCORS=%s; reliclink=%s"
c.application_gateway_affinity
c.application_gateway_affinity_cors
c.reliclink
| None -> "")
(match cookie with Some c -> Data.Platform.Cookie.to_cookie_string c | None -> "")
(Uri.to_string url_with_params)
in
let* _ = Lwt_io.printl curl_command in
Expand Down
File renamed without changes.
12 changes: 8 additions & 4 deletions lib/data/platform/cookie.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ type t =
; application_gateway_affinity_cors : string
; reliclink : string
; session_id : string
; expires_on : int
}

let get_seconds_until_expires c = c.expires_on - int_of_float (Unix.time ())
let to_cookie_string cookie =
Printf.sprintf
"ApplicationGatewayAffinity=%s; ApplicationGatewayAffinityCORS=%s; reliclink=%s"
cookie.application_gateway_affinity
cookie.application_gateway_affinity_cors
cookie.reliclink
;;

let make_form_data alias auth =
[ "accountType", [ "STEAM" ]
Expand Down Expand Up @@ -81,8 +86,7 @@ let create login domain =
let application_gateway_affinity_cors = get_cookie_value cookies "ApplicationGatewayAffinityCORS" in
let application_gateway_affinity = get_cookie_value cookies "ApplicationGatewayAffinity" in
let reliclink = get_cookie_value cookies "reliclink" in
let expires_on = 3600 + int_of_float (Unix.time ()) in
let session_id = extract_session_id body_str in
let c = { application_gateway_affinity; application_gateway_affinity_cors; reliclink; session_id; expires_on } in
let c = { application_gateway_affinity; application_gateway_affinity_cors; reliclink; session_id } in
Lwt.return @@ Some c
;;
20 changes: 0 additions & 20 deletions lib/form.ml

This file was deleted.

16 changes: 16 additions & 0 deletions lib/models/stub/game/observable_advertisment_member.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type t =
{ int1 : int
; int2 : int
; platform_id : string
; icon : string option
; name : string
; string1 : string
; int3 : int
; int4 : int
; int5 : int
; int6 : int
; int_null : int option
; string2 : string
; int7 : int option
; list1 : Yojson.Basic.t list
}
2 changes: 1 addition & 1 deletion tests/integration/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ let setup_community () =
let setup_game () =
let open Test_state.Game in
let open Data.Platform.Steam_login in
let login = Some { alias = vgetenv "STEAM_USER_ALIAS"; app_ticket = vgetenv "STEAM_APP_TICKET" } in
let domain = "aoe-api.worldsedgelink.com" in
let game = Data.Game.Age2 in
let endpoint = Api.Community.Leaderboard.get_leaderboard_2 ~count:1 in
let login = Some { alias = vgetenv "STEAM_USER_ALIAS"; app_ticket = vgetenv "STEAM_APP_TICKET" } in
let* client = Client.create ~login domain game in
let* leaderboards_response = Client.get endpoint client in
match leaderboards_response with
Expand Down

0 comments on commit 109429f

Please sign in to comment.