|
|
@ -71,34 +71,34 @@ |
|
|
|
)] |
|
|
|
)] |
|
|
|
#![allow(broken_intra_doc_links)] |
|
|
|
#![allow(broken_intra_doc_links)] |
|
|
|
|
|
|
|
|
|
|
|
use std::{ |
|
|
|
use std::{borrow::Cow, io::BufRead, ops}; |
|
|
|
borrow::Cow, |
|
|
|
|
|
|
|
io::BufRead, |
|
|
|
|
|
|
|
ops, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use reqwest::{Client, RequestBuilder, Response}; |
|
|
|
use reqwest::{Client, RequestBuilder, Response}; |
|
|
|
use tap_reader::Tap; |
|
|
|
use tap_reader::Tap; |
|
|
|
use tungstenite::client::AutoStream; |
|
|
|
use tungstenite::client::AutoStream; |
|
|
|
|
|
|
|
|
|
|
|
use crate::entities::prelude::*; |
|
|
|
use crate::{ |
|
|
|
use crate::http_send::{HttpSend, HttpSender}; |
|
|
|
entities::prelude::*, |
|
|
|
use crate::page::Page; |
|
|
|
http_send::{HttpSend, HttpSender}, |
|
|
|
|
|
|
|
page::Page, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
pub use crate::data::Data; |
|
|
|
pub use crate::{ |
|
|
|
pub use crate::errors::{ApiError, Error, Result}; |
|
|
|
data::Data, |
|
|
|
pub use isolang::Language; |
|
|
|
errors::{ApiError, Error, Result}, |
|
|
|
pub use crate::mastodon_client::{MastodonClient, MastodonUnauthenticated}; |
|
|
|
mastodon_client::{MastodonClient, MastodonUnauthenticated}, |
|
|
|
pub use crate::media_builder::MediaBuilder; |
|
|
|
media_builder::MediaBuilder, |
|
|
|
pub use crate::registration::Registration; |
|
|
|
registration::Registration, |
|
|
|
pub use crate::requests::{ |
|
|
|
requests::{ |
|
|
|
AddFilterRequest, |
|
|
|
AddFilterRequest, |
|
|
|
AddPushRequest, |
|
|
|
AddPushRequest, |
|
|
|
StatusesRequest, |
|
|
|
StatusesRequest, |
|
|
|
UpdateCredsRequest, |
|
|
|
UpdateCredsRequest, |
|
|
|
UpdatePushRequest, |
|
|
|
UpdatePushRequest, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
status_builder::{NewStatus, StatusBuilder}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
pub use crate::status_builder::{NewStatus, StatusBuilder}; |
|
|
|
pub use isolang::Language; |
|
|
|
|
|
|
|
|
|
|
|
/// Registering your App
|
|
|
|
/// Registering your App
|
|
|
|
pub mod apps; |
|
|
|
pub mod apps; |
|
|
@ -129,14 +129,16 @@ pub mod status_builder; |
|
|
|
mod macros; |
|
|
|
mod macros; |
|
|
|
/// Automatically import the things you need
|
|
|
|
/// Automatically import the things you need
|
|
|
|
pub mod prelude { |
|
|
|
pub mod prelude { |
|
|
|
pub use crate::scopes::Scopes; |
|
|
|
pub use crate::{ |
|
|
|
pub use crate::Data; |
|
|
|
scopes::Scopes, |
|
|
|
pub use crate::Mastodon; |
|
|
|
Data, |
|
|
|
pub use crate::MastodonClient; |
|
|
|
Mastodon, |
|
|
|
pub use crate::NewStatus; |
|
|
|
MastodonClient, |
|
|
|
pub use crate::Registration; |
|
|
|
NewStatus, |
|
|
|
pub use crate::StatusBuilder; |
|
|
|
Registration, |
|
|
|
pub use crate::StatusesRequest; |
|
|
|
StatusBuilder, |
|
|
|
|
|
|
|
StatusesRequest, |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Your mastodon application client, handles all requests to and from Mastodon.
|
|
|
|
/// Your mastodon application client, handles all requests to and from Mastodon.
|
|
|
@ -473,7 +475,8 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
}; |
|
|
|
}; |
|
|
|
url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
url.set_scheme(new_scheme) |
|
|
|
|
|
|
|
.map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
|
|
|
|
|
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
|
|
|
|
|
|
|
@ -492,7 +495,8 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
}; |
|
|
|
}; |
|
|
|
url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
url.set_scheme(new_scheme) |
|
|
|
|
|
|
|
.map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
|
|
|
|
|
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
|
|
|
|
|
|
|
@ -511,7 +515,8 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
}; |
|
|
|
}; |
|
|
|
url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
url.set_scheme(new_scheme) |
|
|
|
|
|
|
|
.map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
|
|
|
|
|
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
|
|
|
|
|
|
|
@ -531,7 +536,8 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
}; |
|
|
|
}; |
|
|
|
url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
url.set_scheme(new_scheme) |
|
|
|
|
|
|
|
.map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
|
|
|
|
|
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
|
|
|
|
|
|
|
@ -551,7 +557,8 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
}; |
|
|
|
}; |
|
|
|
url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
url.set_scheme(new_scheme) |
|
|
|
|
|
|
|
.map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
|
|
|
|
|
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
|
|
|
|
|
|
|
@ -571,7 +578,8 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
}; |
|
|
|
}; |
|
|
|
url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
url.set_scheme(new_scheme) |
|
|
|
|
|
|
|
.map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
|
|
|
|
|
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
|
|
|
|
|
|
|
@ -590,7 +598,8 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
}; |
|
|
|
}; |
|
|
|
url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
url.set_scheme(new_scheme) |
|
|
|
|
|
|
|
.map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
|
|
|
|
|
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
|
|
|
|
|
|
|
@ -631,7 +640,8 @@ impl<H: HttpSend> MastodonClient<H> for Mastodon<H> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
/// WebSocket newtype so that EventStream can be implemented without coherency issues
|
|
|
|
/// WebSocket newtype so that EventStream can be implemented without coherency
|
|
|
|
|
|
|
|
/// issues
|
|
|
|
pub struct WebSocket(tungstenite::protocol::WebSocket<AutoStream>); |
|
|
|
pub struct WebSocket(tungstenite::protocol::WebSocket<AutoStream>); |
|
|
|
|
|
|
|
|
|
|
|
/// A type that streaming events can be read from
|
|
|
|
/// A type that streaming events can be read from
|
|
|
@ -684,12 +694,12 @@ impl<R: EventStream> EventReader<R> { |
|
|
|
fn make_event(&self, lines: &[String]) -> Result<Event> { |
|
|
|
fn make_event(&self, lines: &[String]) -> Result<Event> { |
|
|
|
let event; |
|
|
|
let event; |
|
|
|
let data; |
|
|
|
let data; |
|
|
|
if let Some(event_line) = lines |
|
|
|
if let Some(event_line) = lines.iter().find(|line| line.starts_with("event:")) { |
|
|
|
.iter() |
|
|
|
|
|
|
|
.find(|line| line.starts_with("event:")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
event = event_line[6..].trim().to_string(); |
|
|
|
event = event_line[6..].trim().to_string(); |
|
|
|
data = lines.iter().find(|line| line.starts_with("data:")).map(|x| x[5..].trim().to_string()); |
|
|
|
data = lines |
|
|
|
|
|
|
|
.iter() |
|
|
|
|
|
|
|
.find(|line| line.starts_with("data:")) |
|
|
|
|
|
|
|
.map(|x| x[5..].trim().to_string()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
use serde::Deserialize; |
|
|
|
use serde::Deserialize; |
|
|
|
#[derive(Deserialize)] |
|
|
|
#[derive(Deserialize)] |
|
|
@ -816,7 +826,8 @@ impl<H: HttpSend> MastodonUnauth<H> { |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
x => return Err(Error::Other(format!("Bad URL scheme: {}", x))), |
|
|
|
}; |
|
|
|
}; |
|
|
|
url.set_scheme(new_scheme).map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
url.set_scheme(new_scheme) |
|
|
|
|
|
|
|
.map_err(|_| Error::Other("Bad URL scheme!".to_string()))?; |
|
|
|
|
|
|
|
|
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
let client = tungstenite::connect(url.as_str())?.0; |
|
|
|
|
|
|
|
|
|
|
|