rename all crates to add prefix socialvoid_
This commit is contained in:
parent
28448a715f
commit
9ae31ee544
|
@ -104,30 +104,17 @@ dependencies = [
|
|||
name = "cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"client",
|
||||
"rawclient",
|
||||
"rpassword",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"session",
|
||||
"shellexpand",
|
||||
"socialvoid",
|
||||
"socialvoid_rawclient",
|
||||
"socialvoid_session",
|
||||
"structopt",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "client"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"help",
|
||||
"network",
|
||||
"rawclient",
|
||||
"serde_json",
|
||||
"session",
|
||||
"tokio",
|
||||
"types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.1"
|
||||
|
@ -393,17 +380,6 @@ dependencies = [
|
|||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "help"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rawclient",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
|
@ -650,17 +626,6 @@ dependencies = [
|
|||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "network"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rawclient",
|
||||
"serde_json",
|
||||
"session",
|
||||
"tokio",
|
||||
"types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.3.6"
|
||||
|
@ -939,21 +904,6 @@ dependencies = [
|
|||
"rand_core 0.6.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rawclient"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"enum_primitive",
|
||||
"futures",
|
||||
"jsonrpc2-client",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rdrand"
|
||||
version = "0.4.0"
|
||||
|
@ -1144,23 +1094,6 @@ dependencies = [
|
|||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "session"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base32",
|
||||
"byteorder",
|
||||
"pad",
|
||||
"rand 0.8.4",
|
||||
"rawclient",
|
||||
"rust-crypto",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha256",
|
||||
"tokio",
|
||||
"types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.9.8"
|
||||
|
@ -1214,6 +1147,82 @@ version = "1.6.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
|
||||
|
||||
[[package]]
|
||||
name = "socialvoid"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde_json",
|
||||
"socialvoid_help",
|
||||
"socialvoid_network",
|
||||
"socialvoid_rawclient",
|
||||
"socialvoid_session",
|
||||
"socialvoid_types",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socialvoid_help"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"socialvoid_rawclient",
|
||||
"socialvoid_types",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socialvoid_network"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde_json",
|
||||
"socialvoid_rawclient",
|
||||
"socialvoid_session",
|
||||
"socialvoid_types",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socialvoid_rawclient"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"enum_primitive",
|
||||
"futures",
|
||||
"jsonrpc2-client",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"socialvoid_types",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socialvoid_session"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"base32",
|
||||
"byteorder",
|
||||
"pad",
|
||||
"rand 0.8.4",
|
||||
"rust-crypto",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha256",
|
||||
"socialvoid_rawclient",
|
||||
"socialvoid_types",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socialvoid_types"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.4.1"
|
||||
|
@ -1406,15 +1415,6 @@ version = "1.14.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
|
||||
|
||||
[[package]]
|
||||
name = "types"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.6.0"
|
||||
|
|
|
@ -10,9 +10,9 @@ name = "socialvoid-cli"
|
|||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
"client" = { path = "../client" }
|
||||
"rawclient" = { path = "../rawclient" }
|
||||
"session" = { path = "../session" }
|
||||
"socialvoid" = { path = "../client" }
|
||||
"socialvoid_rawclient" = { path = "../rawclient" }
|
||||
"socialvoid_session" = { path = "../session" }
|
||||
structopt = "0.3.23"
|
||||
serde = { version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0.67"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use client as sv_client;
|
||||
use session::RegisterRequest;
|
||||
use socialvoid as sv_client;
|
||||
use socialvoid_session::RegisterRequest;
|
||||
use structopt::StructOpt;
|
||||
|
||||
mod utils;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use client as sv_client;
|
||||
use rawclient::{AuthenticationError, ErrorKind};
|
||||
use rpassword::read_password;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use socialvoid as sv_client;
|
||||
use socialvoid_rawclient::{AuthenticationError, ErrorKind};
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
[package]
|
||||
name = "client"
|
||||
name = "socialvoid"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
network = {path = "../network"}
|
||||
session = {path = "../session"}
|
||||
rawclient = {path = "../rawclient"}
|
||||
socialvoid_network = {path = "../network"}
|
||||
socialvoid_session = {path = "../session"}
|
||||
socialvoid_rawclient = {path = "../rawclient"}
|
||||
tokio = {version = "1.11.0", features = ["full"]}
|
||||
types = {path = "../types"}
|
||||
help = {path = "../help"}
|
||||
socialvoid_types = {path = "../types"}
|
||||
socialvoid_help = {path = "../help"}
|
||||
serde_json = "1.0.67"
|
|
@ -1,14 +1,14 @@
|
|||
use rawclient::Error;
|
||||
use session::ClientInfo;
|
||||
use session::RegisterRequest;
|
||||
use session::Session;
|
||||
use session::SessionHolder;
|
||||
use types::HelpDocument;
|
||||
use types::Peer;
|
||||
use socialvoid_rawclient::Error;
|
||||
use socialvoid_session::ClientInfo;
|
||||
use socialvoid_session::RegisterRequest;
|
||||
use socialvoid_session::Session;
|
||||
use socialvoid_session::SessionHolder;
|
||||
use socialvoid_types::HelpDocument;
|
||||
use socialvoid_types::Peer;
|
||||
|
||||
/// Create a client and establish a new session
|
||||
pub async fn new_with_defaults() -> Result<Client, Error> {
|
||||
let rpc_client = rawclient::new();
|
||||
let rpc_client = socialvoid_rawclient::new();
|
||||
let cdn_client = make_cdn_client_from(&rpc_client).await?;
|
||||
let client_info = ClientInfo::generate();
|
||||
let mut session = SessionHolder::new(client_info.clone());
|
||||
|
@ -25,18 +25,20 @@ pub async fn new_with_defaults() -> Result<Client, Error> {
|
|||
|
||||
/// Creates the CDN client by resolving the host url from server information
|
||||
async fn make_cdn_client_from(
|
||||
rpc_client: &rawclient::Client,
|
||||
) -> Result<rawclient::CdnClient, Error> {
|
||||
let server_info = help::get_server_information(&rpc_client).await?;
|
||||
rpc_client: &socialvoid_rawclient::Client,
|
||||
) -> Result<socialvoid_rawclient::CdnClient, Error> {
|
||||
let server_info = socialvoid_help::get_server_information(&rpc_client).await?;
|
||||
|
||||
Ok(rawclient::CdnClient::with_cdn_url(server_info.cdn_server))
|
||||
Ok(socialvoid_rawclient::CdnClient::with_cdn_url(
|
||||
server_info.cdn_server,
|
||||
))
|
||||
}
|
||||
|
||||
/// Create a client with user defined client info and sessions
|
||||
/// And CDN as gven in the server information
|
||||
/// TODO: maybe verify the session and return an error if session is invalid
|
||||
pub async fn new(client_info: ClientInfo, sessions: Vec<SessionHolder>) -> Result<Client, Error> {
|
||||
let rpc_client = rawclient::new();
|
||||
let rpc_client = socialvoid_rawclient::new();
|
||||
let cdn_client = make_cdn_client_from(&rpc_client).await?;
|
||||
Ok(Client {
|
||||
sessions,
|
||||
|
@ -52,8 +54,8 @@ pub fn new_empty_client() -> Client {
|
|||
Client {
|
||||
sessions: Vec::new(),
|
||||
client_info: ClientInfo::generate(),
|
||||
rpc_client: rawclient::new(),
|
||||
cdn_client: rawclient::CdnClient::new(),
|
||||
rpc_client: socialvoid_rawclient::new(),
|
||||
cdn_client: socialvoid_rawclient::CdnClient::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,8 +63,8 @@ pub fn new_empty_client() -> Client {
|
|||
pub struct Client {
|
||||
pub sessions: Vec<SessionHolder>,
|
||||
client_info: ClientInfo,
|
||||
rpc_client: rawclient::Client,
|
||||
cdn_client: rawclient::CdnClient,
|
||||
rpc_client: socialvoid_rawclient::Client,
|
||||
cdn_client: socialvoid_rawclient::CdnClient,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
|
@ -107,7 +109,7 @@ impl Client {
|
|||
|
||||
/// Get terms of service
|
||||
pub async fn get_terms_of_service(&self) -> Result<HelpDocument, Error> {
|
||||
help::get_terms_of_service(&self.rpc_client).await
|
||||
socialvoid_help::get_terms_of_service(&self.rpc_client).await
|
||||
}
|
||||
|
||||
/// Accept terms of service for a specific session
|
||||
|
@ -150,7 +152,7 @@ impl Client {
|
|||
}
|
||||
|
||||
pub async fn get_me(&self, session_key: usize) -> Result<Peer, Error> {
|
||||
network::get_me(
|
||||
socialvoid_network::get_me(
|
||||
&self.rpc_client,
|
||||
self.sessions[session_key].session_identification()?,
|
||||
)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
[package]
|
||||
name = "help"
|
||||
name = "socialvoid_help"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rawclient = {path = "../rawclient"}
|
||||
types = {path = "../types"}
|
||||
socialvoid_rawclient = {path = "../rawclient"}
|
||||
socialvoid_types = {path = "../types"}
|
||||
serde = { version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0.67"
|
||||
tokio = {version = "1.11.0", features = ["rt"]}
|
|
@ -1,30 +1,36 @@
|
|||
use rawclient::Error;
|
||||
use types::{HelpDocument, ServerInformation};
|
||||
use socialvoid_rawclient::Error;
|
||||
use socialvoid_types::{HelpDocument, ServerInformation};
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_json;
|
||||
|
||||
pub async fn get_community_guidelines(client: &rawclient::Client) -> Result<HelpDocument, Error> {
|
||||
pub async fn get_community_guidelines(
|
||||
client: &socialvoid_rawclient::Client,
|
||||
) -> Result<HelpDocument, Error> {
|
||||
client
|
||||
.send_request("help.get_community_guidelines", json!(null))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_privacy_policy(client: &rawclient::Client) -> Result<HelpDocument, Error> {
|
||||
pub async fn get_privacy_policy(
|
||||
client: &socialvoid_rawclient::Client,
|
||||
) -> Result<HelpDocument, Error> {
|
||||
client
|
||||
.send_request("help.get_privacy_policy", json!(null))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_server_information(
|
||||
client: &rawclient::Client,
|
||||
client: &socialvoid_rawclient::Client,
|
||||
) -> Result<ServerInformation, Error> {
|
||||
client
|
||||
.send_request("help.get_server_information", json!(null))
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_terms_of_service(client: &rawclient::Client) -> Result<HelpDocument, Error> {
|
||||
pub async fn get_terms_of_service(
|
||||
client: &socialvoid_rawclient::Client,
|
||||
) -> Result<HelpDocument, Error> {
|
||||
client
|
||||
.send_request("help.get_terms_of_service", json!(null))
|
||||
.await
|
||||
|
@ -36,7 +42,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
pub async fn save_all_documents() {
|
||||
use std::fs::File;
|
||||
let client = rawclient::new();
|
||||
let client = socialvoid_rawclient::new();
|
||||
serde_json::to_writer(
|
||||
&File::create("community_guidelines.json.test").unwrap(),
|
||||
&get_community_guidelines(&client).await.unwrap(),
|
||||
|
|
|
@ -37,21 +37,23 @@ impl Client {
|
|||
) -> Result<T, RpcError> {
|
||||
let request = RawRequest::new(Some(generate_id()), method.to_string(), Some(params));
|
||||
|
||||
println!(
|
||||
dbg!(
|
||||
"Request: {}",
|
||||
serde_json::to_string_pretty(&request).unwrap()
|
||||
);
|
||||
|
||||
//TODO: maybe check the response better as well??
|
||||
let resp = self
|
||||
let resp: serde_json::Value = self
|
||||
.client
|
||||
.post(&self.host_url)
|
||||
.json(&request)
|
||||
.send()
|
||||
.await?
|
||||
.json::<RawResponse<T>>()
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
dbg!("{}", serde_json::to_string_pretty(&resp).unwrap());
|
||||
let resp: RawResponse<T> = serde_json::value::from_value(resp).unwrap();
|
||||
resp.result()
|
||||
}
|
||||
|
||||
|
@ -63,7 +65,7 @@ impl Client {
|
|||
) -> Result<(), RpcError> {
|
||||
let request = RawRequest::new(None, method.to_string(), Some(params));
|
||||
|
||||
println!(
|
||||
dbg!(
|
||||
"Request: {}",
|
||||
serde_json::to_string_pretty(&request).unwrap()
|
||||
);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
[package]
|
||||
name = "network"
|
||||
name = "socialvoid_network"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rawclient = {path = "../rawclient"}
|
||||
session = {path = "../session"}
|
||||
types = {path = "../types"}
|
||||
socialvoid_rawclient = {path = "../rawclient"}
|
||||
socialvoid_session = {path = "../session"}
|
||||
socialvoid_types = {path = "../types"}
|
||||
tokio = {version = "1.11.0", features = ["full"]}
|
||||
serde_json = "1.0.67"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use rawclient::Error;
|
||||
use serde_json::json;
|
||||
use types::Peer;
|
||||
use types::SessionIdentification;
|
||||
use socialvoid_rawclient as rawclient;
|
||||
use socialvoid_rawclient::Error;
|
||||
use socialvoid_types::Peer;
|
||||
use socialvoid_types::SessionIdentification;
|
||||
|
||||
pub async fn get_me(
|
||||
client: &rawclient::Client,
|
||||
|
@ -21,7 +22,7 @@ pub async fn get_me(
|
|||
mod tests {
|
||||
use super::*;
|
||||
use rawclient::{AuthenticationError, ErrorKind};
|
||||
use session::{ClientInfo, SessionHolder};
|
||||
use socialvoid_session::{ClientInfo, SessionHolder};
|
||||
#[tokio::test]
|
||||
async fn it_should_return_a_session_not_found_error_if_session_unauthenticated() {
|
||||
let client = rawclient::new();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "rawclient"
|
||||
name = "socialvoid_rawclient"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
|
@ -7,7 +7,7 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
jsonrpc2-client = {path = "../jsonrpc2-client"}
|
||||
types = {path = "../types" }
|
||||
socialvoid_types = {path = "../types" }
|
||||
serde = { version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0.67"
|
||||
enum_primitive = "0.1.1"
|
||||
|
|
|
@ -17,8 +17,8 @@ pub use error::errors::ClientError;
|
|||
pub use error::Error;
|
||||
pub use error::ErrorKind;
|
||||
|
||||
use types::Document;
|
||||
use types::SessionIdentification;
|
||||
use socialvoid_types::Document;
|
||||
use socialvoid_types::SessionIdentification;
|
||||
|
||||
use reqwest::multipart::Part;
|
||||
use reqwest::Body;
|
||||
|
@ -71,7 +71,7 @@ impl CdnClient {
|
|||
|
||||
pub async fn upload(
|
||||
&self,
|
||||
session_identificatin: SessionIdentification,
|
||||
session_identification: SessionIdentification,
|
||||
file_path: String,
|
||||
) -> Result<Document, Error> {
|
||||
// let mut file_bytes = vec![];
|
||||
|
@ -85,11 +85,12 @@ impl CdnClient {
|
|||
// .part("document", Part::bytes(file_bytes).file_name(file_path))
|
||||
.text(
|
||||
"client_public_hash",
|
||||
session_identificatin.client_public_hash, //remove the clonse
|
||||
session_identification.client_public_hash,
|
||||
)
|
||||
.text("session_id", session_identificatin.session_id)
|
||||
.text("challenge_answer", session_identificatin.challenge_answer)
|
||||
.text("session_id", session_identification.session_id)
|
||||
.text("challenge_answer", session_identification.challenge_answer)
|
||||
.text("action", "upload");
|
||||
|
||||
let resp: CdnResponse<Document> = self
|
||||
.client
|
||||
.post(&self.host_url)
|
||||
|
@ -103,17 +104,17 @@ impl CdnClient {
|
|||
|
||||
pub async fn download(
|
||||
&self,
|
||||
session_identificatin: SessionIdentification,
|
||||
session_identification: SessionIdentification,
|
||||
document_id: String,
|
||||
) -> Result<Vec<u8>, Error> {
|
||||
let form = reqwest::multipart::Form::new()
|
||||
.text("document", document_id)
|
||||
.text(
|
||||
"client_public_hash",
|
||||
session_identificatin.client_public_hash, //remove the clonse
|
||||
session_identification.client_public_hash, //remove the clonse
|
||||
)
|
||||
.text("session_id", session_identificatin.session_id)
|
||||
.text("challenge_answer", session_identificatin.challenge_answer)
|
||||
.text("session_id", session_identification.session_id)
|
||||
.text("challenge_answer", session_identification.challenge_answer)
|
||||
.text("action", "download");
|
||||
|
||||
let response = self
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
[package]
|
||||
name = "session"
|
||||
name = "socialvoid_session"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rawclient = {path = "../rawclient"}
|
||||
types = {path = "../types"}
|
||||
socialvoid_rawclient = {path = "../rawclient"}
|
||||
socialvoid_types = {path = "../types"}
|
||||
serde = { version = "1.0", features = ["derive"]}
|
||||
serde_json = "1.0.67"
|
||||
sha256 = "1.0.2"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use super::ClientInfo;
|
||||
use rawclient::ClientError;
|
||||
use rawclient::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use types::Document;
|
||||
pub use types::HelpDocument;
|
||||
use types::Peer;
|
||||
use types::SessionIdentification;
|
||||
use socialvoid_rawclient::ClientError;
|
||||
use socialvoid_rawclient::Error;
|
||||
use socialvoid_types::Document;
|
||||
pub use socialvoid_types::HelpDocument;
|
||||
use socialvoid_types::Peer;
|
||||
use socialvoid_types::SessionIdentification;
|
||||
|
||||
use super::session_challenge::answer_challenge;
|
||||
|
||||
|
@ -46,7 +46,7 @@ impl SessionHolder {
|
|||
/// Creates a session and sets a session established object which contains a challenge.
|
||||
/// A session object is not yet returned - the challenge needs to be solved and sent inside a session identification
|
||||
/// object using the `get_session` method to get the Session object.
|
||||
pub async fn create(&mut self, rpc_client: &rawclient::Client) -> Result<(), Error> {
|
||||
pub async fn create(&mut self, rpc_client: &socialvoid_rawclient::Client) -> Result<(), Error> {
|
||||
let client_info = &self.client_info;
|
||||
self.established = Some(
|
||||
rpc_client
|
||||
|
@ -58,7 +58,10 @@ impl SessionHolder {
|
|||
|
||||
/// `session.get`
|
||||
/// Returns a `Session`
|
||||
pub async fn get(&mut self, rpc_client: &rawclient::Client) -> Result<Session, Error> {
|
||||
pub async fn get(
|
||||
&mut self,
|
||||
rpc_client: &socialvoid_rawclient::Client,
|
||||
) -> Result<Session, Error> {
|
||||
let session_identification = self.session_identification()?;
|
||||
let sesh: Session = rpc_client
|
||||
.send_request(
|
||||
|
@ -74,7 +77,7 @@ impl SessionHolder {
|
|||
/// Authenticates a user via a username & password and optionally an OTP - extends session expiration time
|
||||
pub async fn authenticate_user(
|
||||
&mut self,
|
||||
rpc_client: &rawclient::Client,
|
||||
rpc_client: &socialvoid_rawclient::Client,
|
||||
username: String,
|
||||
password: String,
|
||||
otp: Option<String>,
|
||||
|
@ -97,7 +100,10 @@ impl SessionHolder {
|
|||
|
||||
/// `session.logout`
|
||||
/// Log out without destroying the session - changes the session expiration date too
|
||||
pub async fn logout(&mut self, rpc_client: &rawclient::Client) -> Result<bool, Error> {
|
||||
pub async fn logout(
|
||||
&mut self,
|
||||
rpc_client: &socialvoid_rawclient::Client,
|
||||
) -> Result<bool, Error> {
|
||||
let session_identification = self.session_identification()?;
|
||||
let response = rpc_client
|
||||
.send_request(
|
||||
|
@ -114,7 +120,7 @@ impl SessionHolder {
|
|||
pub async fn register(
|
||||
&mut self,
|
||||
request: RegisterRequest,
|
||||
rpc_client: &rawclient::Client,
|
||||
rpc_client: &socialvoid_rawclient::Client,
|
||||
) -> Result<Peer, Error> {
|
||||
let session_identification = self.session_identification()?;
|
||||
|
||||
|
@ -140,7 +146,7 @@ impl SessionHolder {
|
|||
pub async fn upload_file(
|
||||
&self,
|
||||
file: &str,
|
||||
cdn_client: &rawclient::CdnClient,
|
||||
cdn_client: &socialvoid_rawclient::CdnClient,
|
||||
) -> Result<Document, Error> {
|
||||
let session_identification = self.session_identification()?;
|
||||
cdn_client
|
||||
|
@ -152,7 +158,7 @@ impl SessionHolder {
|
|||
pub async fn download_file(
|
||||
&self,
|
||||
document_id: String,
|
||||
cdn_client: &rawclient::CdnClient,
|
||||
cdn_client: &socialvoid_rawclient::CdnClient,
|
||||
) -> Result<Vec<u8>, Error> {
|
||||
let session_identification = self.session_identification()?;
|
||||
cdn_client
|
||||
|
@ -162,7 +168,7 @@ impl SessionHolder {
|
|||
|
||||
/// Accepts the terms of service
|
||||
/// The client must explicitly call `session.accept_terms_of_service(terms_of_service)` to
|
||||
/// accept the terms of service. The HelpDocument can be acquired via `help::get_terms_of_service(rawclient)`
|
||||
/// accept the terms of service. The HelpDocument can be acquired via `help::get_terms_of_service(socialvoid_rawclient)`
|
||||
pub fn accept_terms_of_service(&mut self, tos: HelpDocument) {
|
||||
self.tos_read = Some(tos.id);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ mod tests {
|
|||
let client_info = ClientInfo::generate();
|
||||
let private_hash = client_info.private_hash.clone();
|
||||
let mut session = SessionHolder::new(client_info);
|
||||
let client = rawclient::new();
|
||||
let client = socialvoid_rawclient::new();
|
||||
session
|
||||
.create(&client)
|
||||
.await
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod entities;
|
||||
|
||||
extern crate rawclient;
|
||||
extern crate socialvoid_rawclient;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_json;
|
||||
|
@ -17,11 +17,11 @@ mod tests {
|
|||
use entities::RegisterRequest;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use rand::{thread_rng, Rng};
|
||||
use rawclient::{ClientError, Error, ErrorKind};
|
||||
use socialvoid_rawclient::{ClientError, Error, ErrorKind};
|
||||
#[tokio::test]
|
||||
async fn it_should_establish_a_session_and_get_it() -> Result<(), Error> {
|
||||
let mut session = SessionHolder::new(ClientInfo::generate());
|
||||
let client = rawclient::new();
|
||||
let client = socialvoid_rawclient::new();
|
||||
session.create(&client).await?;
|
||||
|
||||
let sesh = session.get(&client).await?;
|
||||
|
@ -34,7 +34,7 @@ mod tests {
|
|||
let creds: serde_json::Value =
|
||||
serde_json::from_str(&std::fs::read_to_string("../client/test_creds.test").unwrap())?;
|
||||
let mut session = SessionHolder::new(ClientInfo::generate());
|
||||
let client = rawclient::new();
|
||||
let client = socialvoid_rawclient::new();
|
||||
session.create(&client).await?;
|
||||
|
||||
assert_eq!(
|
||||
|
@ -56,7 +56,7 @@ mod tests {
|
|||
.map(char::from)
|
||||
.collect();
|
||||
std::fs::write(file_name, file_content.clone()).unwrap();
|
||||
let cdn_client = rawclient::CdnClient::new();
|
||||
let cdn_client = socialvoid_rawclient::CdnClient::new();
|
||||
let document = session.upload_file(file_name, &cdn_client).await?;
|
||||
println!("Document: {:#?}", document);
|
||||
std::fs::remove_file(file_name).unwrap();
|
||||
|
@ -84,7 +84,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn it_should_throw_a_terms_of_service_not_agreed_error() -> Result<(), Error> {
|
||||
let mut session = SessionHolder::new(ClientInfo::generate());
|
||||
let client = rawclient::new();
|
||||
let client = socialvoid_rawclient::new();
|
||||
session.create(&client).await?;
|
||||
let response = session
|
||||
.register(
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "types"
|
||||
name = "socialvoid_types"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
|
|
Loading…
Reference in New Issue