A client library for the Gemini and Titan protocols
$ dotnet add package OpalA client library for the Gemini protocol written for .NET 6
Install the Nuget package
Install-Package Opal -Version 1.0.0
Create an instance of a client and make requests
// the default behavior is to automatically follow redirects and to persit
// local and remote certificates to disk
var client = OpalClient.CreateNew(OpalOptions.Default);
var response = client.SendRequest("gemini.circumlunar.space");
if (response is GemtextResponse gmi)
{
// the response body may accessed directly...
using (var reader = new StreamReader(gmi.Body))
Console.WriteLine(reader.ReadToEnd());
// ... or as a collection of strongly-typed ILine objects
foreach (var line in gmi.AsDocument())
{
if (line is LinkLine link)
Console.WriteLine($"Found link to {link.Uri}");
Console.WriteLine(line);
}
}
Subscribe to events in order to control certain protocol features
var client = OpalClient.CreateNew(OpalOptions.Default);
// using the default configuration, this certificate will be saved to the disk and
// sent whenever this host asks for it
client.CertificateRequired += (_, e) =>
e.Certificate = CertificateHelper.GenerateNew($"cool glasses for {e.Host}", TimeSpan.FromDays(100));
client.InputRequired +=
(_, e) =>
{
Console.Write($"{e.Prompt}: ");
e.Value = Console.ReadLine();
};