Update README

This commit is contained in:
asonix 2019-05-12 12:24:45 -05:00
parent 58b4eb3681
commit b636ff58b1
2 changed files with 37 additions and 29 deletions

View file

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

View file

@ -9,46 +9,51 @@ First, add Actix Webfinger as a dependency
```toml ```toml
[dependencies] [dependencies]
actix = "0.7" actix = "0.8"
actix-web = "0.7" actix-web = "1.0.0-beta.3"
actix-webfinger = "0.1" actix-webfinger = "0.2.0-beta.2"
``` ```
Then use it in your application Then use it in your application
#### Client Example #### Client Example
```rust ```rust
use actix::{Actor, System}; use actix::System;
use actix_web::client::ClientConnector; use actix_web::client::Connector;
use actix_webfinger::Webfinger; use actix_webfinger::Webfinger;
use futures::Future; use futures::{future::lazy, Future};
use openssl::ssl::{SslConnector, SslMethod}; use openssl::ssl::{SslConnector, SslMethod};
use std::error::Error;
fn main() { fn main() -> Result<(), Box<dyn Error>> {
let sys = System::new("asonix"); let sys = System::new("sir-boops");
let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build(); let ssl_conn = SslConnector::builder(SslMethod::tls())?.build();
let conn = ClientConnector::with_connector(ssl_conn).start(); let conn = Connector::new().ssl(ssl_conn).finish();
let fut = Webfinger::fetch(conn, "asonix@asonix.dog", "localhost:8000", false) let fut = lazy(move || {
.map(move |w: Webfinger| { Webfinger::fetch(conn, "asonix@asonix.dog", "localhost:8000", false)
println!("asonix's webfinger:\n{:#?}", w); .map(move |w: Webfinger| {
println!("asonix's webfinger:\n{:#?}", w);
System::current().stop(); System::current().stop();
}) })
.map_err(|e| eprintln!("Error: {}", e)); .map_err(|e| eprintln!("Error: {}", e))
});
actix::spawn(fut); actix::spawn(fut);
let _ = sys.run(); sys.run()?;
Ok(())
} }
``` ```
#### Server Example #### Server Example
```rust ```rust
use actix_web::server; use actix_web::{web::Data, App, HttpServer};
use actix_webfinger::{Resolver, Webfinger}; use actix_webfinger::{Resolver, Webfinger};
use futures::{future::IntoFuture, Future}; use futures::{future::IntoFuture, Future};
use std::error::Error;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MyState { pub struct MyState {
@ -57,13 +62,13 @@ pub struct MyState {
pub struct MyResolver; pub struct MyResolver;
impl Resolver<MyState> for MyResolver { impl Resolver<Data<MyState>> for MyResolver {
type Error = actix_web::error::JsonPayloadError; type Error = actix_web::error::JsonPayloadError;
fn find( fn find(
account: &str, account: &str,
domain: &str, domain: &str,
state: &MyState, state: &Data<MyState>,
) -> Box<dyn Future<Item = Option<Webfinger>, Error = Self::Error>> { ) -> Box<dyn Future<Item = Option<Webfinger>, Error = Self::Error>> {
let w = if domain == state.domain { let w = if domain == state.domain {
Some(Webfinger::new(&format!("{}@{}", account, domain))) Some(Webfinger::new(&format!("{}@{}", account, domain)))
@ -75,15 +80,18 @@ impl Resolver<MyState> for MyResolver {
} }
} }
fn main() { fn main() -> Result<(), Box<dyn Error>> {
server::new(|| { HttpServer::new(|| {
actix_webfinger::app::<MyState, MyResolver>(MyState { App::new()
domain: "asonix.dog".to_owned(), .data(MyState {
}) domain: "asonix.dog".to_owned(),
})
.service(actix_webfinger::resource::<_, MyResolver>())
}) })
.bind("127.0.0.1:8000") .bind("127.0.0.1:8000")?
.unwrap() .run()?;
.run();
Ok(())
} }
``` ```