Skip to content

Commit

Permalink
code cleanup & comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardTibben committed Nov 13, 2023
1 parent 75e4e15 commit 664245a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
14 changes: 1 addition & 13 deletions src/claimable_balances/single_claimable_balance_request.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use chrono::format;

use crate::models::*;

use super::super::AssetType;
use super::super::Order;

/// SingleClaimableBalanceRequest is the struct that implements the type for the /claimable_balances endpoint to get a single claimable balance
/// [More Details](https://laboratory.stellar.org/#explorer?resource=claimable_balances&endpoint=single&network=test "Single Claimable Balance")
#[derive(Debug)]
Expand Down Expand Up @@ -50,13 +45,6 @@ impl Request for SingleClaimableBalanceRequest {
/// # Returns
/// The URL for the request
fn build_url(&self, base_url: &str) -> String {
println!("\n\nBUILD URL: {:?}", format!(
"{}{}{}",
base_url,
self.get_path(),
self.get_query_parameters()
));

format!(
"{}{}{}",
base_url,
Expand Down Expand Up @@ -88,4 +76,4 @@ impl SingleClaimableBalanceRequest {
self.claimable_balance_id = Some(claimable_balance_id);
self
}
}
}
33 changes: 24 additions & 9 deletions src/horizon_client/horizon_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl HorizonClient {
Ok(Self { base_url })
}

/// Gets the base URL for the Horizon server
/// Gets an account list from the server
/// # Arguments
/// * `self` - The Horizon client
/// * request - The accounts request
Expand All @@ -49,7 +49,7 @@ impl HorizonClient {
self.get::<AccountsResponse>(request).await
}

/// Gets the base URL for the Horizon server
/// Gets a single account from the server
/// # Arguments
/// * `self` - The Horizon client
/// * request - The account request
Expand All @@ -65,7 +65,7 @@ impl HorizonClient {
self.get::<SingleAccountsResponse>(request).await
}

/// Gets the base URL for the Horizon server
/// Gets all assets from the server
/// # Arguments
/// * `self` - The Horizon client
/// * request - The all assets request
Expand All @@ -81,7 +81,7 @@ impl HorizonClient {
self.get::<AllAssetsResponse>(request).await
}

/// Gets the base URL for the Horizon server
/// Gets all claimable balances from the server
/// # Arguments
/// * `self` - The Horizon client
/// * request - The all claimable balances request
Expand All @@ -97,7 +97,7 @@ impl HorizonClient {
self.get::<AllClaimableBalancesResponse>(request).await
}

/// Gets the base URL for the Horizon server
/// Gets a single claimable balance from the server
/// # Arguments
/// * `self` - The Horizon client
/// * request - The single claimable balance request
Expand All @@ -113,13 +113,31 @@ impl HorizonClient {
self.get::<SingleClaimableBalanceResponse>(request).await
}

/// Gets the all ledger response from the server
/// # Arguments
/// * `self` - The Horizon client
/// * request - The ledgers request
/// # Returns
/// The ledgers response
/// # Errors
/// Returns an error if the request fails
/// [GET /ledgers](https://www.stellar.org/developers/horizon/reference/endpoints/ledgers-all.html)
pub async fn get_all_ledgers(
&self,
request: &LedgersRequest,
) -> Result<LedgersResponse, String> {
self.get::<LedgersResponse>(request).await
}

/// Gets a single ledger from the server
/// # Arguments
/// * `self` - The Horizon client
/// * request - The single ledger request
/// # Returns
/// The single ledger response
/// # Errors
/// Returns an error if the request fails
/// [GET /ledgers/{ledger_id}](https://www.stellar.org/developers/horizon/reference/endpoints/ledgers-single.html)
pub async fn get_single_ledger(
&self,
request: &SingleLedgerRequest,
Expand All @@ -146,7 +164,6 @@ impl HorizonClient {
// TODO: construct with query parameters

let url = request.build_url(&self.base_url);
// println!("\n\nURL: {}", url);
let response = reqwest::get(&url).await.map_err(|e| e.to_string())?;
println!("\n\nREQWEST RESPONSE: {:?}", response);
let result: TResponse = handle_response(response).await?;
Expand All @@ -170,7 +187,6 @@ async fn handle_response<TResponse: Response>(
match response.status() {
reqwest::StatusCode::OK => {
let _response = response.text().await.map_err(|e| e.to_string())?;
// println!("\n\nHANDLE_RESPONSE RESPONSE: {:?}", _response);
TResponse::from_json(_response)
}
_ => {
Expand All @@ -187,7 +203,7 @@ fn url_validate(url: &str) -> Result<(), String> {
return Err(format!("URL must start with http:// or https://: {}", url));
}
Url::parse(url).map_err(|e| e.to_string())?;

Ok(())
}

Expand Down Expand Up @@ -1429,7 +1445,6 @@ mod tests {

assert_eq!(predicate.is_valid_claim(jan_first_2022), false);


assert_eq!(
single_claimable_balance_response
.clone()
Expand Down

0 comments on commit 664245a

Please sign in to comment.