-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19242c9
commit e2c35bb
Showing
9 changed files
with
120 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": [ | ||
"./Cargo.toml" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use crate::models::*; | ||
|
||
use super::super::Order; | ||
use super::super::AssetType; | ||
|
||
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>, | ||
} | ||
|
||
impl Request for LedgersRequest { | ||
fn new() -> Self { | ||
Self { | ||
cursor: None, | ||
limit: None, | ||
order: None, | ||
} | ||
} | ||
|
||
fn get_path(&self) -> &str { | ||
"/ledgers" | ||
} | ||
|
||
fn get_query_parameters(&self) -> String { | ||
let mut query_parameters = vec![]; | ||
|
||
if let Some(cursor) = &self.cursor { | ||
query_parameters.push(format!("cursor={}", cursor)); | ||
} | ||
|
||
if let Some(limit) = &self.limit { | ||
query_parameters.push(format!("limit={}", limit)); | ||
} | ||
|
||
if let Some(order) = &self.order { | ||
query_parameters.push(format!("order={}", order)); | ||
} | ||
|
||
query_parameters.join("&") | ||
} | ||
|
||
fn validate(&self) -> Result<(), String> { | ||
if let Some(cursor) = &self.cursor { | ||
if *cursor < 1 { | ||
return Err("cursor must be greater than or equal to 1".to_string()); | ||
} | ||
} | ||
|
||
if let Some(limit) = &self.limit { | ||
if *limit < 1 { | ||
return Err("limit must be greater than or equal to 1".to_string()); | ||
} | ||
if *limit > 200 { | ||
return Err("limit must be less than or equal to 200".to_string()); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn build_url(&self, base_url: &str) -> String { | ||
todo!() | ||
} | ||
} | ||
|
||
impl LedgersRequest { | ||
/// Sets the cursor for the page | ||
pub fn cursor(mut self, cursor: u32) -> Self { | ||
self.cursor = Some(cursor); | ||
self | ||
} | ||
|
||
/// Sets the maximum number of records to return | ||
pub fn limit(mut self, limit: u32) -> Self { | ||
self.limit = Some(limit); | ||
self | ||
} | ||
|
||
/// Sets the order of the records | ||
pub fn order(mut self, order: Order) -> Self { | ||
self.order = Some(order); | ||
self | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_ledgers_request() { | ||
let request = LedgersRequest::new(); | ||
|
||
assert_eq!(request.get_path(), "/ledgers"); | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod ledgers_request; | ||
mod ledgers_response; | ||
|
||
pub mod prelude { | ||
pub use super::ledgers_request::*; | ||
pub use super::ledgers_response::*; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod assets; | ||
mod accounts; | ||
mod ledgers; | ||
mod horizon_client; | ||
mod models; | ||
mod xdr; | ||
|