Skip to content

Commit

Permalink
Remove duplicate examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Eline Jorritsma committed Dec 21, 2023
1 parent 3927ed7 commit c255398
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 405 deletions.
16 changes: 1 addition & 15 deletions src/accounts/accounts_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{models::*, BuildQueryParametersExt};
/// # let base_url = "https://horizon-testnet.stellar.org".to_string();
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// let request: AccountsRequest<NoSponsorFilter, SignerFilter, NoAssetFilter, NoLiquidityPoolFilter> = AccountsRequest::new()
/// let request = AccountsRequest::new()
/// .set_signer_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7")
/// .unwrap();
///
Expand Down Expand Up @@ -186,19 +186,6 @@ valid_account_request_impl!(AccountsRequest<NoSponsorFilter, NoSignerFilter, NoA
/// - `order`: The [`Order`] of the returned records, either ascending ([`Order::Asc`]) or descending ([`Order::Desc`]).
/// Defaults to ascending if not set.
///
/// # Usage
///
/// Instances of `AccountsRequest` are created and configured using setter methods for each
/// parameter.
/// ```
/// # use stellar_rust_sdk::accounts::accounts_request::AccountsRequest;
/// # use crate::stellar_rust_sdk::models::Request;
/// let request = AccountsRequest::new()
/// .set_signer_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7").unwrap()
/// .set_limit(10).unwrap();
/// // Use with HorizonClient::get_account_list
/// ```
///
#[derive(Default)]
pub struct AccountsRequest<Sp, Si, A, L> {
/// Filter for accounts sponsored by the account ID or have a subentry
Expand Down Expand Up @@ -377,6 +364,5 @@ mod tests {
.set_sponsor_filter("sponsor".to_string());

assert!(request.is_err());
// assert_eq!(request.unwrap_err(), "Public key must be 56 characters long");
}
}
103 changes: 2 additions & 101 deletions src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,9 @@
/// is meant to be used with the [`HorizonClient::get_accounts_list`](crate::horizon_client::HorizonClient::get_account_list)
/// method.
///
/// The detailed documentation and usage instructions for the `AccountsRequest` struct
/// can be found within the struct definition itself.
///
/// # Usage
///
/// Typically, an instance of `AccountsRequest` is created and potentially configured
/// with specific query parameters, before being passed to [`HorizonClient::get_accounts_list`](crate::horizon_client::HorizonClient::get_account_list).
/// For example, construct a request to filter by signer:
///
/// ```rust
/// # use stellar_rust_sdk::accounts::accounts_request::AccountsRequest;
/// # use crate::stellar_rust_sdk::models::Request;
/// let mut request = AccountsRequest::new()
/// .set_signer_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7").unwrap()
/// .set_limit(10).unwrap();
/// // Use with HorizonClient::get_account_list
/// ```
///
pub mod accounts_request;


/// Provides the `AccountsResponse`.
///
/// This module provides a set of structures that represent the response received from the Horizon
Expand All @@ -34,46 +17,11 @@ pub mod accounts_request;
/// For a more elaborate overview of the returned values, please refer to the documentation of the
/// <a href="https://developers.stellar.org/api/horizon/resources/list-all-accounts">List All Accounts endpoint</a>.
///
/// Each structure is equipped with the necessary serialization and deserialization capabilities to handle
/// the JSON data returned by the Horizon server. Additionally, the `Getters` derive macro is used to
/// provide convenient getter methods for accessing the fields of these structures.
///
/// # Usage
///
/// These structures are mainly used internally by the `HorizonClient` when processing responses from
/// account-related API calls. The [`AccountsResponse`](crate::accounts::accounts_response::AccountsResponse) struct is of special importance here,
/// as it is returned by the [`HorizonClient::get_accounts_list`](crate::horizon_client::HorizonClient::get_account_list) method,
/// providing a user-friendly way to access account data.
///
/// # Example
///
/// ```
/// # use stellar_rust_sdk::accounts::prelude::{AccountsRequest, AccountsResponse};
/// # use stellar_rust_sdk::models::*;
/// # use stellar_rust_sdk::horizon_client::HorizonClient;
/// #
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let base_url = "https://horizon-testnet.stellar.org".to_string();
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// #
/// # let accounts_request = AccountsRequest::new()
/// # .set_signer_filter("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7").unwrap()
/// # .set_limit(10).unwrap();
/// #
/// let accounts_response: Result<AccountsResponse, String> = horizon_client
/// .get_account_list(&accounts_request)
/// .await;
///
/// // Access the account details
/// for record in accounts_response?._embedded().records() {
/// println!("Account ID: {}", record.account_id());
/// // Further processing...
/// }
/// # Ok({})
/// # }
/// ```
///
pub mod accounts_response;


Expand All @@ -84,24 +32,9 @@ pub mod accounts_response;
/// server. It is tailored for use with the [`HorizonClient::get_single_account`](crate::horizon_client::HorizonClient::get_single_account)
/// method.
///
/// # Usage
///
/// Create an instance of `SingleAccountRequest` and set the account ID to specify the
/// target account for the query. The struct can then be passed to the `get_single_account`
/// method of the `HorizonClient` to initiate the request.
///
/// ```
/// # use stellar_rust_sdk::accounts::prelude::SingleAccountRequest;
/// # use crate::stellar_rust_sdk::models::Request;
/// #
/// let mut single_account_request = SingleAccountRequest::new()
/// .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
/// .unwrap();
/// // Use with HorizonClient::get_single_account
/// ```
///
pub mod single_account_request;


/// Provides the `SingleAccountResponse`.
///
/// This module defines structures representing the response from the Horizon API when querying
Expand All @@ -111,38 +44,6 @@ pub mod single_account_request;
/// These structures are equipped with serialization capabilities to handle the JSON data from the
/// Horizon server and with getter methods for easy field access.
///
/// # Usage
///
/// Primarily used internally by the `HorizonClient` when handling responses from single account
/// queries. The [`SingleAccountResponse`](crate::accounts::single_account_response::SingleAccountResponse) struct,
/// specifically, is utilized to encapsulate and provide access to the details of the account being queried.
///
/// # Example
///
/// ```
/// # use stellar_rust_sdk::accounts::prelude::{SingleAccountRequest, SingleAccountResponse};
/// # use stellar_rust_sdk::models::*;
/// # use stellar_rust_sdk::horizon_client::HorizonClient;
/// #
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let base_url = "https://horizon-testnet.stellar.org".to_string();
/// # let horizon_client = HorizonClient::new(base_url)
/// # .expect("Failed to create Horizon Client");
/// #
/// # let mut single_account_request = SingleAccountRequest::new()
/// # .set_account_id("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
/// # .unwrap();
/// #
/// let _single_account_response = horizon_client
/// .get_single_account(&single_account_request)
/// .await;
///
/// // Access the account details
/// println!("Account ID: {}", _single_account_response?.account_id());
/// # Ok({})
/// # }
/// ```
///
pub mod single_account_response;

/// The base path for account-related endpoints in the Horizon API.
Expand Down
53 changes: 0 additions & 53 deletions src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@
/// to perform the actual API calls and fetch asset data. It adheres to the structure
/// and requirements of the Horizon API for asset queries.
///
/// # Usage
///
/// To use this module, create an instance of `AllAssetsRequest` and optionally set the desired
/// query parameters. Then, pass the request object to `HorizonClient::get_all_assets` method to
/// execute the query. The method returns an `AllAssetsResponse` containing the information about
/// the requested assets.
///
/// # Example
/// ```
/// # use stellar_rust_sdk::assets::all_assets_request::AllAssetsRequest;
/// # use stellar_rust_sdk::horizon_client::HorizonClient;
/// # use stellar_rust_sdk::models::Request;
/// #
/// # async fn fetch_assets() -> Result<(), Box<dyn std::error::Error>> {
/// # let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
/// let request = AllAssetsRequest::new()
/// .set_asset_code("USD").unwrap(); // Example asset code
///
/// let response = horizon_client.get_all_assets(&request).await?;
/// // Process the response
/// # Ok(())
/// # }
/// ```
///
pub mod all_assets_request;

/// Provides the `AllAssetsResponse`.
Expand All @@ -47,35 +23,6 @@ pub mod all_assets_request;
/// with the JSON format of the Horizon server's response. They also leverage the `Getters` derive macro
/// to furnish convenient getter methods for accessing their fields.
///
/// # Usage
///
/// These response structures are predominantly used internally by the `HorizonClient` to parse responses
/// from asset-related API calls. The `AllAssetsResponse` struct, in particular, plays a crucial role, as it
/// is returned by the [`HorizonClient::get_all_assets`](crate::horizon_client::HorizonClient::get_all_assets) method, offering a user-friendly interface
/// to asset data.
///
/// # Example
///
/// ```
/// # use stellar_rust_sdk::assets::prelude::{AllAssetsRequest, AllAssetsResponse};
/// # use stellar_rust_sdk::horizon_client::HorizonClient;
/// # use stellar_rust_sdk::models::Response;
/// #
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
/// # let request = AllAssetsRequest::new()
/// # .set_asset_code("USD").unwrap(); // Example asset code
/// let all_assets_response: Result<AllAssetsResponse, String> = horizon_client.get_all_assets(&request).await;
///
/// // Access asset details
/// for asset in all_assets_response?._embedded().records() {
/// println!("Asset Code: {}", asset.asset_code());
/// // Further processing...
/// }
/// # Ok(())
/// # }
/// ```
///
pub mod all_assets_response;

/// The base path for all assets endpoints in the Stellar Horizon API.
Expand Down
119 changes: 1 addition & 118 deletions src/claimable_balances/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,6 @@
/// to perform the actual API calls and fetch claimable balance data. It adheres to the structure
/// and requirements of the Horizon API for claimable balance queries.
///
/// # Usage
///
/// To use this module, create an instance of `AllClaimableBalancesRequest` and optionally set the desired
/// query parameters. Then, pass the request object to [`HorizonClient::get_all_claimable_balances`](crate::horizon_client::HorizonClient::get_all_claimable_balances)
/// method to execute the query. The method returns an `AllClaimableBalancesResponse` containing the information about
/// the requested assets.
///
/// # Example
/// ```
/// # use stellar_rust_sdk::claimable_balances::all_claimable_balances_request::AllClaimableBalancesRequest;
/// # use stellar_rust_sdk::horizon_client::HorizonClient;
/// # use stellar_rust_sdk::models::Request;
/// #
/// # async fn fetch_claimable_balances() -> Result<(), Box<dyn std::error::Error>> {
/// # let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
/// let request = AllClaimableBalancesRequest::new()
/// .set_sponsor("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
/// .unwrap();
///
/// let response = horizon_client.get_all_claimable_balances(&request).await?;
/// // Process the response
/// # Ok(())
/// # }
/// ```
///
pub mod all_claimable_balances_request;


Expand All @@ -44,42 +19,6 @@ pub mod all_claimable_balances_request;
/// Claimable balances are ledger entries that can be claimed by a designated account under
/// certain conditions and are a unique feature of the Stellar network.
///
/// # Usage
///
/// This module is typically used by the `HorizonClient` to deserialize the JSON response from
/// the Horizon server into a `AllClaimableBalancesResponse` object, which provides easy access
/// to the list of claimable balances and related information.
///
/// # Example
/// ```
/// # use stellar_rust_sdk::claimable_balances::prelude::*;
/// # use stellar_rust_sdk::horizon_client::HorizonClient;
/// # use stellar_rust_sdk::models::Response;
/// #
/// # async fn get_all_claimable_balances() -> Result<(), Box<dyn std::error::Error>> {
/// # let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
/// # let request = AllClaimableBalancesRequest::new()
/// # .set_sponsor("GDQJUTQYK2MQX2VGDR2FYWLIYAQIEGXTQVTFEMGH2BEWFG4BRUY4CKI7".to_string())
/// # .unwrap();
/// #
/// let response: Result<AllClaimableBalancesResponse, String> = horizon_client
/// .get_all_claimable_balances(&request)
/// .await;
///
/// match response {
/// Ok(all_balances) => {
/// for balance in all_balances.embedded().records() {
/// println!("Balance ID: {}", balance.id());
/// // Further processing...
/// }
/// },
/// Err(e) => eprintln!("Error fetching claimable balances: {}", e),
/// }
/// #
/// # Ok(())
/// # }
/// ```
///
pub mod all_claimable_balances_response;

/// Provides the `SingleClaimableBalanceRequest` struct.
Expand All @@ -90,29 +29,7 @@ pub mod all_claimable_balances_response;
///
/// The struct is intended to be used with the [`HorizonClient`](crate::horizon_client::HorizonClient)
/// to perform API calls and fetch detailed information about a specific claimable balance.
///
/// # Usage
///
/// To use this module, instantiate a `SingleClaimableBalanceRequest` and set the claimable balance ID.
/// Then, pass this request to the [`HorizonClient::get_single_claimable_balance`](crate::horizon_client::HorizonClient::get_single_claimable_balance) method to execute the query.
/// The method returns a `SingleClaimableBalanceResponse` with the detailed information.
///
/// # Example
/// ```
/// # use stellar_rust_sdk::claimable_balances::single_claimable_balance_request::SingleClaimableBalanceRequest;
/// # use stellar_rust_sdk::horizon_client::HorizonClient;
/// # use stellar_rust_sdk::models::Request;
/// #
/// # async fn fetch_claimable_balance() -> Result<(), Box<dyn std::error::Error>> {
/// # let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
/// let request = SingleClaimableBalanceRequest::new()
/// .set_claimable_balance_id("00000000".to_string()); // Example claimable balance ID
///
/// let response = horizon_client.get_single_claimable_balance(&request).await?;
/// // Process the response
/// # Ok(())
/// # }
/// ```
///
pub mod single_claimable_balance_request;

Expand All @@ -131,40 +48,6 @@ pub mod single_claimable_balance_request;
/// JSON data returned by the Horizon server. The `Getters` derive macro is used to provide
/// convenient getter methods for accessing fields of these structures.
///
/// # Usage
///
/// The response structures are primarily used internally by the `HorizonClient` when processing
/// responses from claimable balance-related API calls. The `SingleClaimableBalanceResponse` struct
/// is especially important as it is returned by the
/// [`HorizonClient::get_single_claimable_balance`](crate::horizon_client::HorizonClient::get_single_claimable_balance)
/// method, providing a user-friendly way to access data of a single claimable balance.
///
/// # Example
///
/// ```
/// # use stellar_rust_sdk::claimable_balances::prelude::{SingleClaimableBalanceRequest, SingleClaimableBalanceResponse};
/// # use stellar_rust_sdk::horizon_client::HorizonClient;
/// # use stellar_rust_sdk::models::Response;
/// #
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org".to_string())?;
/// let claimable_balance_id = "123456789abcdefg".to_string();
/// let request = SingleClaimableBalanceRequest::new()
/// .set_claimable_balance_id(claimable_balance_id);
///
/// let response = horizon_client
/// .get_single_claimable_balance(&request)
/// .await;
///
/// // Access the details of the claimable balance
/// if let Ok(balance_response) = response {
/// println!("Balance Amount: {}", balance_response.amount());
/// // Further processing...
/// }
/// # Ok(())
/// # }
/// ```
///
pub mod single_claimable_balance_response;


Expand Down
Loading

0 comments on commit c255398

Please sign in to comment.