diff options
author | Ryan Kavanagh <rak@rak.ac> | 2021-11-06 20:10:31 -0400 |
---|---|---|
committer | Ryan Kavanagh <rak@rak.ac> | 2021-11-06 20:10:48 -0400 |
commit | d91ac3d746bac124f3344986ed1f430727055d19 (patch) | |
tree | 8372b0f65051ef54b33aec7e7e8a352d7a9fd873 /lib | |
parent | Add dependencies (diff) |
Refactor listenbrainz.atd and fix differences with API
Diffstat (limited to 'lib')
-rw-r--r-- | lib/listenbrainz.atd | 20 | ||||
-rw-r--r-- | lib/listenbrainz_util.ml | 10 |
2 files changed, 17 insertions, 13 deletions
diff --git a/lib/listenbrainz.atd b/lib/listenbrainz.atd index cf4e09a..ede37f5 100644 --- a/lib/listenbrainz.atd +++ b/lib/listenbrainz.atd @@ -1,12 +1,12 @@ type mbid = string <ocaml valid="Listenbrainz_util.validate_mbid"> -type isrc = string +type isrc = string <ocaml valid="Listenbrainz_util.validate_isrc"> type unixtime = float <json repr="int"> type tm = unixtime wrap <ocaml module="Unix" t="Unix.tm" wrap="Unix.gmtime" unwrap="Listenbrainz_util.tm_unwrap"> type additional_info = { ?artist_mbids : mbid list option; - ?release_group_mbid : mbid list option; - ?release_mid : mbid option; + ?release_group_mbid : mbid option; + ?release_mbid : mbid option; ?recording_mbid : mbid option; ?track_mbid : mbid option; ?work_mbids : mbid list option; @@ -41,6 +41,12 @@ type payload_listen = { track_metadata : track_metadata; } +type payload_listens = { + count : int; + user_id : mbid; + listens : payload_listen list; +} + type payload_listen_count = { count : int; } @@ -69,17 +75,13 @@ type get_user_listen_count = { } type get_user_playing_now = { - count : int; - user_id : mbid; - listens : payload_listen list; + payload : payload_listens; } <ocaml valid="Listenbrainz_util.validate_get_user_playing_now"> type get_user_similar_to = similar_user type get_user_listens = { - count : int; - user_id : mbid; - listens : payload_listen list; + payload : payload_listens } <ocaml valid="Listenbrainz_util.validate_get_user_listens"> type get_latest_import = { diff --git a/lib/listenbrainz_util.ml b/lib/listenbrainz_util.ml index 5056c09..f0b90dd 100644 --- a/lib/listenbrainz_util.ml +++ b/lib/listenbrainz_util.ml @@ -14,6 +14,8 @@ let tm_unwrap tm = let validate_mbid mbid = Str.string_match uuid_v4_re mbid 0 +let validate_isrc isrc = Str.string_match uuid_v4_re isrc 0 + let validate_post_submit_listens s = match s.listen_type with | `Single -> List.length s.payload = 1 @@ -22,11 +24,11 @@ let validate_post_submit_listens s = let validate_get_validate_token r = r.code = 200 || r.code = 400 -let validate_get_user_playing_now r = - match r.listens with +let validate_get_user_playing_now (r : get_user_playing_now) = + match r.payload.listens with | [] -> true | [l] -> l.listened_at = None | _ -> false -let validate_get_user_listens r = - List.length r.listens = r.count +let validate_get_user_listens (r : get_user_listens) = + List.length r.payload.listens = r.payload.count |