OCaml library for JSONfeed parsing and creation

simplify

+4 -7
lib/attachment.ml
···
unknown : Unknown.t;
}
-
let make ~url ~mime_type ?title ?size_in_bytes ?duration_in_seconds ?(unknown = Unknown.empty) () =
+
let create ~url ~mime_type ?title ?size_in_bytes ?duration_in_seconds ?(unknown = Unknown.empty) () =
{ url; mime_type; title; size_in_bytes; duration_in_seconds; unknown }
-
-
let create ~url ~mime_type ?title ?size_in_bytes ?duration_in_seconds () =
-
make ~url ~mime_type ?title ?size_in_bytes ?duration_in_seconds ()
let url t = t.url
let mime_type t = t.mime_type
···
} in
map ~kind:"Unknown members" Jsont.json ~dec_empty ~dec_add ~dec_finish ~enc
in
-
let make_obj url mime_type title size_in_bytes duration_in_seconds unknown =
-
make ~url ~mime_type ?title ?size_in_bytes ?duration_in_seconds ~unknown ()
+
let create_obj url mime_type title size_in_bytes duration_in_seconds unknown =
+
create ~url ~mime_type ?title ?size_in_bytes ?duration_in_seconds ~unknown ()
in
-
Jsont.Object.map ~kind ~doc make_obj
+
Jsont.Object.map ~kind ~doc create_obj
|> Jsont.Object.mem "url" Jsont.string ~enc:url
|> Jsont.Object.mem "mime_type" Jsont.string ~enc:mime_type
|> Jsont.Object.opt_mem "title" Jsont.string ~enc:title
+3 -12
lib/attachment.mli
···
?title:string ->
?size_in_bytes:int64 ->
?duration_in_seconds:int ->
+
?unknown:Unknown.t ->
unit ->
t
-
(** [create ~url ~mime_type ?title ?size_in_bytes ?duration_in_seconds ()]
+
(** [create ~url ~mime_type ?title ?size_in_bytes ?duration_in_seconds ?unknown ()]
creates an attachment object.
@param url The location of the attachment (required)
···
of the same resource
@param size_in_bytes The size of the attachment file in bytes
@param duration_in_seconds The duration of the attachment in seconds (for audio/video)
+
@param unknown Unknown/custom fields for extensions (default: empty)
{b Examples:}
{[
···
~size_in_bytes:15_728_640L
~duration_in_seconds:1800 ()
]} *)
-
-
val make :
-
url:string ->
-
mime_type:string ->
-
?title:string ->
-
?size_in_bytes:int64 ->
-
?duration_in_seconds:int ->
-
?unknown:Unknown.t ->
-
unit ->
-
t
-
(** [make] is like {!create} but allows setting unknown fields. *)
(** {1 Accessors} *)
+4 -7
lib/author.ml
···
unknown : Unknown.t;
}
-
let make ?name ?url ?avatar ?(unknown = Unknown.empty) () =
-
{ name; url; avatar; unknown }
-
-
let create ?name ?url ?avatar () =
+
let create ?name ?url ?avatar ?(unknown = Unknown.empty) () =
if name = None && url = None && avatar = None then
invalid_arg "Author.create: at least one field (name, url, or avatar) must be provided";
-
make ?name ?url ?avatar ()
+
{ name; url; avatar; unknown }
let name t = t.name
let url t = t.url
···
map ~kind:"Unknown members" Jsont.json ~dec_empty ~dec_add ~dec_finish ~enc
in
(* Constructor that matches the jsont object map pattern *)
-
let make_obj name url avatar unknown = make ?name ?url ?avatar ~unknown () in
-
Jsont.Object.map ~kind ~doc make_obj
+
let create_obj name url avatar unknown = create ?name ?url ?avatar ~unknown () in
+
Jsont.Object.map ~kind ~doc create_obj
|> Jsont.Object.opt_mem "name" Jsont.string ~enc:name
|> Jsont.Object.opt_mem "url" Jsont.string ~enc:url
|> Jsont.Object.opt_mem "avatar" Jsont.string ~enc:avatar
+5 -8
lib/author.mli
···
(** {1 Construction} *)
-
val create : ?name:string -> ?url:string -> ?avatar:string -> unit -> t
-
(** [create ?name ?url ?avatar ()] creates an author.
+
val create :
+
?name:string -> ?url:string -> ?avatar:string ->
+
?unknown:Unknown.t -> unit -> t
+
(** [create ?name ?url ?avatar ?unknown ()] creates an author.
At least one of the optional parameters must be provided, otherwise
the function will raise [Invalid_argument].
···
@param name The author's name
@param url URL of the author's website or profile
@param avatar URL of the author's avatar image (should be square, 512x512 or larger)
+
@param unknown Unknown/custom fields for extensions (default: empty)
{b Examples:}
{[
···
~url:"https://janedoe.com"
~avatar:"https://janedoe.com/avatar.png" ()
]} *)
-
-
val make :
-
?name:string -> ?url:string -> ?avatar:string ->
-
?unknown:Unknown.t -> unit -> t
-
(** [make] is like {!create} but allows setting unknown fields.
-
Useful when round-tripping JSON with custom extensions. *)
(** {1 Accessors} *)
+3 -6
lib/hub.ml
···
unknown : Unknown.t;
}
-
let make ~type_ ~url ?(unknown = Unknown.empty) () =
+
let create ~type_ ~url ?(unknown = Unknown.empty) () =
{ type_; url; unknown }
-
-
let create ~type_ ~url () =
-
make ~type_ ~url ()
let type_ t = t.type_
let url t = t.url
···
} in
map ~kind:"Unknown members" Jsont.json ~dec_empty ~dec_add ~dec_finish ~enc
in
-
let make_obj type_ url unknown = make ~type_ ~url ~unknown () in
-
Jsont.Object.map ~kind ~doc make_obj
+
let create_obj type_ url unknown = create ~type_ ~url ~unknown () in
+
Jsont.Object.map ~kind ~doc create_obj
|> Jsont.Object.mem "type" Jsont.string ~enc:type_
|> Jsont.Object.mem "url" Jsont.string ~enc:url
|> Jsont.Object.keep_unknown unknown_mems ~enc:unknown
+5 -7
lib/hub.mli
···
(** {1 Construction} *)
-
val create : type_:string -> url:string -> unit -> t
-
(** [create ~type_ ~url ()] creates a hub object.
+
val create :
+
type_:string -> url:string ->
+
?unknown:Unknown.t -> unit -> t
+
(** [create ~type_ ~url ?unknown ()] creates a hub object.
@param type_ The type of hub protocol (e.g., ["rssCloud"], ["WebSub"])
@param url The URL endpoint for the hub
+
@param unknown Unknown/custom fields for extensions (default: empty)
{b Example:}
{[
···
~type_:"WebSub"
~url:"https://pubsubhubbub.appspot.com/" ()
]} *)
-
-
val make :
-
type_:string -> url:string ->
-
?unknown:Unknown.t -> unit -> t
-
(** [make] is like {!create} but allows setting unknown fields. *)
(** {1 Accessors} *)
+1 -6
lib/item.ml
···
unknown : Unknown.t;
}
-
let make ~id ~content ?url ?external_url ?title ?summary ?image ?banner_image
+
let create ~id ~content ?url ?external_url ?title ?summary ?image ?banner_image
?date_published ?date_modified ?authors ?tags ?language ?attachments ?references
?(unknown = Unknown.empty) () =
{
···
date_published; date_modified; authors; tags; language; attachments; references;
unknown;
}
-
-
let create ~id ~content ?url ?external_url ?title ?summary ?image ?banner_image
-
?date_published ?date_modified ?authors ?tags ?language ?attachments ?references () =
-
make ~id ~content ?url ?external_url ?title ?summary ?image ?banner_image
-
?date_published ?date_modified ?authors ?tags ?language ?attachments ?references ()
let id t = t.id
let content t = t.content
-19
lib/item.mli
···
?language:string ->
?attachments:Attachment.t list ->
?references:Reference.t list ->
-
unit ->
-
t
-
-
val make :
-
id:string ->
-
content:content ->
-
?url:string ->
-
?external_url:string ->
-
?title:string ->
-
?summary:string ->
-
?image:string ->
-
?banner_image:string ->
-
?date_published:Ptime.t ->
-
?date_modified:Ptime.t ->
-
?authors:Author.t list ->
-
?tags:string list ->
-
?language:string ->
-
?attachments:Attachment.t list ->
-
?references:Reference.t list ->
?unknown:Unknown.t ->
unit ->
t
+1 -6
lib/jsonfeed.ml
···
unknown : Unknown.t;
}
-
let make ~title ?home_page_url ?feed_url ?description ?user_comment
+
let create ~title ?home_page_url ?feed_url ?description ?user_comment
?next_url ?icon ?favicon ?authors ?language ?expired ?hubs ~items
?(unknown = Unknown.empty) () =
{
···
items;
unknown;
}
-
-
let create ~title ?home_page_url ?feed_url ?description ?user_comment
-
?next_url ?icon ?favicon ?authors ?language ?expired ?hubs ~items () =
-
make ~title ?home_page_url ?feed_url ?description ?user_comment
-
?next_url ?icon ?favicon ?authors ?language ?expired ?hubs ~items ()
let version t = t.version
let title t = t.title
+8 -38
lib/jsonfeed.mli
···
type t
-
(** {1 Unknown Fields} *)
+
(** {1 Jsont Type} *)
+
+
val jsont : t Jsont.t
+
(** Declarative JSON type for JSON feeds.
+
+
Maps the complete JSON Feed 1.1 specification including all required
+
and optional fields. *)
module Unknown : sig
type t = (string * Jsont.json) list
···
(** [is_empty u] returns [true] if there are no unknown fields. *)
end
-
-
(** {1 Jsont Type} *)
-
-
val jsont : t Jsont.t
-
(** Declarative JSON type for JSON feeds.
-
-
Maps the complete JSON Feed 1.1 specification including all required
-
and optional fields. *)
-
-
-
(** {1 Construction} *)
-
val create :
title:string ->
?home_page_url:string ->
···
?expired:bool ->
?hubs:Hub.t list ->
items:Item.t list ->
-
unit ->
-
t
-
-
val make :
-
title:string ->
-
?home_page_url:string ->
-
?feed_url:string ->
-
?description:string ->
-
?user_comment:string ->
-
?next_url:string ->
-
?icon:string ->
-
?favicon:string ->
-
?authors:Author.t list ->
-
?language:string ->
-
?expired:bool ->
-
?hubs:Hub.t list ->
-
items:Item.t list ->
?unknown:Unknown.t ->
unit ->
t
-
-
-
(** {1 Accessors} *)
val version : t -> string
val title : t -> string
···
val items : t -> Item.t list
val unknown : t -> Unknown.t
-
-
(** {1 Encoding and Decoding with Bytesrw} *)
+
(** {1 Encoding and Decoding} *)
val decode :
?layout:bool -> ?locs:bool -> ?file:string ->
···
(** [encode_string feed] encodes [feed] to a string. *)
-
(** {1 Convenience Functions} *)
-
val of_string : string -> (t, Jsont.Error.t) result
(** Alias for [decode_string] with default options. *)
···
val pp : Format.formatter -> t -> unit
val pp_summary : Format.formatter -> t -> unit
-
(** {1 Submodules} *)
+3 -6
lib/reference.ml
···
unknown : Unknown.t;
}
-
let make ~url ?doi ?cito ?(unknown = Unknown.empty) () =
+
let create ~url ?doi ?cito ?(unknown = Unknown.empty) () =
{ url; doi; cito; unknown }
-
-
let create ~url ?doi ?cito () =
-
make ~url ?doi ?cito ()
let url t = t.url
let doi t = t.doi
···
} in
map ~kind:"Unknown members" Jsont.json ~dec_empty ~dec_add ~dec_finish ~enc
in
-
let make_obj url doi cito unknown = make ~url ?doi ?cito ~unknown () in
-
Jsont.Object.map ~kind ~doc make_obj
+
let create_obj url doi cito unknown = create ~url ?doi ?cito ~unknown () in
+
Jsont.Object.map ~kind ~doc create_obj
|> Jsont.Object.mem "url" Jsont.string ~enc:url
|> Jsont.Object.opt_mem "doi" Jsont.string ~enc:doi
|> Jsont.Object.opt_mem "cito" (Jsont.list Cito.jsont) ~enc:cito
+3 -10
lib/reference.mli
···
url:string ->
?doi:string ->
?cito:Cito.t list ->
+
?unknown:Unknown.t ->
unit ->
t
-
(** [create ~url ?doi ?cito ()] creates a reference.
+
(** [create ~url ?doi ?cito ?unknown ()] creates a reference.
@param url Unique URL for the reference (required).
A URL based on a persistent unique identifier (like DOI) is recommended.
@param doi Digital Object Identifier for the reference
@param cito Citation Typing Ontology intent annotations
+
@param unknown Unknown/custom fields for extensions (default: empty)
{b Examples:}
{[
···
~cito:[`CitesAsRecommendedReading; `UsesMethodIn]
()
]} *)
-
-
val make :
-
url:string ->
-
?doi:string ->
-
?cito:Cito.t list ->
-
?unknown:Unknown.t ->
-
unit ->
-
t
-
(** [make] is like {!create} but allows setting unknown fields. *)
(** {1 Accessors} *)