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]
name = "actix-webfinger"
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"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/asonix/actix-webfinger"

View file

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