fix installation request

This commit is contained in:
Yuri Iozzelli 2020-09-27 22:15:19 +02:00
parent 3a67a50671
commit 76bbb96490
3 changed files with 40 additions and 14 deletions

36
Cargo.lock generated
View File

@ -26,6 +26,8 @@ dependencies = [
"dotenv",
"isahc",
"openssl",
"serde",
"serde_json",
]
[[package]]
@ -192,9 +194,9 @@ dependencies = [
[[package]]
name = "isahc"
version = "0.9.8"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c7ae3a678e7d3bf240bfecc3ffda276db5db61e160c7639a196a1d944b2a5d4"
checksum = "4ecedb6ed2615f66b14d9790bad67f8d45dfaffe01464681fb868fe90ca20c41"
dependencies = [
"bytes",
"crossbeam-channel",
@ -325,18 +327,18 @@ dependencies = [
[[package]]
name = "pin-project"
version = "0.4.23"
version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca4433fff2ae79342e497d9f8ee990d174071408f28f726d6d83af93e58e48aa"
checksum = "f48fad7cfbff853437be7cf54d7b993af21f53be7f0988cbfe4a51535aa77205"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "0.4.23"
version = "0.4.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c0e815c3ee9a031fdf5af21c10aa17c573c9c6a566328d99e3936c34e36461f"
checksum = "24c6d293bdd3ca5a1697997854c6cf7855e43fb6a0ba1c47af57a5bcafd158ae"
dependencies = [
"proc-macro2",
"quote",
@ -357,9 +359,9 @@ checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
[[package]]
name = "proc-macro2"
version = "1.0.21"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
checksum = "51ef7cd2518ead700af67bf9d1a658d90b6037d77110fd9c0445429d0ba1c6c9"
dependencies = [
"unicode-xid",
]
@ -400,6 +402,20 @@ name = "serde"
version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
@ -444,9 +460,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.41"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6690e3e9f692504b941dc6c3b188fd28df054f7fb8469ab40680df52fdcc842b"
checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228"
dependencies = [
"proc-macro2",
"quote",

View File

@ -11,3 +11,5 @@ anyhow = "1.0.32"
isahc = { version = "0.9.8", features = ["json"] }
dotenv = "0.15.0"
openssl = "0.10.30"
serde_json = "1.0.57"
serde = { version = "1.0.116", features = ["derive"] }

View File

@ -1,19 +1,27 @@
use anyhow::Result;
use isahc::prelude::*;
use serde::Serialize;
use openssl::pkey::PKey;
const BASE: &str = "https://public-api.sandbox.bunq.com/v1/";
#[derive(Serialize)]
struct Installation<'a> {
client_public_key: &'a str,
}
fn main() -> Result<()> {
dotenv::dotenv()?;
let api_key = std::env::var("API_KEY")?;
let pem = include_bytes!("../private.pem");
let keypair = PKey::private_key_from_pem(pem)?;
let pem_private = include_bytes!("../private.pem");
let pem_public = include_bytes!("../public.pem");
let keypair = PKey::private_key_from_pem(pem_private)?;
let mut response = isahc::post(format!("{}installation",BASE), format!("{{'client_public_key': '{}'}}", std::str::from_utf8(pem)?))?;
let client_public_key = std::str::from_utf8(pem_public)?;
let body = Installation { client_public_key: &client_public_key};
let mut response = isahc::post(format!("{}installation",BASE), serde_json::to_string(&body)?)?;
println!("{}", response.text()?);
Ok(())
}