diff --git a/stellar_rust_sdk/src/horizon_client.rs b/stellar_rust_sdk/src/horizon_client.rs index 4174a87..0c4f7a3 100644 --- a/stellar_rust_sdk/src/horizon_client.rs +++ b/stellar_rust_sdk/src/horizon_client.rs @@ -866,6 +866,8 @@ impl HorizonClient { /// # use stellar_rs::offers::prelude::*; /// # use stellar_rs::models::Request; /// # use stellar_rs::horizon_client::HorizonClient; + /// # use stellar_rust_sdk_derive::Pagination; + /// # use stellar_rs::Paginatable; /// # /// # async fn example() -> Result<(), Box> { /// # let base_url = "https://horizon-testnet.stellar.org".to_string(); diff --git a/stellar_rust_sdk/src/offers/all_offers_request.rs b/stellar_rust_sdk/src/offers/all_offers_request.rs index 8d93330..726d4a0 100644 --- a/stellar_rust_sdk/src/offers/all_offers_request.rs +++ b/stellar_rust_sdk/src/offers/all_offers_request.rs @@ -1,5 +1,4 @@ use crate::{models::*, BuildQueryParametersExt}; - use stellar_rust_sdk_derive::Pagination; use crate::Paginatable; @@ -20,6 +19,8 @@ use crate::Paginatable; /// ``` /// use stellar_rs::offers::all_offers_request::AllOffersRequest; /// use stellar_rs::models::{Asset, NativeAsset, Order}; +/// use stellar_rust_sdk_derive::Pagination; +/// use stellar_rs::Paginatable; /// /// let request = AllOffersRequest::new() /// .set_sponsor("GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5".to_string()).unwrap() // Optional sponsor filter @@ -43,11 +44,9 @@ pub struct AllOffersRequest { seller: Option, /// Optional. Indicates an selling asset for which offers are being queried. /// When set, the response will filter the offers that hold this specific asset. - // TODO: Make `NativeAsset` also possible selling: Option>, /// Optional. Indicates a buying asset for which offers are being queried. /// When set, the response will filter the offers that hold this specific asset. - // TODO: Make `NativeAsset` also possible buying: Option>, /// A pointer to a specific location in a collection of responses, derived from the /// `paging_token` value of a record. Used for pagination control in the API response. @@ -145,48 +144,4 @@ impl AllOffersRequest { ..self } } - - /// Sets the cursor for pagination. - /// - /// # Arguments - /// * `cursor` - A `u32` value pointing to a specific location in a collection of responses. - /// - pub fn set_cursor(self, cursor: u32) -> Result { - if cursor < 1 { - return Err("cursor must be greater than or equal to 1".to_string()); - } - - Ok(AllOffersRequest { - cursor: Some(cursor), - ..self - }) - } - - /// Sets the maximum number of records to return. - /// - /// # Arguments - /// * `limit` - A `u8` value specifying the maximum number of records. Range: 1 to 200. Defaults to 10. - /// - pub fn set_limit(self, limit: u8) -> Result { - if limit < 1 || limit > 200 { - return Err("limit must be between 1 and 200".to_string()); - } - - Ok(AllOffersRequest { - limit: Some(limit), - ..self - }) - } - - /// Sets the order of the returned records. - /// - /// # Arguments - /// * `order` - An [`Order`] enum value specifying the order (ascending or descending). - /// - pub fn set_order(self, order: Order) -> AllOffersRequest { - AllOffersRequest { - order: Some(order), - ..self - } - } } \ No newline at end of file diff --git a/stellar_rust_sdk/src/offers/mod.rs b/stellar_rust_sdk/src/offers/mod.rs index eaab01a..707433c 100644 --- a/stellar_rust_sdk/src/offers/mod.rs +++ b/stellar_rust_sdk/src/offers/mod.rs @@ -73,8 +73,7 @@ pub mod prelude { #[cfg(test)] pub mod test { use super::prelude::*; - use crate::horizon_client::HorizonClient; - use crate::models::*; + use crate::{horizon_client::HorizonClient, models::*, Paginatable}; const LINK_SELF: &str = "https://horizon-testnet.stellar.org/offers/1"; const LINK_OFFER_MAKER: &str = "https://horizon-testnet.stellar.org/accounts/GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"; @@ -180,12 +179,12 @@ pub mod test { const BUYING_ASSET_TYPE: &str = "credit_alphanum12"; const BUYING_ASSET_CODE: &str = "EURCAllow"; const BUYING_ASSET_ISSUER: &str = "GA6HVGLFUF3BHHGR5CMYXIVZ3RYVUH5EUYAOAY4T3OKI5OQVIWVRK24R"; - const AMOUNT: &str = "922320116343.5775807"; + const AMOUNT: &str = "922320116343.0475807"; const PRICE_R_N: &u32 = &1; const PRICE_R_D: &u32 = &1; const PRICE: &str = "1.0000000"; - const LAST_MODIFIED_LEDGER: &u32 = &1265238; - const LAST_MODIFIED_TIME: &str = "2024-04-23T16:33:24Z"; + const LAST_MODIFIED_LEDGER: &u32 = &1384257; + const LAST_MODIFIED_TIME: &str = "2024-04-30T22:19:21Z"; let horizon_client = HorizonClient::new("https://horizon-testnet.stellar.org" @@ -193,13 +192,12 @@ pub mod test { .unwrap(); // Create a request and supply values for optional filters. - // TODO: Try to supply more filters and produce testable response results let all_offers_request = AllOffersRequest::new() .set_seller(SELLER.to_string()).unwrap() .set_cursor(1).unwrap() .set_limit(100).unwrap() - .set_order(Order::Asc); + .set_order(Order::Asc).unwrap(); let all_offers_response = horizon_client .get_all_offers(&all_offers_request)