Skip to content

Commit 0e1ee88

Browse files
committed
Update args
1 parent f9da8b0 commit 0e1ee88

File tree

4 files changed

+59
-58
lines changed

4 files changed

+59
-58
lines changed

src/command/element.rs

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,78 @@ pub fn get_element(args: &GetElementArgs) -> Result<()> {
1313

1414
#[derive(Args)]
1515
pub struct SetElementTagArgs {
16-
pub id: String,
17-
pub name: String,
18-
pub value: String,
16+
pub element_id: i64,
17+
pub tag_name: String,
18+
pub tag_value: String,
1919
}
2020

2121
pub fn set_element_tag(args: &SetElementTagArgs) -> Result<()> {
22-
let value: Value = serde_json::from_str(&args.value)?;
22+
let value: Value = serde_json::from_str(&args.tag_value)?;
2323
rpc::call(
2424
"set_element_tag",
25-
json!({"id": args.id,"name": args.name, "value": value}),
25+
json!({"element_id": args.element_id, "tag_name": args.tag_name, "tag_value": value}),
2626
)?
2727
.print()
2828
}
2929

3030
#[derive(Args)]
3131
pub struct RemoveElementTagArgs {
32-
pub id: String,
33-
pub tag: String,
32+
pub element_id: i64,
33+
pub tag_name: String,
3434
}
3535

3636
pub fn remove_element_tag(args: &RemoveElementTagArgs) -> Result<()> {
37-
rpc::call("remove_element_tag", json!({"id": args.id,"tag": args.tag}))?.print()
38-
}
39-
40-
#[derive(Args)]
41-
pub struct AddElementCommentArgs {
42-
pub id: String,
43-
pub comment: String,
44-
}
45-
46-
pub fn add_element_comment(args: &AddElementCommentArgs) -> Result<()> {
4737
rpc::call(
48-
"add_element_comment",
49-
json!({"id": args.id,"comment": args.comment}),
38+
"remove_element_tag",
39+
json!({"element_id": args.element_id, "tag_name": args.tag_name}),
5040
)?
5141
.print()
5242
}
5343

44+
pub fn get_boosted_elements() -> Result<()> {
45+
rpc::call("get_boosted_elements", json!({}))?.print()
46+
}
47+
5448
#[derive(Args)]
5549
pub struct BoostElementArgs {
5650
pub id: String,
5751
pub days: i64,
5852
}
5953

6054
pub fn boost_element(args: &BoostElementArgs) -> Result<()> {
61-
rpc::call("boost_element", json!({"id": args.id,"days": args.days}))?.print()
55+
rpc::call("boost_element", json!({"id": args.id, "days": args.days}))?.print()
56+
}
57+
58+
pub fn paywall_get_boost_element_quote() -> Result<()> {
59+
rpc::call("paywall_get_boost_element_quote", json!({}))?.print()
6260
}
6361

6462
#[derive(Args)]
65-
pub struct GetBoostedElementsArgs {}
63+
pub struct PaywallBoostElementArgs {
64+
pub element_id: String,
65+
pub days: i64,
66+
}
6667

67-
pub fn get_boosted_elements(_: &GetBoostedElementsArgs) -> Result<()> {
68-
rpc::call("get_boosted_elements", json!({}))?.print()
68+
pub fn paywall_boost_element(args: &PaywallBoostElementArgs) -> Result<()> {
69+
rpc::call(
70+
"paywall_boost_element",
71+
json!({"element_id": args.element_id, "days": args.days}),
72+
)?
73+
.print()
74+
}
75+
76+
#[derive(Args)]
77+
pub struct AddElementCommentArgs {
78+
pub element_id: i64,
79+
pub comment: String,
80+
}
81+
82+
pub fn add_element_comment(args: &AddElementCommentArgs) -> Result<()> {
83+
rpc::call(
84+
"add_element_comment",
85+
json!({"element_id": args.element_id, "comment": args.comment}),
86+
)?
87+
.print()
6988
}
7089

7190
#[derive(Args)]

src/command/paywall.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,3 @@ pub fn paywall_add_element_comment(args: &PaywallAddElementCommentArgs) -> Resul
1919
)?
2020
.print()
2121
}
22-
23-
pub fn paywall_get_boost_element_quote() -> Result<()> {
24-
rpc::call("paywall_get_boost_element_quote", json!({}))?.print()
25-
}
26-
27-
#[derive(Args)]
28-
pub struct PaywallBoostElementArgs {
29-
pub element_id: String,
30-
pub days: i64,
31-
}
32-
33-
pub fn paywall_boost_element(args: &PaywallBoostElementArgs) -> Result<()> {
34-
rpc::call(
35-
"paywall_boost_element",
36-
json!({"element_id": args.element_id, "days": args.days}),
37-
)?
38-
.print()
39-
}

