Skip to content

Commit

Permalink
✨ Update GitHub profile location
Browse files Browse the repository at this point in the history
  • Loading branch information
malted committed Feb 8, 2024
1 parent 933b5d0 commit 66fff20
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
25 changes: 13 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ humantime = "2.1.0"
openssl = { version = "0.10.61", features = ["vendored"] }
parking_lot = "0.12.1"
rand = "0.8.5"
reqwest = "0.11.22"
reqwest = { version = "0.11.22", features = ["blocking", "json"] }
rocket = { version = "0.5.0", features = ["json"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.113"
14 changes: 12 additions & 2 deletions src/api/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::MaltedState;
use parking_lot::RwLock;
use reqwest::header::{ACCEPT, AUTHORIZATION};
use rocket::{serde::json::Json, State};

#[derive(serde::Serialize)]
Expand Down Expand Up @@ -51,15 +52,24 @@ pub fn patch_location(
*malted_state.write() = MaltedState {
lat,
lon,
city,
country,
city: city.clone(),
country: country.clone(),
timestamp,
battery,
};
} else {
return err("Invalid timestamp");
}

let github_pat = std::env::var("github_pat").unwrap();
let _ = reqwest::blocking::Client::new()
.patch("https://api.github.com/user")
.header(ACCEPT, "application/vnd.github+json")
.header(AUTHORIZATION, format!("Bearer {}", github_pat))
.header("X-GitHub-Api-Version", "2022-11-28")
.json(&serde_json::json!({ "location": format!("{}, {}", city, country) }))
.send();

Json(ApiResponse {
success: true,
message: "Location saved".to_string(),
Expand Down

0 comments on commit 66fff20

Please sign in to comment.