2020-09-27 13:17:59 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use isahc::prelude::*;
|
2020-09-27 20:15:19 +00:00
|
|
|
use serde::Serialize;
|
2020-09-27 13:17:59 +00:00
|
|
|
use openssl::pkey::PKey;
|
|
|
|
|
|
|
|
const BASE: &str = "https://public-api.sandbox.bunq.com/v1/";
|
|
|
|
|
2020-09-27 20:15:19 +00:00
|
|
|
#[derive(Serialize)]
|
|
|
|
struct Installation<'a> {
|
|
|
|
client_public_key: &'a str,
|
|
|
|
}
|
|
|
|
|
2020-09-27 13:17:59 +00:00
|
|
|
fn main() -> Result<()> {
|
|
|
|
dotenv::dotenv()?;
|
|
|
|
|
|
|
|
let api_key = std::env::var("API_KEY")?;
|
|
|
|
|
2020-09-27 20:15:19 +00:00
|
|
|
let pem_private = include_bytes!("../private.pem");
|
|
|
|
let pem_public = include_bytes!("../public.pem");
|
|
|
|
let keypair = PKey::private_key_from_pem(pem_private)?;
|
2020-09-27 13:17:59 +00:00
|
|
|
|
2020-09-27 20:15:19 +00:00
|
|
|
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)?)?;
|
2020-09-27 13:17:59 +00:00
|
|
|
println!("{}", response.text()?);
|
|
|
|
Ok(())
|
|
|
|
}
|