Update versions and examples
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Aode (Lion) 2022-03-08 11:56:05 -06:00
parent fe105531f6
commit 8ab8f74821
3 changed files with 50 additions and 24 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "actix-webfinger"
description = "Types and helpers to create and fetch Webfinger resources"
version = "0.4.0"
version = "0.4.1"
license = "GPL-3.0"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/asonix/actix-webfinger"

View file

@ -13,23 +13,30 @@ First, add Actix Webfinger as a dependency
```toml
[dependencies]
actix-rt = "=2.0.0-beta.1"
actix-web = "4.0.0-alpha.1"
actix-webfinger = "0.4.0-beta.1"
actix-rt = "2.6.0"
actix-web = "4.0.0"
actix-webfinger = "0.4.0"
```
Then use it in your application
#### Client Example
```rust
use actix_web::client::Client;
use actix_webfinger::Webfinger;
use awc::Client;
use std::error::Error;
#[actix_rt::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = Client::default();
let wf = Webfinger::fetch(&client, "asonix@asonix.dog", "localhost:8000", false).await?;
let wf = Webfinger::fetch(
&client,
Some("acct:"),
"asonix@localhost:8000",
"localhost:8000",
false,
)
.await?;
println!("asonix's webfinger:\n{:#?}", wf);
Ok(())
@ -38,7 +45,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
#### Server Example
```rust
use actix_web::{web::Data, App, HttpServer};
use actix_web::{middleware::Logger, web::Data, App, HttpServer};
use actix_webfinger::{Resolver, Webfinger};
use std::{error::Error, future::Future, pin::Pin};
@ -49,16 +56,19 @@ pub struct MyState {
pub struct MyResolver;
type LocalBoxFuture<'a, Output> = Pin<Box<dyn Future<Output = Output> + 'a>>;
impl Resolver for MyResolver {
type State = Data<MyState>;
type Error = actix_web::error::JsonPayloadError;
fn find(
scheme: Option<&str>,
account: &str,
domain: &str,
state: Data<MyState>,
) -> Pin<Box<dyn Future<Output = Result<Option<Webfinger>, Self::Error>>>> {
let w = if domain == state.domain {
) -> LocalBoxFuture<'static, Result<Option<Webfinger>, Self::Error>> {
let w = if scheme == Some("acct:") && domain == state.domain {
Some(Webfinger::new(&format!("{}@{}", account, domain)))
} else {
None
@ -70,12 +80,15 @@ impl Resolver for MyResolver {
#[actix_rt::main]
async fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_LOG", "info");
pretty_env_logger::init();
HttpServer::new(|| {
App::new()
.data(MyState {
domain: "asonix.dog".to_owned(),
})
.service(actix_webfinger::resource::<_, MyResolver>())
.app_data(Data::new(MyState {
domain: "localhost:8000".to_owned(),
}))
.wrap(Logger::default())
.service(actix_webfinger::resource::<MyResolver>())
})
.bind("127.0.0.1:8000")?
.run()

View file

@ -13,9 +13,9 @@
//!
//! ```toml
//! [dependencies]
//! actix = "0.10.0-alpha.1"
//! actix-web = "3.0.0-alpha.1"
//! actix-webfinger = "0.3.0-alpha.2"
//! actix-rt = "2.6.0"
//! actix-web = "4.0.0"
//! actix-webfinger = "0.4.0"
//! ```
//!
//! Then use it in your application
@ -29,7 +29,14 @@
//! #[actix_rt::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//! let client = Client::default();
//! let wf = Webfinger::fetch(&client, None, "asonix@asonix.dog", "localhost:8000", false).await?;
//! let wf = Webfinger::fetch(
//! &client,
//! Some("acct:"),
//! "asonix@localhost:8000",
//! "localhost:8000",
//! false,
//! )
//! .await?;
//!
//! println!("asonix's webfinger:\n{:#?}", wf);
//! Ok(())
@ -38,7 +45,7 @@
//!
//! #### Server Example
//! ```rust,ignore
//! use actix_web::{web::Data, App, HttpServer};
//! use actix_web::{middleware::Logger, web::Data, App, HttpServer};
//! use actix_webfinger::{Resolver, Webfinger};
//! use std::{error::Error, future::Future, pin::Pin};
//!
@ -49,16 +56,19 @@
//!
//! pub struct MyResolver;
//!
//! type LocalBoxFuture<'a, Output> = Pin<Box<dyn Future<Output = Output> + 'a>>;
//!
//! impl Resolver for MyResolver {
//! type State = Data<MyState>;
//! type Error = actix_web::error::JsonPayloadError;
//!
//! fn find(
//! scheme: Option<&str>,
//! account: &str,
//! domain: &str,
//! state: S,
//! ) -> Pin<Box<dyn Future<Output = Result<Option<Webfinger>, Self::Error>>>> {
//! let w = if domain == state.domain {
//! state: Data<MyState>,
//! ) -> LocalBoxFuture<'static, Result<Option<Webfinger>, Self::Error>> {
//! let w = if scheme == Some("acct:") && domain == state.domain {
//! Some(Webfinger::new(&format!("{}@{}", account, domain)))
//! } else {
//! None
@ -70,11 +80,14 @@
//!
//! #[actix_rt::main]
//! async fn main() -> Result<(), Box<dyn Error>> {
//! std::env::set_var("RUST_LOG", "info");
//! pretty_env_logger::init();
//! HttpServer::new(|| {
//! App::new()
//! .data(MyState {
//! domain: "asonix.dog".to_owned(),
//! })
//! .app_data(Data::new(MyState {
//! domain: "localhost:8000".to_owned(),
//! }))
//! .wrap(Logger::default())
//! .service(actix_webfinger::resource::<MyResolver>())
//! })
//! .bind("127.0.0.1:8000")?