mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 09:05:45 +00:00
implement Request constructors, remove build methods
This commit is contained in:
parent
e2097138a9
commit
ce5d3ac4d2
5 changed files with 29 additions and 29 deletions
|
|
@ -53,10 +53,8 @@ use ggemini::client::{
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
Client::new().request_async(
|
Client::new().request_async(
|
||||||
Request::Gemini(
|
Request::gemini(
|
||||||
Gemini::build(
|
Uri::parse(REQUEST, UriFlags::NONE).unwrap(),
|
||||||
Uri::parse("gemini://geminiprotocol.net/", UriFlags::NONE).unwrap()
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
Priority::DEFAULT,
|
Priority::DEFAULT,
|
||||||
Cancellable::new(),
|
Cancellable::new(),
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ pub use gemini::Gemini;
|
||||||
pub use titan::Titan;
|
pub use titan::Titan;
|
||||||
|
|
||||||
use gio::NetworkAddress;
|
use gio::NetworkAddress;
|
||||||
|
use glib::Uri;
|
||||||
|
|
||||||
/// Single `Request` implementation for different protocols
|
/// Single `Request` implementation for different protocols
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
|
|
@ -15,6 +16,23 @@ pub enum Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
/// Create new `Self` for [Gemini protocol](https://geminiprotocol.net)
|
||||||
|
pub fn gemini(uri: Uri) -> Self {
|
||||||
|
Self::Gemini(Gemini { uri })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create new `Self` for [Titan protocol](gemini://transjovian.org/titan/page/The%20Titan%20Specification)
|
||||||
|
pub fn titan(uri: Uri, mime: String, token: Option<String>, data: Vec<u8>) -> Self {
|
||||||
|
Self::Titan(Titan {
|
||||||
|
uri,
|
||||||
|
mime,
|
||||||
|
token,
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/// Get [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) for `Self`
|
/// Get [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) for `Self`
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,6 @@ pub struct Gemini {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gemini {
|
impl Gemini {
|
||||||
// Constructors
|
|
||||||
|
|
||||||
/// Build valid new `Self`
|
|
||||||
pub fn build(uri: Uri) -> Self {
|
|
||||||
Self { uri } // @TODO validate
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)
|
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)
|
||||||
|
|
|
||||||
|
|
@ -9,18 +9,6 @@ pub struct Titan {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Titan {
|
impl Titan {
|
||||||
// Constructors
|
|
||||||
|
|
||||||
/// Build valid new `Self`
|
|
||||||
pub fn build(uri: Uri, mime: String, token: Option<String>, data: Vec<u8>) -> Self {
|
|
||||||
Self {
|
|
||||||
uri,
|
|
||||||
mime,
|
|
||||||
token,
|
|
||||||
data,
|
|
||||||
} // @TODO validate
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)
|
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,18 @@
|
||||||
use gio::*;
|
use gio::*;
|
||||||
use glib::*;
|
use glib::*;
|
||||||
|
|
||||||
use ggemini::client::connection::request::Gemini;
|
use ggemini::client::connection::Request;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn client_connection_request_gemini_build() {
|
fn client_connection_request_gemini() {
|
||||||
const REQUEST: &str = "gemini://geminiprotocol.net/";
|
const REQUEST: &str = "gemini://geminiprotocol.net/";
|
||||||
|
assert_eq!(
|
||||||
let request = Gemini::build(Uri::parse(REQUEST, UriFlags::NONE).unwrap());
|
&match Request::gemini(Uri::parse(REQUEST, UriFlags::NONE).unwrap()) {
|
||||||
|
Request::Gemini(request) => request.uri.to_string(),
|
||||||
assert_eq!(&request.uri.to_string(), REQUEST);
|
Request::Titan(_) => panic!(),
|
||||||
|
},
|
||||||
|
REQUEST
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TODO
|
// @TODO
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue