From 0e1ee88fdd15a0e650aae0b1dc94cd852dcebb79 Mon Sep 17 00:00:00 2001 From: Igor Bubelov Date: Wed, 5 Feb 2025 17:23:40 +0700 Subject: [PATCH] Update args --- src/command/element.rs | 65 +++++++++++++++++++++++++++--------------- src/command/paywall.rs | 18 ------------ src/main.rs | 32 ++++++++++----------- src/rpc.rs | 2 +- 4 files changed, 59 insertions(+), 58 deletions(-) diff --git a/src/command/element.rs b/src/command/element.rs index 3bbfa81..d14049d 100644 --- a/src/command/element.rs +++ b/src/command/element.rs @@ -13,44 +13,38 @@ pub fn get_element(args: &GetElementArgs) -> Result<()> { #[derive(Args)] pub struct SetElementTagArgs { - pub id: String, - pub name: String, - pub value: String, + pub element_id: i64, + pub tag_name: String, + pub tag_value: String, } pub fn set_element_tag(args: &SetElementTagArgs) -> Result<()> { - let value: Value = serde_json::from_str(&args.value)?; + let value: Value = serde_json::from_str(&args.tag_value)?; rpc::call( "set_element_tag", - json!({"id": args.id,"name": args.name, "value": value}), + json!({"element_id": args.element_id, "tag_name": args.tag_name, "tag_value": value}), )? .print() } #[derive(Args)] pub struct RemoveElementTagArgs { - pub id: String, - pub tag: String, + pub element_id: i64, + pub tag_name: String, } pub fn remove_element_tag(args: &RemoveElementTagArgs) -> Result<()> { - rpc::call("remove_element_tag", json!({"id": args.id,"tag": args.tag}))?.print() -} - -#[derive(Args)] -pub struct AddElementCommentArgs { - pub id: String, - pub comment: String, -} - -pub fn add_element_comment(args: &AddElementCommentArgs) -> Result<()> { rpc::call( - "add_element_comment", - json!({"id": args.id,"comment": args.comment}), + "remove_element_tag", + json!({"element_id": args.element_id, "tag_name": args.tag_name}), )? .print() } +pub fn get_boosted_elements() -> Result<()> { + rpc::call("get_boosted_elements", json!({}))?.print() +} + #[derive(Args)] pub struct BoostElementArgs { pub id: String, @@ -58,14 +52,39 @@ pub struct BoostElementArgs { } pub fn boost_element(args: &BoostElementArgs) -> Result<()> { - rpc::call("boost_element", json!({"id": args.id,"days": args.days}))?.print() + rpc::call("boost_element", json!({"id": args.id, "days": args.days}))?.print() +} + +pub fn paywall_get_boost_element_quote() -> Result<()> { + rpc::call("paywall_get_boost_element_quote", json!({}))?.print() } #[derive(Args)] -pub struct GetBoostedElementsArgs {} +pub struct PaywallBoostElementArgs { + pub element_id: String, + pub days: i64, +} -pub fn get_boosted_elements(_: &GetBoostedElementsArgs) -> Result<()> { - rpc::call("get_boosted_elements", json!({}))?.print() +pub fn paywall_boost_element(args: &PaywallBoostElementArgs) -> Result<()> { + rpc::call( + "paywall_boost_element", + json!({"element_id": args.element_id, "days": args.days}), + )? + .print() +} + +#[derive(Args)] +pub struct AddElementCommentArgs { + pub element_id: i64, + pub comment: String, +} + +pub fn add_element_comment(args: &AddElementCommentArgs) -> Result<()> { + rpc::call( + "add_element_comment", + json!({"element_id": args.element_id, "comment": args.comment}), + )? + .print() } #[derive(Args)] diff --git a/src/command/paywall.rs b/src/command/paywall.rs index 7078e19..5e3f1dc 100644 --- a/src/command/paywall.rs +++ b/src/command/paywall.rs @@ -19,21 +19,3 @@ pub fn paywall_add_element_comment(args: &PaywallAddElementCommentArgs) -> Resul )? .print() } - -pub fn paywall_get_boost_element_quote() -> Result<()> { - rpc::call("paywall_get_boost_element_quote", json!({}))?.print() -} - -#[derive(Args)] -pub struct PaywallBoostElementArgs { - pub element_id: String, - pub days: i64, -} - -pub fn paywall_boost_element(args: &PaywallBoostElementArgs) -> Result<()> { - rpc::call( - "paywall_boost_element", - json!({"element_id": args.element_id, "days": args.days}), - )? - .print() -} diff --git a/src/main.rs b/src/main.rs index 1d51387..1844b1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,16 +43,20 @@ enum Commands { Search(command::common::SearchArgs), /// Fetch element by a numeric or OSM (node:12345) id. You can also use node=12345 format GetElement(command::element::GetElementArgs), - /// Set tag to a certain element. You can use either numeric or OSM (node:12345) id. Every tag must be a valid JSON value. Nulls are not allowed and will be interpreted as deletion requests + /// Set tag to a certain element. Every tag must be a valid JSON value. Nulls are not allowed and will be interpreted as deletion requests SetElementTag(command::element::SetElementTagArgs), - /// Remove tag from a certain element. You can use either numeric or OSM (node:12345) id + /// Remove tag from a certain element RemoveElementTag(command::element::RemoveElementTagArgs), - /// Add coment to a certain element. You can use either numeric or OSM (node:12345) id - AddElementComment(command::element::AddElementCommentArgs), + /// Get all boosted elements + GetBoostedElements, /// Boost an element for a set number of days. You can use either numeric or OSM (node:12345) id BoostElement(command::element::BoostElementArgs), - /// Get all boosted elements - GetBoostedElements(command::element::GetBoostedElementsArgs), + /// Get current element boost price in sats + PaywallGetBoostElementQuote, + /// Submit boost request to receive an invoice + PaywallBoostElement(command::element::PaywallBoostElementArgs), + /// Add coment to a certain element + AddElementComment(command::element::AddElementCommentArgs), /// Fetch the latest Overpass snapshot and merge it with cached elements. It may take a long time and it's not supposed to be called manually SyncElements(command::element::SyncElementsArgs), /// Generate icon:android tags for a specific element id range @@ -85,10 +89,6 @@ enum Commands { PaywallGetAddElementCommentQuote, /// Submit comment to receive an invoice PaywallAddElementComment(command::paywall::PaywallAddElementCommentArgs), - /// Get current element boost price in sats - PaywallGetBoostElementQuote, - /// Submit boost request to receive an invoice - PaywallBoostElement(command::paywall::PaywallBoostElementArgs), } type Result = std::result::Result>; @@ -137,9 +137,13 @@ fn main() -> Result<()> { Commands::GetElement(args) => element::get_element(args), Commands::SetElementTag(args) => element::set_element_tag(args), Commands::RemoveElementTag(args) => element::remove_element_tag(args), - Commands::AddElementComment(args) => element::add_element_comment(args), + Commands::GetBoostedElements => element::get_boosted_elements(), Commands::BoostElement(args) => element::boost_element(args), - Commands::GetBoostedElements(args) => element::get_boosted_elements(args), + Commands::PaywallGetBoostElementQuote => { + command::element::paywall_get_boost_element_quote() + } + Commands::PaywallBoostElement(args) => command::element::paywall_boost_element(args), + Commands::AddElementComment(args) => element::add_element_comment(args), Commands::SyncElements(args) => element::sync_elements(args), Commands::GenerateElementIcons(args) => element::generate_element_icons(args), Commands::GenerateElementCategories(args) => element::generate_element_categories(args), @@ -166,10 +170,6 @@ fn main() -> Result<()> { Commands::PaywallAddElementComment(args) => { command::paywall::paywall_add_element_comment(args) } - Commands::PaywallGetBoostElementQuote => { - command::paywall::paywall_get_boost_element_quote() - } - Commands::PaywallBoostElement(args) => command::paywall::paywall_boost_element(args), } } diff --git a/src/rpc.rs b/src/rpc.rs index 36102db..1e99f21 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -49,7 +49,7 @@ pub fn call(method: &str, mut params: Value) -> Result { println!("{}", serde_json::to_string(&args)?.to_colored_json_auto()?); } let response = ureq::post(api_url) - .header("Content-Type", "application/json") + //.header("Content-Type", "application/json") .send_json(args)? .body_mut() .read_to_string()?;