|
|
@ -86,13 +86,7 @@ pub use crate::{ |
|
|
|
mastodon_client::{MastodonClient, MastodonUnauthenticated}, |
|
|
|
mastodon_client::{MastodonClient, MastodonUnauthenticated}, |
|
|
|
media_builder::MediaBuilder, |
|
|
|
media_builder::MediaBuilder, |
|
|
|
registration::Registration, |
|
|
|
registration::Registration, |
|
|
|
requests::{ |
|
|
|
requests::{AddFilterRequest, AddPushRequest, StatusesRequest, UpdateCredsRequest, UpdatePushRequest}, |
|
|
|
AddFilterRequest, |
|
|
|
|
|
|
|
AddPushRequest, |
|
|
|
|
|
|
|
StatusesRequest, |
|
|
|
|
|
|
|
UpdateCredsRequest, |
|
|
|
|
|
|
|
UpdatePushRequest, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
status_builder::{NewStatus, StatusBuilder}, |
|
|
|
status_builder::{NewStatus, StatusBuilder}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
pub use isolang::Language; |
|
|
|
pub use isolang::Language; |
|
|
@ -125,14 +119,7 @@ mod macros; |
|
|
|
/// Automatically import the things you need
|
|
|
|
/// Automatically import the things you need
|
|
|
|
pub mod prelude { |
|
|
|
pub mod prelude { |
|
|
|
pub use crate::{ |
|
|
|
pub use crate::{ |
|
|
|
scopes::Scopes, |
|
|
|
scopes::Scopes, Data, Mastodon, MastodonClient, NewStatus, Registration, StatusBuilder, StatusesRequest, |
|
|
|
Data, |
|
|
|
|
|
|
|
Mastodon, |
|
|
|
|
|
|
|
MastodonClient, |
|
|
|
|
|
|
|
NewStatus, |
|
|
|
|
|
|
|
Registration, |
|
|
|
|
|
|
|
StatusBuilder, |
|
|
|
|
|
|
|
StatusesRequest, |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -162,9 +149,7 @@ impl From<Data> for Mastodon { |
|
|
|
fn from(data: Data) -> Mastodon { |
|
|
|
fn from(data: Data) -> Mastodon { |
|
|
|
let mut builder = MastodonBuilder::new(); |
|
|
|
let mut builder = MastodonBuilder::new(); |
|
|
|
builder.data(data); |
|
|
|
builder.data(data); |
|
|
|
builder |
|
|
|
builder.build().expect("We know `data` is present, so this should be fine") |
|
|
|
.build() |
|
|
|
|
|
|
|
.expect("We know `data` is present, so this should be fine") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -289,11 +274,7 @@ impl MastodonClient for Mastodon { |
|
|
|
|
|
|
|
|
|
|
|
/// Post a new status to the account.
|
|
|
|
/// Post a new status to the account.
|
|
|
|
fn new_status(&self, status: NewStatus) -> Result<Status> { |
|
|
|
fn new_status(&self, status: NewStatus) -> Result<Status> { |
|
|
|
let response = self.send( |
|
|
|
let response = self.send(self.client.post(&self.route("/api/v1/statuses")).json(&status))?; |
|
|
|
self.client |
|
|
|
|
|
|
|
.post(&self.route("/api/v1/statuses")) |
|
|
|
|
|
|
|
.json(&status), |
|
|
|
|
|
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deserialise(response) |
|
|
|
deserialise(response) |
|
|
|
} |
|
|
|
} |
|
|
@ -393,11 +374,7 @@ impl MastodonClient for Mastodon { |
|
|
|
/// Add a push notifications subscription
|
|
|
|
/// Add a push notifications subscription
|
|
|
|
fn add_push_subscription(&self, request: &AddPushRequest) -> Result<Subscription> { |
|
|
|
fn add_push_subscription(&self, request: &AddPushRequest) -> Result<Subscription> { |
|
|
|
let request = request.build()?; |
|
|
|
let request = request.build()?; |
|
|
|
let response = self.send( |
|
|
|
let response = self.send(self.client.post(&self.route("/api/v1/push/subscription")).json(&request))?; |
|
|
|
self.client |
|
|
|
|
|
|
|
.post(&self.route("/api/v1/push/subscription")) |
|
|
|
|
|
|
|
.json(&request), |
|
|
|
|
|
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deserialise(response) |
|
|
|
deserialise(response) |
|
|
|
} |
|
|
|
} |
|
|
@ -406,11 +383,7 @@ impl MastodonClient for Mastodon { |
|
|
|
/// access token
|
|
|
|
/// access token
|
|
|
|
fn update_push_data(&self, request: &UpdatePushRequest) -> Result<Subscription> { |
|
|
|
fn update_push_data(&self, request: &UpdatePushRequest) -> Result<Subscription> { |
|
|
|
let request = request.build(); |
|
|
|
let request = request.build(); |
|
|
|
let response = self.send( |
|
|
|
let response = self.send(self.client.put(&self.route("/api/v1/push/subscription")).json(&request))?; |
|
|
|
self.client |
|
|
|
|
|
|
|
.put(&self.route("/api/v1/push/subscription")) |
|
|
|
|
|
|
|
.json(&request), |
|
|
|
|
|
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deserialise(response) |
|
|
|
deserialise(response) |
|
|
|
} |
|
|
|
} |
|
|
@ -462,10 +435,7 @@ impl MastodonClient for Mastodon { |
|
|
|
url.query_pairs_mut() |
|
|
|
url.query_pairs_mut() |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("stream", "user"); |
|
|
|
.append_pair("stream", "user"); |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())? |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())?.url().as_str().parse()?; |
|
|
|
.url() |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.parse()?; |
|
|
|
|
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
"http" => "ws", |
|
|
|
"http" => "ws", |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
@ -485,10 +455,7 @@ impl MastodonClient for Mastodon { |
|
|
|
url.query_pairs_mut() |
|
|
|
url.query_pairs_mut() |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("stream", "public"); |
|
|
|
.append_pair("stream", "public"); |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())? |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())?.url().as_str().parse()?; |
|
|
|
.url() |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.parse()?; |
|
|
|
|
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
"http" => "ws", |
|
|
|
"http" => "ws", |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
@ -508,10 +475,7 @@ impl MastodonClient for Mastodon { |
|
|
|
url.query_pairs_mut() |
|
|
|
url.query_pairs_mut() |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("stream", "public:local"); |
|
|
|
.append_pair("stream", "public:local"); |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())? |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())?.url().as_str().parse()?; |
|
|
|
.url() |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.parse()?; |
|
|
|
|
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
"http" => "ws", |
|
|
|
"http" => "ws", |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
@ -532,10 +496,7 @@ impl MastodonClient for Mastodon { |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("stream", "hashtag") |
|
|
|
.append_pair("stream", "hashtag") |
|
|
|
.append_pair("tag", hashtag); |
|
|
|
.append_pair("tag", hashtag); |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())? |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())?.url().as_str().parse()?; |
|
|
|
.url() |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.parse()?; |
|
|
|
|
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
"http" => "ws", |
|
|
|
"http" => "ws", |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
@ -556,10 +517,7 @@ impl MastodonClient for Mastodon { |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("stream", "hashtag:local") |
|
|
|
.append_pair("stream", "hashtag:local") |
|
|
|
.append_pair("tag", hashtag); |
|
|
|
.append_pair("tag", hashtag); |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())? |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())?.url().as_str().parse()?; |
|
|
|
.url() |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.parse()?; |
|
|
|
|
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
"http" => "ws", |
|
|
|
"http" => "ws", |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
@ -580,10 +538,7 @@ impl MastodonClient for Mastodon { |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("stream", "list") |
|
|
|
.append_pair("stream", "list") |
|
|
|
.append_pair("list", list_id); |
|
|
|
.append_pair("list", list_id); |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())? |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())?.url().as_str().parse()?; |
|
|
|
.url() |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.parse()?; |
|
|
|
|
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
"http" => "ws", |
|
|
|
"http" => "ws", |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
@ -603,10 +558,7 @@ impl MastodonClient for Mastodon { |
|
|
|
url.query_pairs_mut() |
|
|
|
url.query_pairs_mut() |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("access_token", &self.token) |
|
|
|
.append_pair("stream", "direct"); |
|
|
|
.append_pair("stream", "direct"); |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())? |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())?.url().as_str().parse()?; |
|
|
|
.url() |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.parse()?; |
|
|
|
|
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
"http" => "ws", |
|
|
|
"http" => "ws", |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
@ -689,11 +641,7 @@ impl MastodonClient for Mastodon { |
|
|
|
form = form.text("focus", format!("{},{}", x, y)); |
|
|
|
form = form.text("focus", format!("{},{}", x, y)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let response = self.send( |
|
|
|
let response = self.send(self.client.post(&self.route("/api/v1/media")).multipart(form))?; |
|
|
|
self.client |
|
|
|
|
|
|
|
.post(&self.route("/api/v1/media")) |
|
|
|
|
|
|
|
.multipart(form), |
|
|
|
|
|
|
|
)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
deserialise(response) |
|
|
|
deserialise(response) |
|
|
|
} |
|
|
|
} |
|
|
@ -774,23 +722,19 @@ impl<R: EventStream> EventReader<R> { |
|
|
|
let event: &str = &event; |
|
|
|
let event: &str = &event; |
|
|
|
Ok(match event { |
|
|
|
Ok(match event { |
|
|
|
"notification" => { |
|
|
|
"notification" => { |
|
|
|
let data = data.ok_or_else(|| { |
|
|
|
let data = data.ok_or_else(|| Error::Other("Missing `data` line for notification".to_string()))?; |
|
|
|
Error::Other("Missing `data` line for notification".to_string()) |
|
|
|
|
|
|
|
})?; |
|
|
|
|
|
|
|
let notification = serde_json::from_str::<Notification>(&data)?; |
|
|
|
let notification = serde_json::from_str::<Notification>(&data)?; |
|
|
|
Event::Notification(notification) |
|
|
|
Event::Notification(notification) |
|
|
|
}, |
|
|
|
} |
|
|
|
"update" => { |
|
|
|
"update" => { |
|
|
|
let data = |
|
|
|
let data = data.ok_or_else(|| Error::Other("Missing `data` line for update".to_string()))?; |
|
|
|
data.ok_or_else(|| Error::Other("Missing `data` line for update".to_string()))?; |
|
|
|
|
|
|
|
let status = serde_json::from_str::<Status>(&data)?; |
|
|
|
let status = serde_json::from_str::<Status>(&data)?; |
|
|
|
Event::Update(status) |
|
|
|
Event::Update(status) |
|
|
|
}, |
|
|
|
} |
|
|
|
"delete" => { |
|
|
|
"delete" => { |
|
|
|
let data = |
|
|
|
let data = data.ok_or_else(|| Error::Other("Missing `data` line for delete".to_string()))?; |
|
|
|
data.ok_or_else(|| Error::Other("Missing `data` line for delete".to_string()))?; |
|
|
|
|
|
|
|
Event::Delete(data) |
|
|
|
Event::Delete(data) |
|
|
|
}, |
|
|
|
} |
|
|
|
"filters_changed" => Event::FiltersChanged, |
|
|
|
"filters_changed" => Event::FiltersChanged, |
|
|
|
_ => return Err(Error::Other(format!("Unknown event `{}`", event))), |
|
|
|
_ => return Err(Error::Other(format!("Unknown event `{}`", event))), |
|
|
|
}) |
|
|
|
}) |
|
|
@ -876,10 +820,7 @@ impl MastodonUnauth { |
|
|
|
pub fn streaming_public(&self) -> Result<EventReader<WebSocket>> { |
|
|
|
pub fn streaming_public(&self) -> Result<EventReader<WebSocket>> { |
|
|
|
let mut url: url::Url = self.route("/api/v1/streaming/public/local")?; |
|
|
|
let mut url: url::Url = self.route("/api/v1/streaming/public/local")?; |
|
|
|
url.query_pairs_mut().append_pair("stream", "public"); |
|
|
|
url.query_pairs_mut().append_pair("stream", "public"); |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())? |
|
|
|
let mut url: url::Url = reqwest::blocking::get(url.as_str())?.url().as_str().parse()?; |
|
|
|
.url() |
|
|
|
|
|
|
|
.as_str() |
|
|
|
|
|
|
|
.parse()?; |
|
|
|
|
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
let new_scheme = match url.scheme() { |
|
|
|
"http" => "ws", |
|
|
|
"http" => "ws", |
|
|
|
"https" => "wss", |
|
|
|
"https" => "wss", |
|
|
@ -931,7 +872,7 @@ fn deserialise<T: for<'de> serde::Deserialize<'de>>(response: Response) -> Resul |
|
|
|
Ok(t) => { |
|
|
|
Ok(t) => { |
|
|
|
log::debug!("{}", String::from_utf8_lossy(&reader.bytes)); |
|
|
|
log::debug!("{}", String::from_utf8_lossy(&reader.bytes)); |
|
|
|
Ok(t) |
|
|
|
Ok(t) |
|
|
|
}, |
|
|
|
} |
|
|
|
// If deserializing into the desired type fails try again to
|
|
|
|
// If deserializing into the desired type fails try again to
|
|
|
|
// see if this is an error response.
|
|
|
|
// see if this is an error response.
|
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
@ -940,6 +881,6 @@ fn deserialise<T: for<'de> serde::Deserialize<'de>>(response: Response) -> Resul |
|
|
|
return Err(Error::Api(error)); |
|
|
|
return Err(Error::Api(error)); |
|
|
|
} |
|
|
|
} |
|
|
|
Err(e.into()) |
|
|
|
Err(e.into()) |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|