-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
comment test
- Loading branch information
leonard
committed
Feb 13, 2024
1 parent
c46fb18
commit 67f0fe4
Showing
5 changed files
with
494 additions
and
21 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
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,109 @@ | ||
use crate::models::{Order, Request}; | ||
use crate::BuildQueryParametersExt; | ||
|
||
#[derive(Default)] | ||
pub struct EffectsForLiquidityPoolsRequest { | ||
/// The liquidity pool id | ||
liquidity_pool_id: Option<String>, | ||
|
||
/// 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. | ||
cursor: Option<u32>, | ||
|
||
/// Specifies the maximum number of records to be returned in a single response. | ||
/// The range for this parameter is from 1 to 200. The default value is set to 10. | ||
limit: Option<u8>, | ||
|
||
/// Determines the [`Order`] of the records in the response. Valid options are [`Order::Asc`] (ascending) | ||
/// and [`Order::Desc`] (descending). If not specified, it defaults to ascending. | ||
order: Option<Order>, | ||
} | ||
|
||
impl EffectsForLiquidityPoolsRequest { | ||
/// Creates a new `EffectsForLiquidityPoolsRequest` with default parameters. | ||
pub fn new() -> Self { | ||
EffectsForLiquidityPoolsRequest::default() | ||
} | ||
|
||
/// Sets the liquidity pool id for the request. | ||
/// | ||
/// # Arguments | ||
/// * `liquidity_pool_id` - A `String` value representing the liquidity pool id. | ||
/// | ||
pub fn set_liquidity_pool_id( | ||
self, | ||
liquidity_pool_id: String, | ||
) -> EffectsForLiquidityPoolsRequest { | ||
EffectsForLiquidityPoolsRequest { | ||
liquidity_pool_id: Some(liquidity_pool_id), | ||
..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<EffectsForLiquidityPoolsRequest, String> { | ||
if cursor < 1 { | ||
return Err("cursor must be greater than or equal to 1".to_string()); | ||
} | ||
|
||
Ok(EffectsForLiquidityPoolsRequest { | ||
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<EffectsForLiquidityPoolsRequest, String> { | ||
if limit < 1 || limit > 200 { | ||
return Err("limit must be between 1 and 200".to_string()); | ||
} | ||
|
||
Ok(EffectsForLiquidityPoolsRequest { | ||
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) -> EffectsForLiquidityPoolsRequest { | ||
EffectsForLiquidityPoolsRequest { | ||
order: Some(order), | ||
..self | ||
} | ||
} | ||
} | ||
|
||
impl Request for EffectsForLiquidityPoolsRequest { | ||
fn get_query_parameters(&self) -> String { | ||
vec![ | ||
self.liquidity_pool_id | ||
.as_ref() | ||
.map(|l| format!("liquidity_pool_id={}", l)), | ||
self.cursor.as_ref().map(|c| format!("cursor={}", c)), | ||
self.limit.as_ref().map(|l| format!("limit={}", l)), | ||
self.order.as_ref().map(|o| format!("order={}", o)), | ||
] | ||
.build_query_parameters() | ||
} | ||
|
||
fn build_url(&self, base_url: &str) -> String { | ||
format!( | ||
"{}/{}{}", | ||
base_url, | ||
super::EFFECTS_PATH, | ||
self.get_query_parameters() | ||
) | ||
} | ||
} |
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,110 @@ | ||
use derive_getters::Getters; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::models::Response; | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Getters)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct EffectsForLiquidityPoolResponse { | ||
/// Navigational links for the current, next, and previous pages of the response. | ||
#[serde(rename = "_links")] | ||
pub links: Links, | ||
/// Contains the actual list of effect records in the `records` field. | ||
#[serde(rename = "_embedded")] | ||
pub embedded: Embedded, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Getters)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Links { | ||
/// Navigational links for the current, next, and previous pages of the response. | ||
#[serde(rename = "self")] | ||
pub self_field: Link, | ||
/// Navigational links for the next page of the response. | ||
pub next: Link, | ||
/// Navigational links for the previous page of the response. | ||
pub prev: Link, | ||
} | ||
|
||
/// Represents different kinds of links a Response might have. | ||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Getters)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Link { | ||
/// Navigational links for the current, next, and previous pages of the response. | ||
#[serde(rename = "self")] | ||
pub self_field: Option<String>, | ||
/// Navigational links for the next page of the response. | ||
pub next: Option<String>, | ||
/// Navigational links for the previous page of the response. | ||
pub prev: Option<String>, | ||
/// Navigational links for the operation of the response. | ||
pub operation: Option<String>, | ||
/// Navigational links for the succeeds of the response. | ||
pub succeeds: Option<String>, | ||
/// Navigational links for the precedes of the response. | ||
pub precedes: Option<String>, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Getters)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Embedded { | ||
/// A list of effect records. | ||
pub records: Vec<Record>, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Getters)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Record { | ||
/// Navigational links for the current, next, and previous pages of the response. | ||
#[serde(rename = "_links")] | ||
pub links: RecordLinks, | ||
/// A unique identifier of the effect | ||
pub id: String, | ||
#[serde(rename = "paging_token")] | ||
/// A token used for paging through results. | ||
pub paging_token: String, | ||
/// The account that generated the effect. | ||
pub account: String, | ||
/// The type of effect. | ||
#[serde(rename = "type")] | ||
pub type_field: String, | ||
/// The type_i of the effect. | ||
#[serde(rename = "type_i")] | ||
pub type_i: i64, | ||
/// the epoch timestamp when the effect was created. | ||
#[serde(rename = "created_at")] | ||
pub created_at: String, | ||
/// The starting balance of the effect. | ||
#[serde(rename = "starting_balance")] | ||
pub starting_balance: Option<String>, | ||
/// The asset type of the effect. | ||
#[serde(rename = "asset_type")] | ||
pub asset_type: Option<String>, | ||
/// the amount of the effect | ||
pub amount: Option<String>, | ||
/// the wheight of the effect | ||
pub weight: Option<i64>, | ||
#[serde(rename = "public_key")] | ||
/// The public key of the effect | ||
pub public_key: Option<String>, | ||
/// The trustor of the effect | ||
pub key: Option<String>, | ||
} | ||
|
||
/// Represents different kinds of links a Record might have. | ||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, Getters)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct RecordLinks { | ||
/// Navigational links for the current, next, and previous pages of the response. | ||
pub operation: Link, | ||
/// Navigational links for the next page of the response. | ||
pub succeeds: Link, | ||
/// Navigational links for the previous page of the response. | ||
pub precedes: Link, | ||
} | ||
|
||
impl Response for EffectsForLiquidityPoolResponse { | ||
fn from_json(json: String) -> Result<Self, String> { | ||
serde_json::from_str(&json).map_err(|e| e.to_string()) | ||
} | ||
} |
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
Oops, something went wrong.