12345678910111213141516171819202122232425262728293031323334353637383940(*
* Copyright (c) 2014, OCaml.org project
* Copyright (c) 2015 KC Sivaramakrishnan <sk826@cl.cam.ac.uk>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)typesource={name:string;url:string}typecontent=AtomofSyndic.Atom.feed|Rss2ofSyndic.Rss2.channelletstring_of_feed=functionAtom_->"Atom"|Rss2_->"Rss2"typet={name:string;title:string;url:string;content:content}letclassify_feed~xmlbase(xml:string)=tryAtom(Syndic.Atom.parse~xmlbase(Xmlm.make_input(`String(0,xml))))withSyndic.Atom.Error.Error_->(tryRss2(Syndic.Rss2.parse~xmlbase(Xmlm.make_input(`String(0,xml))))withSyndic.Rss2.Error.Error_->failwith"Neither Atom nor RSS2 feed")letfetch(source:source)=letxmlbase=Uri.of_string@@source.urlinletresponse=Http.getsource.urlinletcontent=classify_feed~xmlbaseresponseinlettitle=matchcontentwith|Atomatom->Util.string_of_text_constructatom.Syndic.Atom.title|Rss2ch->ch.Syndic.Rss2.titlein{name=source.name;title;content;url=source.url}