Skip to content

Commit

Permalink
documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonardTibben committed Nov 14, 2023
1 parent c927e5e commit 05e74a8
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 177 deletions.
10 changes: 1 addition & 9 deletions src/accounts/accounts_request.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::models::*;

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

/// AccountsRequest is the request object for the /accounts endpoint
/// [More Details](https://www.stellar.org/developers/horizon/reference/endpoints/accounts.html "Accounts")
Expand Down Expand Up @@ -31,10 +31,6 @@ pub struct AccountsRequest {
}

impl Request for AccountsRequest {
/// Creates a new request object
/// # Returns
/// A new request object
/// [AccountsRequest](struct.AccountsRequest.html)
fn new() -> Self {
AccountsRequest {
sponsor: None,
Expand All @@ -47,12 +43,10 @@ impl Request for AccountsRequest {
}
}

/// Gets the relative URL for the request
fn get_path(&self) -> &str {
"/accounts"
}

/// Gets the query parameters for the request
fn get_query_parameters(&self) -> String {
let mut query = String::new();
if let Some(sponsor) = &self.sponsor {
Expand All @@ -79,7 +73,6 @@ impl Request for AccountsRequest {
query.trim_end_matches('&').to_string()
}

// Build the URL for the request
fn build_url(&self, base_url: &str) -> String {
format!(
"{}{}?{}",
Expand All @@ -89,7 +82,6 @@ impl Request for AccountsRequest {
)
}

/// Validate the request
fn validate(&self) -> Result<(), String> {
if let Some(sponsor) = &self.sponsor {
let is_valid = is_public_key(sponsor);
Expand Down
8 changes: 0 additions & 8 deletions src/accounts/single_account_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@ pub struct SingleAccountRequest {
}

impl Request for SingleAccountRequest {
/// Creates a new request object
/// # Returns
/// A new request object
/// [SingleAccountRequest](struct.SingleAccountRequest.html)
fn new() -> Self {
SingleAccountRequest { account_id: None }
}

/// Gets the relative URL for the request
fn get_path(&self) -> &str {
"/accounts/"
}

/// Gets the query parameters for the request
fn get_query_parameters(&self) -> String {
let mut query = String::new();
if let Some(account_id) = &self.account_id {
Expand All @@ -31,7 +25,6 @@ impl Request for SingleAccountRequest {
query.trim_end_matches('&').to_string()
}

/// Build the URL for the request
fn build_url(&self, base_url: &str) -> String {
format!(
"{}{}{}",
Expand All @@ -41,7 +34,6 @@ impl Request for SingleAccountRequest {
)
}

/// Validate the request
fn validate(&self) -> Result<(), String> {
if let Some(account_id) = &self.account_id {
let is_valid = is_public_key(account_id);
Expand Down
8 changes: 0 additions & 8 deletions src/assets/all_assets_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ pub struct AllAssetsRequest {
}

impl Request for AllAssetsRequest {
/// Creates a new request object
/// # Returns
/// A new request object
/// [AllAssetsRequest](struct.AllAssetsRequest.html)
fn new() -> Self {
AllAssetsRequest {
asset_code: None,
Expand All @@ -39,12 +35,10 @@ impl Request for AllAssetsRequest {
}
}

/// Gets the relative URL for the request
fn get_path(&self) -> &str {
"/assets"
}

/// Gets the query parameters for the request
fn get_query_parameters(&self) -> String {
let mut query = String::new();
if let Some(asset_code) = &self.asset_code {
Expand All @@ -66,7 +60,6 @@ impl Request for AllAssetsRequest {
query.trim_end_matches('&').to_string()
}

/// Validates the request
fn validate(&self) -> Result<(), String> {
if let Some(asset_code) = &self.asset_code {
// TODO: implement full asset code regex
Expand Down Expand Up @@ -97,7 +90,6 @@ impl Request for AllAssetsRequest {
Ok(())
}

/// Builds the URL for the request
fn build_url(&self, base_url: &str) -> String {
format!(
"{}{}?{}",
Expand Down
9 changes: 9 additions & 0 deletions src/assets/all_assets_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::models::Response;
use derive_getters::Getters;
use serde::{Deserialize, Serialize};

/// Struct defining the self link in the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct Links {
#[serde(rename = "self")]
Expand All @@ -10,17 +11,20 @@ pub struct Links {
prev: Link,
}

/// Struct defining the self link in the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct Link {
href: Option<String>,
toml: Option<Toml>,
}

/// Struct defining the self link in the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct Toml {
href: String,
}

/// Struct defining a single balance in the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct Records {
_links: Link,
Expand All @@ -41,20 +45,23 @@ pub struct Records {
flags: Flags,
}

/// Struct defining a single balance in the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct AccountInfo {
authorized: u32,
authorized_to_maintain_liabilities: u32,
unauthorized: u32,
}

/// Struct defining a single balance in the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct AccountBalances {
authorized: String,
authorized_to_maintain_liabilities: String,
unauthorized: String,
}

/// Struct defining the thresholds in the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct Flags {
auth_required: bool,
Expand All @@ -63,11 +70,13 @@ pub struct Flags {
auth_clawback_enabled: bool,
}

/// Struct defining the embedded in the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct Embedded {
records: Vec<Records>,
}

/// Struct defining the list all accounts response.
#[derive(Debug, Serialize, Deserialize, Clone, Getters)]
pub struct AllAssetsResponse {
_links: Links,
Expand Down
12 changes: 0 additions & 12 deletions src/claimable_balances/all_claimable_balances_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ pub struct AllClaimableBalancesRequest {
}

impl Request for AllClaimableBalancesRequest {
/// Creates a new request object
/// # Returns
/// A new request object
/// [AllClaimableBalancesRequest](struct.AllClaimableBalancesRequest.html)
fn new() -> Self {
AllClaimableBalancesRequest {
sponsor: None,
Expand All @@ -44,12 +40,10 @@ impl Request for AllClaimableBalancesRequest {
}
}

/// Gets the relative URL for the request
fn get_path(&self) -> &str {
"/claimable_balances/"
}

// Gets the query parameters for the request
fn get_query_parameters(&self) -> String {
let mut query = String::new();
if let Some(sponsor) = &self.sponsor {
Expand All @@ -74,12 +68,6 @@ impl Request for AllClaimableBalancesRequest {
query.trim_end_matches('&').to_string()
}

/// Builds the URL for the request
/// # Arguments
/// * `self` - The request object
/// * `base_url` - The base URL for the Horizon server
/// # Returns
/// The URL for the request
fn build_url(&self, base_url: &str) -> String {
format!(
"{}{}?{}",
Expand Down
1 change: 1 addition & 0 deletions src/claimable_balances/all_claimable_balances_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl Response for AllClaimableBalancesResponse {
}
}

/// This method checks if a claim is valid at a specific datetime.
impl Predicate {
// This method checks if a claim is valid at a specific datetime.
pub fn is_valid_claim(&self, datetime: DateTime<Utc>) -> bool {
Expand Down
24 changes: 1 addition & 23 deletions src/claimable_balances/single_claimable_balance_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,16 @@ pub struct SingleClaimableBalanceRequest {
}

impl Request for SingleClaimableBalanceRequest {
/// Creates a new request object
/// # Returns
/// A new request object
/// [SingleClaimableBalanceRequest](struct.SingleClaimableBalanceRequest.html)
fn new() -> Self {
SingleClaimableBalanceRequest {
claimable_balance_id: None,
}
}

/// Gets the relative URL for the request
/// # Returns
/// The relative URL for the request
fn get_path(&self) -> &str {
"/claimable_balances/"
}

/// Gets the query parameters for the request
/// # Returns
/// The query parameters for the request
fn get_query_parameters(&self) -> String {
let mut query = String::new();
if let Some(claimable_balance_id) = &self.claimable_balance_id {
Expand All @@ -38,12 +28,6 @@ impl Request for SingleClaimableBalanceRequest {
query
}

/// Builds the URL for the request
/// # Arguments
/// * `self` - The request object
/// * `base_url` - The base URL for the Horizon server
/// # Returns
/// The URL for the request
fn build_url(&self, base_url: &str) -> String {
format!(
"{}{}{}",
Expand All @@ -53,13 +37,7 @@ impl Request for SingleClaimableBalanceRequest {
)
}

/// Returns the type of request
/// # Returns
/// The type of request
/// [RequestType](../enum.RequestType.html)
/// [More Details](https://laboratory.stellar.org/#explorer?resource=claimable_balances&endpoint=single&network=test "Single Claimable Balance")
fn validate(&self) -> Result<(), String> {

// TODO: Validate claimable_balance_id

Ok(())
Expand All @@ -76,4 +54,4 @@ impl SingleClaimableBalanceRequest {
self.claimable_balance_id = Some(claimable_balance_id);
self
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl Response for SingleClaimableBalanceResponse {
}
}

/// This method checks if a claim is valid at a specific datetime.
impl Predicate {
// This method checks if a claim is valid at a specific datetime.
pub fn is_valid_claim(&self, datetime: DateTime<Utc>) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions src/ledgers/ledgers_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ use super::super::Order;
pub struct LedgersRequest {
/// The cursor for the page
cursor: Option<u32>,

/// The maximum number of records to return
limit: Option<u32>,

/// The order of the records
order: Option<Order>,
}
Expand Down
Loading

0 comments on commit 05e74a8

Please sign in to comment.