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 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);

View File

@@ -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 {

View File

@@ -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))?;

View File

@@ -1,14 +1,6 @@
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>,
@@ -73,44 +65,3 @@ 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)
}
}
*/

View File

@@ -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 {

View File

@@ -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;

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, 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/"), [
String::from("/teams/"),
self.self_info.clone().unwrap().team.unwrap(), self.self_info.clone().unwrap().team.unwrap(),
String::from("/members"),].concat() String::from("/members"),
]
.concat(),
)) ))
.await .await
.unwrap()); .unwrap(),
);
Ok(()) Ok(())
} }

View File

@@ -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)))?;