Skip to content

Commit

Permalink
Update args
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Feb 5, 2025
1 parent f9da8b0 commit 0e1ee88
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 58 deletions.
65 changes: 42 additions & 23 deletions src/command/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,78 @@ 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,
pub days: i64,
}

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)]
Expand Down
18 changes: 0 additions & 18 deletions src/command/paywall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
32 changes: 16 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<T> = std::result::Result<T, Box<dyn Error>>;
Expand Down Expand Up @@ -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),
Expand All @@ -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),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn call(method: &str, mut params: Value) -> Result<RpcResponse> {
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()?;
Expand Down

0 comments on commit 0e1ee88

Please sign in to comment.