add code
This commit is contained in:
parent
7bf6daa598
commit
63516bf7e6
@ -7,3 +7,6 @@ edition = "2018"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
reqwest = { version = "0.10.4", features = ["json", "blocking"] }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
50
src/main.rs
50
src/main.rs
@ -1,3 +1,49 @@
|
|||||||
fn main() {
|
use serde::Deserialize;
|
||||||
println!("Hello, world!");
|
use std::{thread, time};
|
||||||
|
|
||||||
|
extern crate reqwest;
|
||||||
|
|
||||||
|
const API_URL: &str = "https://status.robertsspaceindustries.com/";
|
||||||
|
|
||||||
|
const STATUS_URL: &str = "https://status.robertsspaceindustries.com/static/content/api/v0/systems.en.json";
|
||||||
|
const INCIDENTS_URL: &str = "https://status.robertsspaceindustries.com/static/content/api/v0/incidents/timeline.en.json";
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
struct Status {
|
||||||
|
name: String,
|
||||||
|
status: String,
|
||||||
|
order: u8,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_incidents() -> Result<(),reqwest::Error> {
|
||||||
|
// TODO add parsing for the data this returns
|
||||||
|
let res = reqwest::blocking::get(INCIDENTS_URL)?;
|
||||||
|
let data = res.text()?;
|
||||||
|
// let pu = &data[1];
|
||||||
|
// let ea = &data[2];
|
||||||
|
//println!("Persistent Universe: {}\nEA: {}", pu.status, ea.status);
|
||||||
|
dbg!(data);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_status() -> Result<(),reqwest::Error> {
|
||||||
|
let res = reqwest::blocking::get(STATUS_URL)?;
|
||||||
|
let data = res.json::<Vec<Status>>()?;
|
||||||
|
let pu = &data[1];
|
||||||
|
let ea = &data[2];
|
||||||
|
println!("Persistent Universe: {}\nEA: {}", pu.status, ea.status);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
match get_status(){
|
||||||
|
Err(e) => println!("{:?}", e),
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
// match get_incidents(){
|
||||||
|
// Err(e) => println!("{:?}", e),
|
||||||
|
// _ => ()
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user