Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Mar 27, 2024
1 parent 94e6d2c commit 5420290
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version=0.25.1
profile = conventional
break-separators = after
space-around-lists = false
Expand Down
2 changes: 1 addition & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
(-> lastfm.noop.ml)))
(modules lastfm_constants lastfm_generic lastfm)
(synopsis
"Implementation of the API used by the last.fm to keep count of played songs"))
"Implementation of the API used by the last.fm to keep count of played songs"))

(rule
(target lastfm_constants.ml)
Expand Down
12 changes: 6 additions & 6 deletions src/lastfm.ocamlnet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ module Http_ocamlnet = struct
http_headers#set_fields headers;
begin
match request with
| Get -> ()
| Post post ->
body#set_value post;
call#set_request_body body;
http_headers#update_field "Content-length"
(string_of_int (String.length post))
| Get -> ()
| Post post ->
body#set_value post;
call#set_request_body body;
http_headers#update_field "Content-length"
(string_of_int (String.length post))
end;
call#set_request_header http_headers;
pipeline#add call;
Expand Down
14 changes: 7 additions & 7 deletions src/lastfm_generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ let of_hex1 c =

let url_decode ?(plus = true) s =
Pcre.substitute
~rex:(Pcre.regexp
"\\+|%..")
~rex:(Pcre.regexp "\\+|%..")
(* TODO why do we match %. and % and seem to exclude them below ? *)
~subst:(fun s ->
if s = "+" then if plus then " " else "+"
Expand Down Expand Up @@ -134,12 +133,13 @@ let to_hex2 =
Bytes.to_string s

let url_encode ?(plus = true) s =
Pcre.substitute ~rex:(Pcre.regexp "[^A-Za-z0-9_.!*-]")
Pcre.substitute
~rex:(Pcre.regexp "[^A-Za-z0-9_.!*-]")
~subst:(fun x ->
if plus && x = " " then "+"
else (
let k = Char.code x.[0] in
"%" ^ to_hex2 k ))
"%" ^ to_hex2 k))
s

module type Http_t = sig
Expand Down Expand Up @@ -380,7 +380,7 @@ module Audioscrobbler_generic (Http : Http_t) = struct
Hashtbl.replace sessions (user, pass, (host, port)) id;
Hashtbl.replace urls id v;
id
| e -> raise e )
| e -> raise e)

let check_song s a =
match s.source with
Expand Down Expand Up @@ -412,7 +412,7 @@ module Audioscrobbler_generic (Http : Http_t) = struct
(BadData
"bad rating value (ban and skip are for \
lastfm sources only)")
| _ -> () ) ) ) )
| _ -> ()))))

let audioscrobbler_post ?timeout id base_url values =
let host, port, req = parse_url base_url in
Expand Down Expand Up @@ -753,7 +753,7 @@ module Radio_generic (Http : Http_t) = struct
base_url;
base_path;
};
args )
args)
else begin
clear id;
raise (Adjust (req, ret))
Expand Down
4 changes: 2 additions & 2 deletions src/lastfm_generic.mli
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ end

(** Generic implementation of Audioscrobbler, independent
* from the Http request. *)
module Audioscrobbler_generic (Http : Http_t) : Audioscrobbler_t
module Audioscrobbler_generic (_ : Http_t) : Audioscrobbler_t

(** Generic implementation of the Radio API, independant
* from the Http request. *)
module Radio_generic (Http : Http_t) : Radio_t
module Radio_generic (_ : Http_t) : Radio_t

0 comments on commit 5420290

Please sign in to comment.