Clean dependencies

Delete useless dependencies in files
Sort dependencies
This commit is contained in:
CramMK
2020-01-15 14:59:02 +00:00
parent 49ceef2a7f
commit 8a5a129a87
8 changed files with 108 additions and 154 deletions

View File

@@ -1,12 +1,6 @@
use std::env;
use irssi_wire::net::wire_api::{
wire_client::WireClient,
auth::Config,
conversations::Conversations,
members::Members,
self_info::SelfInfo,
};
use irssi_wire::net::wire_api::{auth::Config, wire_client::WireClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -16,10 +10,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Config::Default,
);
let auth_response = client
.authentification()
.await
.unwrap();
let _auth_response = client.authentification().await.unwrap();
dbg!(client);

View File

@@ -24,7 +24,7 @@ use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions;
/// Generated files are compatible only with the same version
/// 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)]
pub struct GenericMessage {

View File

@@ -1,11 +1,11 @@
use hyper::body::Buf;
use hyper::client::connect::HttpConnector;
use hyper::{header, Body, Client, Method, Request};
use hyper_tls::HttpsConnector;
// Dependencies
use hyper::{
body::Buf,
{header, Body, Method, Request},
};
use serde::{Deserialize, Serialize};
use crate::net::wire_api::wire_client::{WireClient};
use crate::net::wire_api::error::ApiError;
use crate::net::wire_api::{error::ApiError, wire_client::WireClient};
#[derive(Debug, Clone)]
pub struct ConnectionUrls {
@@ -56,11 +56,11 @@ impl WireClient {
pub async fn authentification(&mut self) -> Result<(), ApiError> {
let endpoint = [
self.config.fetch().rest_url,
String::from("/login?persist=true")
].concat();
String::from("/login?persist=true"),
]
.concat();
let json = serde_json::to_string(&self.login_info)
.unwrap();
let json = serde_json::to_string(&self.login_info).unwrap();
let auth_request = Request::builder()
.method(Method::POST)
@@ -70,7 +70,8 @@ impl WireClient {
.body(Body::from(json))
.unwrap();
let auth_response = self.client
let auth_response = self
.client
.request(auth_request)
.await
.map_err(|e| ApiError::HttpError(e))?;

View File

@@ -1,116 +1,67 @@
use hyper::body::Buf;
use hyper::client::connect::HttpConnector;
use hyper::{header, Body, Client, Method, Request};
use hyper_tls::HttpsConnector;
// Dependencies
use serde::{Deserialize, Serialize};
use crate::net::wire_api::{
wire_client::WireClient,
auth::AuthResponse,
error::ApiError};
#[derive(Serialize, Deserialize, Debug)]
pub struct Conversations {
has_more: Option<bool>,
conversations: Option<Vec<Conversation>>,
has_more: Option<bool>,
conversations: Option<Vec<Conversation>>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Conversation {
access: Option<Access>,
creator: Option<String>,
access_role: Option<String>,
members: Option<ConversationMembers>,
name: Option<String>,
team: Option<String>,
id: Option<String>,
r#type: Option<u32>,
receipt_mode: Option<u32>,
last_event_time: String,
message_timer: Option<u32>,
last_event: Option<String>,
access: Option<Access>,
creator: Option<String>,
access_role: Option<String>,
members: Option<ConversationMembers>,
name: Option<String>,
team: Option<String>,
id: Option<String>,
r#type: Option<u32>,
receipt_mode: Option<u32>,
last_event_time: String,
message_timer: Option<u32>,
last_event: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Access {
#[serde(rename = "0")]
_0: Option<String>,
#[serde(rename = "0")]
_0: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ConversationMembers {
#[serde(rename = "self")]
self_: Option<Member>,
others: Option<Vec<OtherMember>>,
#[serde(rename = "self")]
self_: Option<Member>,
others: Option<Vec<OtherMember>>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Member {
hidden_ref: Option<String>,
stauts: Option<u32>,
service: Option<ServiceRef>,
otr_muted_ref: Option<String>,
conversation_role: Option<String>,
status_time: Option<String>,
hidden: Option<bool>,
status_ref: Option<String>,
id: Option<String>,
otr_archived: Option<bool>,
otr_muted_status: Option<String>,
otr_muted: Option<bool>,
otr_archived_ref: Option<String>,
hidden_ref: Option<String>,
stauts: Option<u32>,
service: Option<ServiceRef>,
otr_muted_ref: Option<String>,
conversation_role: Option<String>,
status_time: Option<String>,
hidden: Option<bool>,
status_ref: Option<String>,
id: Option<String>,
otr_archived: Option<bool>,
otr_muted_status: Option<String>,
otr_muted: Option<bool>,
otr_archived_ref: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct OtherMember {
status: Option<u32>,
conversation_role: Option<String>,
id: Option<String>,
status: Option<u32>,
conversation_role: Option<String>,
id: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ServiceRef {
id: String,
provider: String,
id: 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)
}
}
*/

View File

@@ -1,6 +1,5 @@
use serde::{Serialize, Deserialize};
use crate::net::wire_api::{error::ApiError};
// Dependencies
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Members {

View File

@@ -1,7 +1,7 @@
pub mod error;
pub mod wire_client;
pub mod auth;
pub mod self_info;
pub mod conversations;
pub mod members;
pub mod self_info;
pub mod wire_client;

View File

@@ -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;
use crate::net::wire_api::{error::ApiError, wire_client::WireClient};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SelfInfo {
@@ -26,32 +26,34 @@ pub struct UserAssets {
impl WireClient {
pub async fn fetch_self(&mut self) -> Result<(), ApiError> {
self.self_info = Some(self
.api_get(String::from("/self"))
.await
.unwrap());
self.self_info = Some(self.api_get(String::from("/self")).await.unwrap());
Ok(())
}
pub async fn fetch_conversations(&mut self) -> Result<(), ApiError> {
self.conversations = Some(self
.api_get(String::from("/conversations?size=500"))
.await
.unwrap());
self.conversations = Some(
self.api_get(String::from("/conversations?size=500"))
.await
.unwrap(),
);
Ok(())
}
pub async fn fetch_members(&mut self) -> Result<(), ApiError>{
self.members = Some(self
.api_get(String::from(
[String::from("/teams/"),
self.self_info.clone().unwrap().team.unwrap(),
String::from("/members"),].concat()
))
.await
.unwrap());
pub async fn fetch_members(&mut self) -> Result<(), ApiError> {
self.members = Some(
self.api_get(String::from(
[
String::from("/teams/"),
self.self_info.clone().unwrap().team.unwrap(),
String::from("/members"),
]
.concat(),
))
.await
.unwrap(),
);
Ok(())
}

View File

@@ -1,15 +1,13 @@
use hyper::body::Buf;
use hyper::{
client::connect::HttpConnector,
{header, Body, Client, Method, Request}};
// Dependencies
use hyper::{body::Buf, client::connect::HttpConnector, header, Body, Client, Method, Request};
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::{
self_info::SelfInfo,
auth::{AuthResponse, Config, LoginInfo},
conversations::Conversations,
error::ApiError,
members::Members,
self_info::SelfInfo,
};
#[derive(Debug)]
@@ -21,7 +19,7 @@ pub struct WireClient {
pub config: Config,
pub self_info: Option<SelfInfo>,
pub conversations: Option<Conversations>,
pub members: Option<Members>
pub members: Option<Members>,
}
impl WireClient {
@@ -42,18 +40,25 @@ impl WireClient {
pub async fn api_post<T>(
&mut self,
endpoint: String,
body_content: String) -> Result<T, ApiError>
where T: serde::de::DeserializeOwned {
body_content: String,
) -> Result<T, ApiError>
where
T: serde::de::DeserializeOwned,
{
let api_request = Request::builder()
.method(Method::POST)
.uri(endpoint)
.header(header::CONTENT_TYPE, "application/json")
.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))
.unwrap();
let api_response = self.client
let api_response = self
.client
.request(api_request)
.await
.map_err(|e| ApiError::HttpError(e))?;
@@ -68,26 +73,31 @@ impl WireClient {
Ok(parsed_json)
}
pub async fn api_get<T>(
&mut self,
endpoint: String) -> Result<T, ApiError>
where T: serde::de::DeserializeOwned {
pub async fn api_get<T>(&mut self, endpoint: String) -> Result<T, ApiError>
where
T: serde::de::DeserializeOwned,
{
let api_request = Request::builder()
.method(Method::GET)
.uri([self.config.fetch().rest_url, endpoint].concat())
.header(header::CONTENT_TYPE, "application/json")
.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())
.unwrap();
let api_response = self.client
let api_response = self
.client
.request(api_request)
.await
.map_err(|e| ApiError::HttpError(e))?;
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())
.map_err(|e| ApiError::JsonParseError(Box::new(e)))?;