src/main.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ enum Commands {
4343
Search(command::common::SearchArgs),
4444
/// Fetch element by a numeric or OSM (node:12345) id. You can also use node=12345 format
4545
GetElement(command::element::GetElementArgs),
46-
/// 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
46+
/// 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
4747
SetElementTag(command::element::SetElementTagArgs),
48-
/// Remove tag from a certain element. You can use either numeric or OSM (node:12345) id
48+
/// Remove tag from a certain element
4949
RemoveElementTag(command::element::RemoveElementTagArgs),
50-
/// Add coment to a certain element. You can use either numeric or OSM (node:12345) id
51-
AddElementComment(command::element::AddElementCommentArgs),
50+
/// Get all boosted elements
51+
GetBoostedElements,
5252
/// Boost an element for a set number of days. You can use either numeric or OSM (node:12345) id
5353
BoostElement(command::element::BoostElementArgs),
54-
/// Get all boosted elements
55-
GetBoostedElements(command::element::GetBoostedElementsArgs),
54+
/// Get current element boost price in sats
55+
PaywallGetBoostElementQuote,
56+
/// Submit boost request to receive an invoice
57+
PaywallBoostElement(command::element::PaywallBoostElementArgs),
58+
/// Add coment to a certain element
59+
AddElementComment(command::element::AddElementCommentArgs),
5660
/// 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
5761
SyncElements(command::element::SyncElementsArgs),
5862
/// Generate icon:android tags for a specific element id range
@@ -85,10 +89,6 @@ enum Commands {
8589
PaywallGetAddElementCommentQuote,
8690
/// Submit comment to receive an invoice
8791
PaywallAddElementComment(command::paywall::PaywallAddElementCommentArgs),
88-
/// Get current element boost price in sats
89-
PaywallGetBoostElementQuote,
90-
/// Submit boost request to receive an invoice
91-
PaywallBoostElement(command::paywall::PaywallBoostElementArgs),
9292
}
9393

9494
type Result<T> = std::result::Result<T, Box<dyn Error>>;
@@ -137,9 +137,13 @@ fn main() -> Result<()> {
137137
Commands::GetElement(args) => element::get_element(args),
138138
Commands::SetElementTag(args) => element::set_element_tag(args),
139139
Commands::RemoveElementTag(args) => element::remove_element_tag(args),
140-
Commands::AddElementComment(args) => element::add_element_comment(args),
140+
Commands::GetBoostedElements => element::get_boosted_elements(),
141141
Commands::BoostElement(args) => element::boost_element(args),
142-
Commands::GetBoostedElements(args) => element::get_boosted_elements(args),
142+
Commands::PaywallGetBoostElementQuote => {
143+
command::element::paywall_get_boost_element_quote()
144+
}
145+
Commands::PaywallBoostElement(args) => command::element::paywall_boost_element(args),
146+
Commands::AddElementComment(args) => element::add_element_comment(args),
143147
Commands::SyncElements(args) => element::sync_elements(args),
144148
Commands::GenerateElementIcons(args) => element::generate_element_icons(args),
145149
Commands::GenerateElementCategories(args) => element::generate_element_categories(args),
@@ -166,10 +170,6 @@ fn main() -> Result<()> {
166170
Commands::PaywallAddElementComment(args) => {
167171
command::paywall::paywall_add_element_comment(args)
168172
}
169-
Commands::PaywallGetBoostElementQuote => {
170-
command::paywall::paywall_get_boost_element_quote()
171-
}
172-
Commands::PaywallBoostElement(args) => command::paywall::paywall_boost_element(args),
173173
}
174174
}
175175

src/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn call(method: &str, mut params: Value) -> Result<RpcResponse> {
4949
println!("{}", serde_json::to_string(&args)?.to_colored_json_auto()?);
5050
}
5151
let response = ureq::post(api_url)
52-
.header("Content-Type", "application/json")
52+
//.header("Content-Type", "application/json")
5353
.send_json(args)?
5454
.body_mut()
5555
.read_to_string()?;

0 commit comments

Comments
 (0)