My agentic slop goes here. Not intended for anyone else!
1open Zulip
2
3let () =
4 Printf.printf "OCaml Zulip TOML Support Demo\n";
5 Printf.printf "=============================\n\n";
6
7 (* Example 1: Create a sample zuliprc TOML file *)
8 let zuliprc_content = {|
9# Zulip API Configuration
10[api]
11email = "demo@example.com"
12key = "demo-api-key-12345"
13site = "https://demo.zulipchat.com"
14
15# Optional settings
16insecure = false
17cert_bundle = "/etc/ssl/certs/ca-certificates.crt"
18|} in
19
20 let zuliprc_file = "demo_zuliprc.toml" in
21 let oc = open_out zuliprc_file in
22 output_string oc zuliprc_content;
23 close_out oc;
24
25 Printf.printf "Created sample zuliprc.toml file:\n%s\n" zuliprc_content;
26
27 (* Test loading auth from TOML *)
28 (match Auth.from_zuliprc ~path:zuliprc_file () with
29 | Ok auth ->
30 Printf.printf "✅ Successfully loaded authentication from TOML:\n";
31 Printf.printf " Email: %s\n" (Auth.email auth);
32 Printf.printf " Server: %s\n" (Auth.server_url auth);
33 Printf.printf " Auth Header: %s\n" (Auth.to_basic_auth_header auth);
34
35 (* Test creating client *)
36 let client = Client.create () auth in
37 Printf.printf "✅ Created client successfully\n\n";
38
39 (* Test basic functionality *)
40 (match Client.request client ~method_:`GET ~path:"/users/me" () with
41 | Ok _response -> Printf.printf "✅ Mock API request succeeded\n"
42 | Error err -> Printf.printf "❌ API request failed: %s\n" (Error.message err))
43 | Error err ->
44 Printf.printf "❌ Failed to load auth from TOML: %s\n" (Error.message err));
45
46 (* Example 2: Root-level TOML configuration *)
47 let root_toml_content = {|
48email = "root-user@example.com"
49key = "root-api-key-67890"
50site = "https://root.zulipchat.com"
51|} in
52
53 let root_file = "demo_root.toml" in
54 let oc = open_out root_file in
55 output_string oc root_toml_content;
56 close_out oc;
57
58 Printf.printf "\nTesting root-level TOML configuration:\n";
59 (match Auth.from_zuliprc ~path:root_file () with
60 | Ok auth ->
61 Printf.printf "✅ Root-level TOML parsed successfully:\n";
62 Printf.printf " Email: %s\n" (Auth.email auth);
63 Printf.printf " Server: %s\n" (Auth.server_url auth)
64 | Error err ->
65 Printf.printf "❌ Failed to parse root-level TOML: %s\n" (Error.message err));
66
67 (* Example 3: Test error handling with invalid TOML *)
68 let invalid_toml = {|
69[api
70email = "invalid@example.com" # Missing closing bracket
71|} in
72
73 let invalid_file = "demo_invalid.toml" in
74 let oc = open_out invalid_file in
75 output_string oc invalid_toml;
76 close_out oc;
77
78 Printf.printf "\nTesting error handling with invalid TOML:\n";
79 (match Auth.from_zuliprc ~path:invalid_file () with
80 | Ok _ -> Printf.printf "❌ Should have failed with invalid TOML\n"
81 | Error err -> Printf.printf "✅ Correctly handled invalid TOML: %s\n" (Error.message err));
82
83 (* Example 4: Test missing file handling *)
84 Printf.printf "\nTesting missing file handling:\n";
85 (match Auth.from_zuliprc ~path:"nonexistent.toml" () with
86 | Ok _ -> Printf.printf "❌ Should have failed with missing file\n"
87 | Error err -> Printf.printf "✅ Correctly handled missing file: %s\n" (Error.message err));
88
89 (* Clean up *)
90 List.iter (fun file ->
91 if Sys.file_exists file then Sys.remove file
92 ) [zuliprc_file; root_file; invalid_file];
93
94 Printf.printf "\n🎉 TOML support demonstration complete!\n";
95 Printf.printf "\nFeatures demonstrated:\n";
96 Printf.printf "• Parse TOML files with [api] section\n";
97 Printf.printf "• Parse TOML files with root-level configuration\n";
98 Printf.printf "• Proper error handling for invalid TOML syntax\n";
99 Printf.printf "• Proper error handling for missing files\n";
100 Printf.printf "• Integration with existing Zulip client\n"