-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
369 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
profile = janestreet | ||
break-cases = fit | ||
margin = 117 | ||
wrap-comments = true | ||
line-endings = lf | ||
|
||
# To make ocaml-ci happy | ||
version = ignore | ||
version-check = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
open Lwt.Syntax | ||
|
||
let get game domain send = | ||
let base_url = Uri.make ~scheme:"https" ~host:domain ~path:"/community/advertisement/findAdvertisements" () in | ||
let url = Uri.with_query' base_url [ "title", Data.Game.to_str game ] in | ||
let* json = send url in | ||
match json with | ||
| Some j -> | ||
let model = Models.Response.Community.Advertisement.from_json j in | ||
Lwt.return @@ Some model | ||
| None -> Lwt.return None | ||
;; |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
open Lwt.Syntax | ||
|
||
type client = | ||
{ domain : string | ||
; game : Data.Game.game | ||
} | ||
|
||
let create domain game = { domain; game } | ||
|
||
let get_json url = | ||
let* resp, body = Cohttp_lwt_unix.Client.get url in | ||
let status = Cohttp.Response.status resp in | ||
if Cohttp.Code.code_of_status status = 200 | ||
then | ||
let* body = Cohttp_lwt.Body.to_string body in | ||
let json = Yojson.Basic.from_string body in | ||
Lwt.return @@ Some json | ||
else Lwt.return None | ||
;; | ||
|
||
let get ?requester endpoint client = | ||
let actual_requester = match requester with Some r -> r | None -> get_json in | ||
let* json = endpoint client.game client.domain actual_requester in | ||
Lwt.return json | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[@@@warning "-37"] | ||
|
||
type game = | ||
| Age1 | ||
| Age2 | ||
| Age3 | ||
| Age4 | ||
|
||
let to_str = function Age1 -> "age1" | Age2 -> "age2" | Age3 -> "age3" | Age4 -> "age4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type game = | ||
| Age1 | ||
| Age2 | ||
| Age3 | ||
| Age4 | ||
|
||
val to_str : game -> string |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type advertisement_response = | ||
{ result : Stub.Response.header | ||
; matches : Stub.Advertisement.advertisement list | ||
; avatars : Stub.Avatar.avatar 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) | ||
] | ||
;; | ||
|
||
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) | ||
} | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
type advertisement = | ||
{ id : int | ||
; steamlobbyid : int | ||
; goodoldgameslobbyid : int | ||
; xboxsessionid : string | ||
; host_profile_id : int | ||
; state : int | ||
; description : string | ||
; visible : int | ||
; mapname : string | ||
; options : string | ||
; passwordprotected : int | ||
; maxplayers : int | ||
; matchtype_id : int | ||
; matchmembers : Match_member.match_member list | ||
; observernum : int | ||
; observermax : int | ||
; isobservable : int | ||
; observerdelay : int | ||
; hasobserverpassword : int | ||
; servicetype : int | ||
; relayserver_region : string | ||
} | ||
|
||
let to_json a = | ||
`Assoc | ||
[ "id", `Int a.id | ||
; "steamlobbyid", `Int a.steamlobbyid | ||
; "goodoldgameslobbyid", `Int a.goodoldgameslobbyid | ||
; "xboxsessionid", `String a.xboxsessionid | ||
; "host_profile_id", `Int a.host_profile_id | ||
; "state", `Int a.state | ||
; "description", `String a.description | ||
; "visible", `Int a.visible | ||
; "mapname", `String a.mapname | ||
; "options", `String a.options | ||
; "passwordprotected", `Int a.passwordprotected | ||
; "maxplayers", `Int a.maxplayers | ||
; "matchtype_id", `Int a.matchtype_id | ||
; "matchmembers", `List (List.map Match_member.to_json a.matchmembers) | ||
; "observernum", `Int a.observernum | ||
; "observermax", `Int a.observermax | ||
; "isobservable", `Int a.isobservable | ||
; "observerdelay", `Int a.observerdelay | ||
; "hasobserverpassword", `Int a.hasobserverpassword | ||
; "servicetype", `Int a.servicetype | ||
; "relayserver_region", `String a.relayserver_region | ||
] | ||
;; | ||
|
||
let from_json json = | ||
{ id = Yojson.Basic.Util.(json |> member "id" |> to_int) | ||
; steamlobbyid = Yojson.Basic.Util.(json |> member "steamlobbyid" |> to_int) | ||
; goodoldgameslobbyid = Yojson.Basic.Util.(json |> member "goodoldgameslobbyid" |> to_int) | ||
; xboxsessionid = Yojson.Basic.Util.(json |> member "xboxsessionid" |> to_string) | ||
; host_profile_id = Yojson.Basic.Util.(json |> member "host_profile_id" |> to_int) | ||
; state = Yojson.Basic.Util.(json |> member "state" |> to_int) | ||
; description = Yojson.Basic.Util.(json |> member "description" |> to_string) | ||
; visible = Yojson.Basic.Util.(json |> member "visible" |> to_int) | ||
; mapname = Yojson.Basic.Util.(json |> member "mapname" |> to_string) | ||
; options = Yojson.Basic.Util.(json |> member "options" |> to_string) | ||
; passwordprotected = Yojson.Basic.Util.(json |> member "passwordprotected" |> to_int) | ||
; maxplayers = Yojson.Basic.Util.(json |> member "maxplayers" |> to_int) | ||
; matchtype_id = Yojson.Basic.Util.(json |> member "matchtype_id" |> to_int) | ||
; matchmembers = Yojson.Basic.Util.(json |> member "matchmembers" |> to_list |> List.map Match_member.from_json) | ||
; observernum = Yojson.Basic.Util.(json |> member "observernum" |> to_int) | ||
; observermax = Yojson.Basic.Util.(json |> member "observermax" |> to_int) | ||
; isobservable = Yojson.Basic.Util.(json |> member "isobservable" |> to_int) | ||
; observerdelay = Yojson.Basic.Util.(json |> member "observerdelay" |> to_int) | ||
; hasobserverpassword = Yojson.Basic.Util.(json |> member "hasobserverpassword" |> to_int) | ||
; servicetype = Yojson.Basic.Util.(json |> member "servicetype" |> to_int) | ||
; relayserver_region = Yojson.Basic.Util.(json |> member "relayserver_region" |> to_string) | ||
} | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
type avatar = | ||
{ profile_id : int | ||
; name : string | ||
; alias : string | ||
; personal_statgroup_id : int | ||
; xp : int | ||
; level : int | ||
; leaderboardregion_id : int | ||
; country : string | ||
} | ||
|
||
let to_json a = | ||
`Assoc | ||
[ "profile_id", `Int a.profile_id | ||
; "name", `String a.name | ||
; "alias", `String a.alias | ||
; "personal_statgroup_id", `Int a.personal_statgroup_id | ||
; "xp", `Int a.xp | ||
; "level", `Int a.level | ||
; "leaderboardregion_id", `Int a.leaderboardregion_id | ||
; "country", `String a.country | ||
] | ||
;; | ||
|
||
let from_json json = | ||
{ profile_id = Yojson.Basic.Util.(json |> member "profile_id" |> to_int) | ||
; name = Yojson.Basic.Util.(json |> member "name" |> to_string) | ||
; alias = Yojson.Basic.Util.(json |> member "alias" |> to_string) | ||
; personal_statgroup_id = Yojson.Basic.Util.(json |> member "personal_statgroup_id" |> to_int) | ||
; xp = Yojson.Basic.Util.(json |> member "xp" |> to_int) | ||
; level = Yojson.Basic.Util.(json |> member "level" |> to_int) | ||
; leaderboardregion_id = Yojson.Basic.Util.(json |> member "leaderboardregion_id" |> to_int) | ||
; country = Yojson.Basic.Util.(json |> member "country" |> to_string) | ||
} | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
type match_member = | ||
{ match_id : int | ||
; profile_id : int | ||
; ranking : int | ||
; statgroup_id : int | ||
; race_id : int | ||
; teamid : int | ||
} | ||
|
||
let to_json m = | ||
`Assoc | ||
[ "match_id", `Int m.match_id | ||
; "profile_id", `Int m.profile_id | ||
; "ranking", `Int m.ranking | ||
; "statgroup_id", `Int m.statgroup_id | ||
; "race_id", `Int m.race_id | ||
; "teamid", `Int m.teamid | ||
] | ||
;; | ||
|
||
let from_json json = | ||
{ match_id = Yojson.Basic.Util.(json |> member "match_id" |> to_int) | ||
; profile_id = Yojson.Basic.Util.(json |> member "profile_id" |> to_int) | ||
; ranking = Yojson.Basic.Util.(json |> member "ranking" |> to_int) | ||
; statgroup_id = Yojson.Basic.Util.(json |> member "statgroup_id" |> to_int) | ||
; race_id = Yojson.Basic.Util.(json |> member "race_id" |> to_int) | ||
; teamid = Yojson.Basic.Util.(json |> member "teamid" |> to_int) | ||
} | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type header = | ||
{ code : int | ||
; message : string | ||
} | ||
|
||
let to_json r = `Assoc [ "code", `Int r.code; "message", `String r.message ] | ||
|
||
let from_json json = | ||
{ code = Yojson.Basic.Util.(json |> member "code" |> to_int) | ||
; message = Yojson.Basic.Util.(json |> member "message" |> to_string) | ||
} | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.PHONY: test | ||
test: | ||
find . -name '*.coverage' | xargs rm -f | ||
dune runtest --instrument-with bisect_ppx --force | ||
dune runtest --root $$(pwd) --instrument-with bisect_ppx --force | ||
bisect-ppx-report html | ||
bisect-ppx-report summary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
open Lwt.Infix | ||
open Relic_sdk | ||
|
||
let request_with_file endpoint response_file = | ||
let requester = Mock.Json_file.create_requester response_file in | ||
let client = Client.create "aoe-api.worldsedgelink.com" Data.Game.Age2 in | ||
Client.get endpoint client ~requester | ||
;; | ||
|
||
let test_get_advertisements () = | ||
request_with_file Api.Community.Advertisement.get "findAdvertisements.json" | ||
>>= function | ||
| Some json -> Lwt.return @@ Alcotest.(check string) "Struct has id" "SUCCESS" json.result.message | ||
| None -> Lwt.fail_with "Expected Some but got None" | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
(include_subdirs qualified) | ||
|
||
(test | ||
(name test) | ||
(package relic-sdk) | ||
(deps | ||
(glob_files ./res/*.json)) | ||
(instrumentation | ||
(backend bisect_ppx)) | ||
(libraries alcotest alcotest-lwt relic-sdk)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let create_requester filename = | ||
let path = "res/" ^ filename in | ||
fun _ -> Lwt.return @@ Some (Yojson.Basic.from_file path) | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"result": { | ||
"code": 0, | ||
"message": "SUCCESS" | ||
}, | ||
"matches": [ | ||
{ | ||
"id": 100000001, | ||
"steamlobbyid": 123456789012345678, | ||
"goodoldgameslobbyid": 0, | ||
"xboxsessionid": "session-1", | ||
"host_profile_id": 1000001, | ||
"state": 1, | ||
"description": "Test match 1", | ||
"visible": 1, | ||
"mapname": "test map", | ||
"options": "options-string-1", | ||
"passwordprotected": 0, | ||
"maxplayers": 8, | ||
"slotinfo": "slot-info-1", | ||
"matchtype_id": 1, | ||
"matchmembers": [ | ||
{ | ||
"match_id": 100000001, | ||
"profile_id": 1000001, | ||
"ranking": 10, | ||
"statgroup_id": 10001, | ||
"race_id": 1, | ||
"teamid": 1 | ||
} | ||
], | ||
"observernum": 1, | ||
"observermax": 10, | ||
"isobservable": 1, | ||
"observerdelay": 1, | ||
"hasobserverpassword": 0, | ||
"servicetype": 1, | ||
"relayserver_region": "testregion1" | ||
}, | ||
{ | ||
"id": 100000002, | ||
"steamlobbyid": 123456789012345679, | ||
"goodoldgameslobbyid": 0, | ||
"xboxsessionid": "session-2", | ||
"host_profile_id": 1000002, | ||
"state": 1, | ||
"description": "Test match 2", | ||
"visible": 1, | ||
"mapname": "test map 2", | ||
"options": "options-string-2", | ||
"passwordprotected": 0, | ||
"maxplayers": 8, | ||
"slotinfo": "slot-info-2", | ||
"matchtype_id": 1, | ||
"matchmembers": [ | ||
{ | ||
"match_id": 100000002, | ||
"profile_id": 1000002, | ||
"ranking": 20, | ||
"statgroup_id": 10002, | ||
"race_id": 2, | ||
"teamid": 2 | ||
} | ||
], | ||
"observernum": 2, | ||
"observermax": 20, | ||
"isobservable": 1, | ||
"observerdelay": 2, | ||
"hasobserverpassword": 0, | ||
"servicetype": 2, | ||
"relayserver_region": "testregion2" | ||
} | ||
], | ||
"avatars": [ | ||
{ | ||
"profile_id": 1000001, | ||
"name": "avatar1", | ||
"alias": "Test Avatar 1 人", | ||
"personal_statgroup_id": 10001, | ||
"xp": 10, | ||
"level": 1, | ||
"leaderboardregion_id": 1, | ||
"country": "testcountry1" | ||
}, | ||
{ | ||
"profile_id": 1000002, | ||
"name": "avatar2", | ||
"alias": "Test Avatar 2", | ||
"personal_statgroup_id": 10002, | ||
"xp": 20, | ||
"level": 2, | ||
"leaderboardregion_id": 2, | ||
"country": "testcountry2" | ||
} | ||
] | ||
} |
Oops, something went wrong.