Skip to content

Commit

Permalink
Add boost-element command
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Aug 29, 2024
1 parent e1b71c1 commit 5424f0b
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ fn main() {
.unwrap();
println!("Saved {token} as a token for all future calls");
}
"get-area" => {
"get-element" => {
let id = args[2].clone();
let client = reqwest::blocking::Client::new();
let args = json!(
{"jsonrpc": "2.0", "method": "getarea", "params": {"token": token, "id": id}, "id": 1}
{"jsonrpc": "2.0", "method": "getelement", "params": {"token": token, "id": id}, "id": 1}
);
println!("{args}");
let mut res = client
let res = client
.post("https://api.btcmap.org/rpc")
.body(serde_json::to_string(&args).unwrap())
.send()
Expand All @@ -76,23 +76,35 @@ fn main() {
.get("result")
.unwrap()
.clone();
res.get_mut("tags")
let res = serde_json::to_string_pretty(&res).unwrap();
println!("{}", res);
}
"boost-element" => {
let id = args[2].clone();
let days: i64 = args[3].parse().unwrap();
let client = reqwest::blocking::Client::new();
let args = json!(
{"jsonrpc":"2.0","method":"boostelement","params":{"token":token,"id":id,"days":days},"id":1}
);
println!("{args}");
let res = client
.post("https://api.btcmap.org/rpc")
.body(serde_json::to_string(&args).unwrap())
.send()
.unwrap()
.as_object_mut()
.json::<Map<String, Value>>()
.unwrap()
.remove("geo_json");
.get("result")
.unwrap()
.clone();
let res = serde_json::to_string_pretty(&res).unwrap();
println!("{}", res);
}
"set-area-tag" => {
"get-area" => {
let id = args[2].clone();
let name = args[3].clone();
let value = args[4].clone();
println!("{}", value);
let value: Value = serde_json::from_str(&value).unwrap();
let client = reqwest::blocking::Client::new();
let args = json!(
{"jsonrpc": "2.0", "method": "setareatag", "params": {"token": token, "id": id, "name": name, "value": value}, "id": 1}
{"jsonrpc": "2.0", "method": "getarea", "params": {"token": token, "id": id}, "id": 1}
);
println!("{args}");
let mut res = client
Expand All @@ -113,12 +125,15 @@ fn main() {
let res = serde_json::to_string_pretty(&res).unwrap();
println!("{}", res);
}
"remove-area-tag" => {
"set-area-tag" => {
let id = args[2].clone();
let tag = args[3].clone();
let name = args[3].clone();
let value = args[4].clone();
println!("{}", value);
let value: Value = serde_json::from_str(&value).unwrap();
let client = reqwest::blocking::Client::new();
let args = json!(
{"jsonrpc": "2.0", "method": "removeareatag", "params": {"token": token, "id": id, "tag": tag}, "id": 1}
{"jsonrpc": "2.0", "method": "setareatag", "params": {"token": token, "id": id, "name": name, "value": value}, "id": 1}
);
println!("{args}");
let mut res = client
Expand All @@ -139,14 +154,15 @@ fn main() {
let res = serde_json::to_string_pretty(&res).unwrap();
println!("{}", res);
}
"get-element" => {
"remove-area-tag" => {
let id = args[2].clone();
let tag = args[3].clone();
let client = reqwest::blocking::Client::new();
let args = json!(
{"jsonrpc": "2.0", "method": "getelement", "params": {"token": token, "id": id}, "id": 1}
{"jsonrpc": "2.0", "method": "removeareatag", "params": {"token": token, "id": id, "tag": tag}, "id": 1}
);
println!("{args}");
let res = client
let mut res = client
.post("https://api.btcmap.org/rpc")
.body(serde_json::to_string(&args).unwrap())
.send()
Expand All @@ -156,6 +172,11 @@ fn main() {
.get("result")
.unwrap()
.clone();
res.get_mut("tags")
.unwrap()
.as_object_mut()
.unwrap()
.remove("geo_json");
let res = serde_json::to_string_pretty(&res).unwrap();
println!("{}", res);
}
Expand Down

0 comments on commit 5424f0b

Please sign in to comment.