Clean dependencies
Delete useless dependencies in files Sort dependencies
This commit is contained in:
@@ -1,12 +1,6 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use irssi_wire::net::wire_api::{
|
use irssi_wire::net::wire_api::{auth::Config, wire_client::WireClient};
|
||||||
wire_client::WireClient,
|
|
||||||
auth::Config,
|
|
||||||
conversations::Conversations,
|
|
||||||
members::Members,
|
|
||||||
self_info::SelfInfo,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
@@ -16,10 +10,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Config::Default,
|
Config::Default,
|
||||||
);
|
);
|
||||||
|
|
||||||
let auth_response = client
|
let _auth_response = client.authentification().await.unwrap();
|
||||||
.authentification()
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
dbg!(client);
|
dbg!(client);
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;
|
|||||||
|
|
||||||
/// Generated files are compatible only with the same version
|
/// Generated files are compatible only with the same version
|
||||||
/// of protobuf runtime.
|
/// of protobuf runtime.
|
||||||
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_0;
|
const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_10_1;
|
||||||
|
|
||||||
#[derive(PartialEq,Clone,Default)]
|
#[derive(PartialEq,Clone,Default)]
|
||||||
pub struct GenericMessage {
|
pub struct GenericMessage {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use hyper::body::Buf;
|
// Dependencies
|
||||||
use hyper::client::connect::HttpConnector;
|
use hyper::{
|
||||||
use hyper::{header, Body, Client, Method, Request};
|
body::Buf,
|
||||||
use hyper_tls::HttpsConnector;
|
{header, Body, Method, Request},
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::net::wire_api::wire_client::{WireClient};
|
use crate::net::wire_api::{error::ApiError, wire_client::WireClient};
|
||||||
use crate::net::wire_api::error::ApiError;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ConnectionUrls {
|
pub struct ConnectionUrls {
|
||||||
@@ -56,11 +56,11 @@ impl WireClient {
|
|||||||
pub async fn authentification(&mut self) -> Result<(), ApiError> {
|
pub async fn authentification(&mut self) -> Result<(), ApiError> {
|
||||||
let endpoint = [
|
let endpoint = [
|
||||||
self.config.fetch().rest_url,
|
self.config.fetch().rest_url,
|
||||||
String::from("/login?persist=true")
|
String::from("/login?persist=true"),
|
||||||
].concat();
|
]
|
||||||
|
.concat();
|
||||||
|
|
||||||
let json = serde_json::to_string(&self.login_info)
|
let json = serde_json::to_string(&self.login_info).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let auth_request = Request::builder()
|
let auth_request = Request::builder()
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
@@ -70,7 +70,8 @@ impl WireClient {
|
|||||||
.body(Body::from(json))
|
.body(Body::from(json))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let auth_response = self.client
|
let auth_response = self
|
||||||
|
.client
|
||||||
.request(auth_request)
|
.request(auth_request)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ApiError::HttpError(e))?;
|
.map_err(|e| ApiError::HttpError(e))?;
|
||||||
|
|||||||
@@ -1,116 +1,67 @@
|
|||||||
use hyper::body::Buf;
|
// Dependencies
|
||||||
use hyper::client::connect::HttpConnector;
|
|
||||||
use hyper::{header, Body, Client, Method, Request};
|
|
||||||
use hyper_tls::HttpsConnector;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::net::wire_api::{
|
|
||||||
wire_client::WireClient,
|
|
||||||
auth::AuthResponse,
|
|
||||||
error::ApiError};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Conversations {
|
pub struct Conversations {
|
||||||
has_more: Option<bool>,
|
has_more: Option<bool>,
|
||||||
conversations: Option<Vec<Conversation>>,
|
conversations: Option<Vec<Conversation>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Conversation {
|
pub struct Conversation {
|
||||||
access: Option<Access>,
|
access: Option<Access>,
|
||||||
creator: Option<String>,
|
creator: Option<String>,
|
||||||
access_role: Option<String>,
|
access_role: Option<String>,
|
||||||
members: Option<ConversationMembers>,
|
members: Option<ConversationMembers>,
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
team: Option<String>,
|
team: Option<String>,
|
||||||
id: Option<String>,
|
id: Option<String>,
|
||||||
r#type: Option<u32>,
|
r#type: Option<u32>,
|
||||||
receipt_mode: Option<u32>,
|
receipt_mode: Option<u32>,
|
||||||
last_event_time: String,
|
last_event_time: String,
|
||||||
message_timer: Option<u32>,
|
message_timer: Option<u32>,
|
||||||
last_event: Option<String>,
|
last_event: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Access {
|
pub struct Access {
|
||||||
#[serde(rename = "0")]
|
#[serde(rename = "0")]
|
||||||
_0: Option<String>,
|
_0: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct ConversationMembers {
|
pub struct ConversationMembers {
|
||||||
#[serde(rename = "self")]
|
#[serde(rename = "self")]
|
||||||
self_: Option<Member>,
|
self_: Option<Member>,
|
||||||
others: Option<Vec<OtherMember>>,
|
others: Option<Vec<OtherMember>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Member {
|
pub struct Member {
|
||||||
hidden_ref: Option<String>,
|
hidden_ref: Option<String>,
|
||||||
stauts: Option<u32>,
|
stauts: Option<u32>,
|
||||||
service: Option<ServiceRef>,
|
service: Option<ServiceRef>,
|
||||||
otr_muted_ref: Option<String>,
|
otr_muted_ref: Option<String>,
|
||||||
conversation_role: Option<String>,
|
conversation_role: Option<String>,
|
||||||
status_time: Option<String>,
|
status_time: Option<String>,
|
||||||
hidden: Option<bool>,
|
hidden: Option<bool>,
|
||||||
status_ref: Option<String>,
|
status_ref: Option<String>,
|
||||||
id: Option<String>,
|
id: Option<String>,
|
||||||
otr_archived: Option<bool>,
|
otr_archived: Option<bool>,
|
||||||
otr_muted_status: Option<String>,
|
otr_muted_status: Option<String>,
|
||||||
otr_muted: Option<bool>,
|
otr_muted: Option<bool>,
|
||||||
otr_archived_ref: Option<String>,
|
otr_archived_ref: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct OtherMember {
|
pub struct OtherMember {
|
||||||
status: Option<u32>,
|
status: Option<u32>,
|
||||||
conversation_role: Option<String>,
|
conversation_role: Option<String>,
|
||||||
id: Option<String>,
|
id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct ServiceRef {
|
pub struct ServiceRef {
|
||||||
id: String,
|
id: String,
|
||||||
provider: String,
|
provider: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO delete this
|
|
||||||
/*
|
|
||||||
impl WireClient {
|
|
||||||
pub async fn fetch_conversations(
|
|
||||||
&mut self,
|
|
||||||
auth_response: &AuthResponse,
|
|
||||||
) -> Result<Conversations, ApiError> {
|
|
||||||
let endpoint = [
|
|
||||||
self.config.fetch().rest_url,
|
|
||||||
String::from("/conversations?size=500"),
|
|
||||||
]
|
|
||||||
.concat();
|
|
||||||
let auth_token = auth_response.token_string();
|
|
||||||
|
|
||||||
let fetch_request = Request::builder()
|
|
||||||
.method(Method::GET)
|
|
||||||
.uri(endpoint)
|
|
||||||
.header(header::CONTENT_TYPE, "application/json")
|
|
||||||
.header(header::USER_AGENT, self.user_agent)
|
|
||||||
.header(header::AUTHORIZATION, auth_token)
|
|
||||||
.body(Body::empty())
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let fetch_result = self
|
|
||||||
.client
|
|
||||||
.request(fetch_request)
|
|
||||||
.await
|
|
||||||
.map_err(|e| ApiError::HttpError(e))?;
|
|
||||||
|
|
||||||
let fetch_body = hyper::body::aggregate(fetch_result)
|
|
||||||
.await
|
|
||||||
.map_err(|e| ApiError::HttpError(e))?;
|
|
||||||
|
|
||||||
let fetch_response = serde_json::from_reader(fetch_body.bytes())
|
|
||||||
.map_err(|e| ApiError::JsonParseError(Box::new(e)))?;
|
|
||||||
|
|
||||||
Ok(fetch_response)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
// Dependencies
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use crate::net::wire_api::{error::ApiError};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct Members {
|
pub struct Members {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pub mod error;
|
pub mod error;
|
||||||
|
|
||||||
pub mod wire_client;
|
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod self_info;
|
|
||||||
pub mod conversations;
|
pub mod conversations;
|
||||||
pub mod members;
|
pub mod members;
|
||||||
|
pub mod self_info;
|
||||||
|
pub mod wire_client;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
// Dependencies
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::net::wire_api::wire_client::WireClient;
|
use crate::net::wire_api::{error::ApiError, wire_client::WireClient};
|
||||||
use crate::net::wire_api::error::ApiError;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct SelfInfo {
|
pub struct SelfInfo {
|
||||||
@@ -26,32 +26,34 @@ pub struct UserAssets {
|
|||||||
|
|
||||||
impl WireClient {
|
impl WireClient {
|
||||||
pub async fn fetch_self(&mut self) -> Result<(), ApiError> {
|
pub async fn fetch_self(&mut self) -> Result<(), ApiError> {
|
||||||
self.self_info = Some(self
|
self.self_info = Some(self.api_get(String::from("/self")).await.unwrap());
|
||||||
.api_get(String::from("/self"))
|
|
||||||
.await
|
|
||||||
.unwrap());
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_conversations(&mut self) -> Result<(), ApiError> {
|
pub async fn fetch_conversations(&mut self) -> Result<(), ApiError> {
|
||||||
self.conversations = Some(self
|
self.conversations = Some(
|
||||||
.api_get(String::from("/conversations?size=500"))
|
self.api_get(String::from("/conversations?size=500"))
|
||||||
.await
|
.await
|
||||||
.unwrap());
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_members(&mut self) -> Result<(), ApiError>{
|
pub async fn fetch_members(&mut self) -> Result<(), ApiError> {
|
||||||
self.members = Some(self
|
self.members = Some(
|
||||||
.api_get(String::from(
|
self.api_get(String::from(
|
||||||
[String::from("/teams/"),
|
[
|
||||||
self.self_info.clone().unwrap().team.unwrap(),
|
String::from("/teams/"),
|
||||||
String::from("/members"),].concat()
|
self.self_info.clone().unwrap().team.unwrap(),
|
||||||
))
|
String::from("/members"),
|
||||||
.await
|
]
|
||||||
.unwrap());
|
.concat(),
|
||||||
|
))
|
||||||
|
.await
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
use hyper::body::Buf;
|
// Dependencies
|
||||||
use hyper::{
|
use hyper::{body::Buf, client::connect::HttpConnector, header, Body, Client, Method, Request};
|
||||||
client::connect::HttpConnector,
|
|
||||||
{header, Body, Client, Method, Request}};
|
|
||||||
use hyper_tls::HttpsConnector;
|
use hyper_tls::HttpsConnector;
|
||||||
|
|
||||||
use crate::net::wire_api::error::ApiError;
|
|
||||||
use crate::net::wire_api::auth::{LoginInfo, AuthResponse, Config};
|
|
||||||
use crate::net::wire_api::{
|
use crate::net::wire_api::{
|
||||||
self_info::SelfInfo,
|
auth::{AuthResponse, Config, LoginInfo},
|
||||||
conversations::Conversations,
|
conversations::Conversations,
|
||||||
|
error::ApiError,
|
||||||
members::Members,
|
members::Members,
|
||||||
|
self_info::SelfInfo,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -21,7 +19,7 @@ pub struct WireClient {
|
|||||||
pub config: Config,
|
pub config: Config,
|
||||||
pub self_info: Option<SelfInfo>,
|
pub self_info: Option<SelfInfo>,
|
||||||
pub conversations: Option<Conversations>,
|
pub conversations: Option<Conversations>,
|
||||||
pub members: Option<Members>
|
pub members: Option<Members>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WireClient {
|
impl WireClient {
|
||||||
@@ -42,18 +40,25 @@ impl WireClient {
|
|||||||
pub async fn api_post<T>(
|
pub async fn api_post<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
endpoint: String,
|
endpoint: String,
|
||||||
body_content: String) -> Result<T, ApiError>
|
body_content: String,
|
||||||
where T: serde::de::DeserializeOwned {
|
) -> Result<T, ApiError>
|
||||||
|
where
|
||||||
|
T: serde::de::DeserializeOwned,
|
||||||
|
{
|
||||||
let api_request = Request::builder()
|
let api_request = Request::builder()
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
.uri(endpoint)
|
.uri(endpoint)
|
||||||
.header(header::CONTENT_TYPE, "application/json")
|
.header(header::CONTENT_TYPE, "application/json")
|
||||||
.header(header::USER_AGENT, &self.user_agent)
|
.header(header::USER_AGENT, &self.user_agent)
|
||||||
.header(header::AUTHORIZATION, self.auth_token.as_ref().unwrap().token_string())
|
.header(
|
||||||
|
header::AUTHORIZATION,
|
||||||
|
self.auth_token.as_ref().unwrap().token_string(),
|
||||||
|
)
|
||||||
.body(Body::from(body_content))
|
.body(Body::from(body_content))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let api_response = self.client
|
let api_response = self
|
||||||
|
.client
|
||||||
.request(api_request)
|
.request(api_request)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ApiError::HttpError(e))?;
|
.map_err(|e| ApiError::HttpError(e))?;
|
||||||
@@ -68,26 +73,31 @@ impl WireClient {
|
|||||||
Ok(parsed_json)
|
Ok(parsed_json)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn api_get<T>(
|
pub async fn api_get<T>(&mut self, endpoint: String) -> Result<T, ApiError>
|
||||||
&mut self,
|
where
|
||||||
endpoint: String) -> Result<T, ApiError>
|
T: serde::de::DeserializeOwned,
|
||||||
where T: serde::de::DeserializeOwned {
|
{
|
||||||
let api_request = Request::builder()
|
let api_request = Request::builder()
|
||||||
.method(Method::GET)
|
.method(Method::GET)
|
||||||
.uri([self.config.fetch().rest_url, endpoint].concat())
|
.uri([self.config.fetch().rest_url, endpoint].concat())
|
||||||
.header(header::CONTENT_TYPE, "application/json")
|
.header(header::CONTENT_TYPE, "application/json")
|
||||||
.header(header::USER_AGENT, &self.user_agent)
|
.header(header::USER_AGENT, &self.user_agent)
|
||||||
.header(header::AUTHORIZATION, self.auth_token.as_ref().unwrap().token_string())
|
.header(
|
||||||
|
header::AUTHORIZATION,
|
||||||
|
self.auth_token.as_ref().unwrap().token_string(),
|
||||||
|
)
|
||||||
.body(Body::empty())
|
.body(Body::empty())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let api_response = self.client
|
let api_response = self
|
||||||
|
.client
|
||||||
.request(api_request)
|
.request(api_request)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ApiError::HttpError(e))?;
|
.map_err(|e| ApiError::HttpError(e))?;
|
||||||
|
|
||||||
let body = hyper::body::aggregate(api_response)
|
let body = hyper::body::aggregate(api_response)
|
||||||
.await.map_err(|e| ApiError::HttpError(e))?;
|
.await
|
||||||
|
.map_err(|e| ApiError::HttpError(e))?;
|
||||||
|
|
||||||
let parsed_json = serde_json::from_reader(body.bytes())
|
let parsed_json = serde_json::from_reader(body.bytes())
|
||||||
.map_err(|e| ApiError::JsonParseError(Box::new(e)))?;
|
.map_err(|e| ApiError::JsonParseError(Box::new(e)))?;
|
||||||
|
|||||||
Reference in New Issue
Block a user