|
|
@ -19,25 +19,14 @@ use reqwest::multipart; |
|
|
|
use entities::prelude::*; |
|
|
|
use entities::prelude::*; |
|
|
|
pub use errors::{Error, Result}; |
|
|
|
pub use errors::{Error, Result}; |
|
|
|
use helpers::deserialise_response; |
|
|
|
use helpers::deserialise_response; |
|
|
|
use serde::{Serialize,Deserialize}; |
|
|
|
use requests::{AddFilterRequest, AddPushRequest, StatusesRequest, UpdateCredsRequest, UpdatePushRequest}; |
|
|
|
use requests::{ |
|
|
|
use serde::{Deserialize, Serialize}; |
|
|
|
AddFilterRequest, |
|
|
|
|
|
|
|
AddPushRequest, |
|
|
|
|
|
|
|
StatusesRequest, |
|
|
|
|
|
|
|
UpdateCredsRequest, |
|
|
|
|
|
|
|
UpdatePushRequest, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
use streaming::EventReader; |
|
|
|
use streaming::EventReader; |
|
|
|
pub use streaming::StreamKind; |
|
|
|
pub use streaming::StreamKind; |
|
|
|
|
|
|
|
|
|
|
|
pub use crate::{ |
|
|
|
pub use crate::{ |
|
|
|
data::AppData, |
|
|
|
data::AppData, media_builder::MediaBuilder, page::Page, registration::Registration, scopes::Scopes, |
|
|
|
media_builder::MediaBuilder, |
|
|
|
status_builder::NewStatus, status_builder::StatusBuilder, |
|
|
|
page::Page, |
|
|
|
|
|
|
|
registration::Registration, |
|
|
|
|
|
|
|
scopes::Scopes, |
|
|
|
|
|
|
|
status_builder::NewStatus, |
|
|
|
|
|
|
|
status_builder::StatusBuilder, |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#[macro_use] |
|
|
|
#[macro_use] |
|
|
@ -64,10 +53,10 @@ pub mod requests; |
|
|
|
pub mod scopes; |
|
|
|
pub mod scopes; |
|
|
|
/// Constructing a status
|
|
|
|
/// Constructing a status
|
|
|
|
pub mod status_builder; |
|
|
|
pub mod status_builder; |
|
|
|
/// Client that doesn't need auth
|
|
|
|
|
|
|
|
pub mod unauth; |
|
|
|
|
|
|
|
/// Streaming API
|
|
|
|
/// Streaming API
|
|
|
|
pub mod streaming; |
|
|
|
pub mod streaming; |
|
|
|
|
|
|
|
/// Client that doesn't need auth
|
|
|
|
|
|
|
|
pub mod unauth; |
|
|
|
|
|
|
|
|
|
|
|
pub mod debug; |
|
|
|
pub mod debug; |
|
|
|
|
|
|
|
|
|
|
@ -88,12 +77,12 @@ impl From<AppData> for FediClient { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Serialize,Deserialize,Clone,Copy,PartialEq)] |
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq)] |
|
|
|
#[serde(rename_all="snake_case")] |
|
|
|
#[serde(rename_all = "snake_case")] |
|
|
|
pub enum SearchType { |
|
|
|
pub enum SearchType { |
|
|
|
Accounts, |
|
|
|
Accounts, |
|
|
|
Hashtags, |
|
|
|
Hashtags, |
|
|
|
Statuses |
|
|
|
Statuses, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl FediClient { |
|
|
|
impl FediClient { |
|
|
@ -246,7 +235,9 @@ impl FediClient { |
|
|
|
|
|
|
|
|
|
|
|
/// Post a new status to the account.
|
|
|
|
/// Post a new status to the account.
|
|
|
|
pub async fn new_status(&self, status: NewStatus) -> Result<Status> { |
|
|
|
pub async fn new_status(&self, status: NewStatus) -> Result<Status> { |
|
|
|
let response = self.send(self.http_client.post(&self.route("/api/v1/statuses")).json(&status)).await?; |
|
|
|
let response = self |
|
|
|
|
|
|
|
.send(self.http_client.post(&self.route("/api/v1/statuses")).json(&status)) |
|
|
|
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
deserialise_response(response).await |
|
|
|
deserialise_response(response).await |
|
|
|
} |
|
|
|
} |
|
|
@ -306,7 +297,9 @@ impl FediClient { |
|
|
|
/// Add a push notifications subscription
|
|
|
|
/// Add a push notifications subscription
|
|
|
|
pub async fn add_push_subscription(&self, request: &AddPushRequest) -> Result<Subscription> { |
|
|
|
pub async fn add_push_subscription(&self, request: &AddPushRequest) -> Result<Subscription> { |
|
|
|
let request = request.build()?; |
|
|
|
let request = request.build()?; |
|
|
|
let response = self.send(self.http_client.post(&self.route("/api/v1/push/subscription")).json(&request)).await?; |
|
|
|
let response = self |
|
|
|
|
|
|
|
.send(self.http_client.post(&self.route("/api/v1/push/subscription")).json(&request)) |
|
|
|
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
deserialise_response(response).await |
|
|
|
deserialise_response(response).await |
|
|
|
} |
|
|
|
} |
|
|
@ -315,7 +308,9 @@ impl FediClient { |
|
|
|
/// access token
|
|
|
|
/// access token
|
|
|
|
pub async fn update_push_data(&self, request: &UpdatePushRequest) -> Result<Subscription> { |
|
|
|
pub async fn update_push_data(&self, request: &UpdatePushRequest) -> Result<Subscription> { |
|
|
|
let request = request.build(); |
|
|
|
let request = request.build(); |
|
|
|
let response = self.send(self.http_client.put(&self.route("/api/v1/push/subscription")).json(&request)).await?; |
|
|
|
let response = self |
|
|
|
|
|
|
|
.send(self.http_client.put(&self.route("/api/v1/push/subscription")).json(&request)) |
|
|
|
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
deserialise_response(response).await |
|
|
|
deserialise_response(response).await |
|
|
|
} |
|
|
|
} |
|
|
@ -332,7 +327,6 @@ impl FediClient { |
|
|
|
self.following(&me.id).await |
|
|
|
self.following(&me.id).await |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// returns events that are relevant to the authorized user, i.e. home
|
|
|
|
/// returns events that are relevant to the authorized user, i.e. home
|
|
|
|
/// timeline & notifications
|
|
|
|
/// timeline & notifications
|
|
|
|
pub async fn streaming_user(&self) -> Result<EventReader> { |
|
|
|
pub async fn streaming_user(&self) -> Result<EventReader> { |
|
|
@ -380,7 +374,8 @@ impl FediClient { |
|
|
|
let mut form = multipart::Form::new(); |
|
|
|
let mut form = multipart::Form::new(); |
|
|
|
form = match media.data { |
|
|
|
form = match media.data { |
|
|
|
MediaBuilderData::Reader(reader) => { |
|
|
|
MediaBuilderData::Reader(reader) => { |
|
|
|
let mut part = multipart::Part::stream(reqwest::Body::wrap_stream(tokio_util::io::ReaderStream::new(reader))); |
|
|
|
let mut part = |
|
|
|
|
|
|
|
multipart::Part::stream(reqwest::Body::wrap_stream(tokio_util::io::ReaderStream::new(reader))); |
|
|
|
if let Some(filename) = media.filename { |
|
|
|
if let Some(filename) = media.filename { |
|
|
|
part = part.file_name(filename); |
|
|
|
part = part.file_name(filename); |
|
|
|
} |
|
|
|
} |
|
|
@ -406,7 +401,9 @@ impl FediClient { |
|
|
|
form = form.text("focus", format!("{},{}", x, y)); |
|
|
|
form = form.text("focus", format!("{},{}", x, y)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let response = self.send(self.http_client.post(&self.route("/api/v1/media")).multipart(form)).await?; |
|
|
|
let response = self |
|
|
|
|
|
|
|
.send(self.http_client.post(&self.route("/api/v1/media")).multipart(form)) |
|
|
|
|
|
|
|
.await?; |
|
|
|
|
|
|
|
|
|
|
|
deserialise_response(response).await |
|
|
|
deserialise_response(response).await |
|
|
|
} |
|
|
|
} |
|
|
@ -454,4 +451,3 @@ impl ClientBuilder { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|