Skip to content

Commit

Permalink
Remove debug flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesa-telos committed Oct 10, 2024
1 parent 92f031b commit 8fa2850
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 53 deletions.
15 changes: 0 additions & 15 deletions crates/antelope/src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl Display for HTTPMethod {

#[async_trait::async_trait]
pub trait Provider: Debug + Default + Sync + Send {
fn set_debug(&mut self, debug: bool);
async fn post(&self, path: String, body: Option<String>) -> Result<String, String>;
async fn get(&self, path: String) -> Result<String, String>;
}
Expand All @@ -40,20 +39,6 @@ pub struct APIClient<P: Provider> {
}

impl<P: Provider> APIClient<P> {
pub fn default_provider(base_url: String) -> Result<APIClient<DefaultProvider>, String> {
Self::default_provider_debug(base_url, false)
}

pub fn default_provider_debug(
base_url: String,
debug: bool,
) -> Result<APIClient<DefaultProvider>, String> {
let mut provider = DefaultProvider::new(base_url).unwrap();
provider.set_debug(debug);

APIClient::custom_provider(provider)
}

pub fn custom_provider(provider: P) -> Result<Self, String> {
Ok(APIClient {
v1_chain: ChainAPI::new(provider),
Expand Down
38 changes: 7 additions & 31 deletions crates/antelope/src/api/default_provider.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::api::client::Provider;
use reqwest::Client;
use std::fmt::{Debug, Formatter};
use tracing::info;
use tracing::{debug};

#[derive(Default, Clone)]
pub struct DefaultProvider {
debug: bool,
base_url: String,
client: Client,
}
Expand All @@ -25,7 +24,6 @@ impl DefaultProvider {
let url = base_url.trim_end_matches('/');

Ok(Self {
debug: false,
base_url: String::from(url),
client: client.unwrap(),
})
Expand All @@ -41,61 +39,39 @@ impl Debug for DefaultProvider {
#[async_trait::async_trait]
impl Provider for DefaultProvider {
async fn get(&self, path: String) -> Result<String, String> {
if self.debug {
info!("GET {}", self.base_url.to_string() + &path);
}

debug!("GET {}", self.base_url.to_string() + &path);
let res = self
.client
.get(self.base_url.to_string() + &path)
.send()
.await;
if res.is_err() {
let res_err = res.err().unwrap().to_string();
if self.debug {
info!("Error: {}", res_err);
}

debug!("Error: {}", res_err);
return Err(res_err);
}

let response = res.unwrap().text().await.unwrap();
if self.debug {
info!("Response: {}", response);
}

debug!("Response: {}", response);
Ok(response)
}

async fn post(&self, path: String, body: Option<String>) -> Result<String, String> {
let mut builder = self.client.post(self.base_url.to_string() + &path);
if body.is_some() {
let body_str = body.unwrap();
if self.debug {
info!("POST {} {}", self.base_url.to_string() + &path, body_str);
}

debug!("POST {} {}", self.base_url.to_string() + &path, body_str);
builder = builder.body(body_str);
}
let res = builder.send().await;
if res.is_err() {
let err_str = res.err().unwrap().to_string();
if self.debug {
info!("Error: {}", err_str);
}

debug!("Error: {}", err_str);
return Err(err_str);
}

let response = res.unwrap().text().await.unwrap();
if self.debug {
info!("Response: {}", response);
}

debug!("Response: {}", response);
Ok(response)
}

fn set_debug(&mut self, debug: bool) {
self.debug = debug;
}
}
4 changes: 1 addition & 3 deletions crates/antelope/tests/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use tracing::info;
use antelope::api::client::DefaultProvider;
use antelope::api::v1::structs::{ErrorResponse, IndexPosition, TableIndexType};
use antelope::api::v1::structs::{ErrorResponse};
use antelope::{
api::{
client::APIClient,
Expand Down
4 changes: 0 additions & 4 deletions crates/antelope/tests/utils/mock_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ impl Debug for MockProvider {

#[async_trait::async_trait]
impl Provider for MockProvider {
fn set_debug(&mut self, debug: bool) {
// TODO: Implement if we want debugging of the mock response in tests
}

async fn post(&self, path: String, body: Option<String>) -> Result<String, String> {
self.call(HTTPMethod::POST, path, body)
}
Expand Down

0 comments on commit 8fa2850

Please sign in to comment.