Fix use of CAMLparam etc macros.
[perl4caml.git] / examples / google.ml
1 (* Example program which uses Net::Google to query Google.
2  * You will need to have a Google API key in ~/.googlekey for this to work.
3  * Copyright (C) 2003 Merjis Ltd.
4  * $Id: google.ml,v 1.4 2003-12-11 17:41:52 rich Exp $
5  *)
6
7 open Printf
8
9 open Pl_Net_Google
10
11 let () =
12   (* Load Google API key. *)
13   let home = Sys.getenv "HOME" in
14   let chan = open_in (home ^ "/.googlekey") in
15   let key = input_line chan in
16   close_in chan;
17
18   (* Create the Google query object. *)
19   let google = Pl_Net_Google.new_ ~key () in
20
21   (* Search. *)
22   let search = google#search () in
23   search#set_query "merjis";
24   search#set_max_results 5;
25
26   printf "Top 5 results for \"merjis\":\n"; flush stdout;
27
28   List.iter
29     (fun response ->
30        printf "* %s\n  <URL:%s>\n\n" response#title response#url
31     ) search#results;
32
33   (* Perform a full collection - good way to find GC/allocation bugs. *)
34   Gc.full_major ()