draft new api version

This commit is contained in:
yggverse 2024-10-26 23:22:26 +03:00
parent 8a5f1e2a57
commit 3cde80b6a8
22 changed files with 323 additions and 747 deletions

View file

@ -1,11 +1,15 @@
# ggemini
Glib-oriented client for [Gemini protocol](https://geminiprotocol.net/)
Glib-oriented network library for [Gemini protocol](https://geminiprotocol.net/)
> [!IMPORTANT]
> Project in development!
>
This library initially created as extension for [Yoda Browser](https://github.com/YGGverse/Yoda),
but also could be useful for any other integration as depends of
[glib](https://crates.io/crates/glib) and [gio](https://crates.io/crates/gio) (`2.66+`) crates only.
## Install
```
@ -14,65 +18,22 @@ cargo add ggemini
## Usage
## `client`
### `client`
[Gio](https://docs.gtk.org/gio/) API already includes powerful [SocketClient](https://docs.gtk.org/gio/class.SocketClient.html),
so this Client just bit extends some features for Gemini Protocol.
#### `client::single_socket_request_async`
High-level API to make async socket request, auto-close connection on complete.
Return [Response](#clientresponseresponse) on success or [Error](#clienterror) enum on failure
``` rust
use glib::{Uri, UriFlags};
// Parse URL string to valid Glib URI object
match Uri::parse("gemini://geminiprotocol.net/", UriFlags::NONE) {
// Begin async request
Ok(uri) => ggemini::client::single_socket_request_async(uri, |result| match result {
// Process response
Ok(response) => {
// Expect success status
assert!(match response.header().status() {
Some(ggemini::client::response::header::Status::Success) => true,
_ => false,
})
}
Err(_) => assert!(false),
}),
Err(_) => assert!(false),
}
```
**Pay attention:**
* Response [Buffer](#clientsocketconnectioninputbufferBuffer) limited to default `capacity` (`0x400`) and `max_size` (`0xfffff`). If you want to change these values, use low-level API to setup connection manually.
* To use [Cancelable](https://docs.gtk.org/gio/class.Cancellable.html) or async Priority values, take a look at [connection](#clientsocketconnection) methods.
#### `client::Error`
#### `client::buffer`
#### `client::response`
Response parser for [InputStream](https://docs.gtk.org/gio/class.InputStream.html)
#### `client::response::Response`
#### `client::response::header`
#### `client::response::header::meta`
#### `client::response::header::mime`
#### `client::response::header::status`
#### `client::response::header::language`
#### `client::response::header::charset`
#### `client::response::body`
#### `client::socket`
#### `client::socket::connection`
#### `client::socket::connection::input`
#### `client::socket::connection::input::buffer`
#### `client::socket::connection::input::buffer::Buffer`
#### `client::socket::connection::output`
## Integrations
* [Yoda](https://github.com/YGGverse/Yoda) - Browser for Gemini Protocol
https://docs.gtk.org/glib/struct.Bytes.html
## See also