Add Cargo.toml metadata and README

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 3 years ago
parent 2811aeb40d
commit d6d59c012e
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,7 +1,12 @@
[package]
name = "hydrus-ptr-client"
description = "A http client for the hydrus ptr"
authors = ["trivernis"]
version = "0.1.0"
edition = "2021"
license = "apache-2.0"
readme = "README.md"
repository = "https://github.com/Trivernis/hydrus-ptr-client"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

@ -0,0 +1,47 @@
# Hydrus PTR Client [![](https://img.shields.io/docsrs/hydrus-ptr-client)](https://docs.rs/hydrus-ptr-client) [![](https://img.shields.io/crates/v/hydrus-ptr-client)](https://crates.io/crates/hydrus-ptr-client)
A rust http client for the hydrus PTR. Completeness is not guaranteed.
## Usage
## Fetching metadata and retrieving updates
```rust
use hydrus_ptr_client::Client;
#[tokio::main]
async fn main() {
let client = Client::builder().accept_invalid_certs(true).build().unwrap();
// list of all update files since id = 0
let metadata = client.get_metadata(0).await.unwrap();
let first_update_file = metadata.update_hashes().swap_remove(0);
let update = client.get_update(first_update_file).await.unwrap();
println!("Got update {:?}", update);
}
```
## Streaming updates
```rust
use hydrus_ptr_client::Client;
use futures_util::StreamExt;
#[tokio::main]
async fn main() {
let client = Client::builder().accept_invalid_certs(true).build().unwrap();
// streams all update since id = 0
let mut update_stream = client.stream_updates(0).await.unwrap();
while let Some(result) = update_stream.next().await {
match result {
Ok(update) => println!("We got an update {:?}", update),
Err(e) => println!("Oh no, an error occurred {}", e),
}
break;
}
}
```
## License
Apache-2.0

@ -32,3 +32,13 @@ impl FromJson for MetadataResponse {
Ok(MetadataResponse(metadata))
}
}
impl MetadataResponse {
pub fn update_hashes(&self) -> Vec<&String> {
self.0
.entries
.iter()
.flat_map(|e| e.update_hashes.iter().collect::<Vec<&String>>())
.collect()
}
}

@ -1,3 +1,4 @@
#![allow(unused)]
use crate::constants::HYDRUS_TYPE_DICTIONARY;
use crate::hydrus_serializable::HydrusSerializable;
use crate::{Error, Result};

@ -1,9 +1,11 @@
#![doc=include_str!("../README.md")]
mod client;
mod client_builder;
pub(crate) mod constants;
mod endpoints;
mod error;
pub mod hydrus_serializable;
pub(crate) mod hydrus_serializable;
pub use client::*;
pub use client_builder::*;

@ -11,7 +11,8 @@ async fn test_options() {
#[tokio::test]
async fn test_metadata() {
let client = common::get_client();
client.get_metadata(0).await.unwrap();
let metadata = client.get_metadata(0).await.unwrap();
assert!(metadata.update_hashes().len() > 0);
}
const DEFINITIONS_UPDATE_HASH: &str =
@ -32,8 +33,10 @@ async fn test_update_stream() {
let client = common::get_client(); // 3230
let mut update_stream = client.stream_updates(0).await.unwrap();
let mut retry_count = 3;
let mut test_count = 25;
while let Some(update) = update_stream.next().await {
test_count -= 1;
if let Err(e) = update {
if retry_count > 0 {
retry_count -= 1;
@ -45,6 +48,11 @@ async fn test_update_stream() {
e
)
}
} else {
retry_count = 3;
if test_count <= 0 {
break;
}
}
}
}

Loading…
Cancel
Save