Reorganised price info lookup
This helped stop my eyes from hurting. Further simplification
This commit is contained in:
parent
6399c0a2c7
commit
40b97045f0
@ -11,29 +11,19 @@ pub struct PriceInfo {
|
|||||||
impl PriceInfo {
|
impl PriceInfo {
|
||||||
pub fn get() -> Option<PriceInfo> {
|
pub fn get() -> Option<PriceInfo> {
|
||||||
let mut body = String::new();
|
let mut body = String::new();
|
||||||
// TODO: actually bother dicking around with the errors and make it proper.
|
// TODO: Handle each error type properly
|
||||||
match match match Client::new()
|
Client::new()
|
||||||
.get("http://api.etherscan.io/api?module=stats&action=ethprice")
|
.get("http://api.etherscan.io/api?module=stats&action=ethprice")
|
||||||
.header(Connection::close())
|
.header(Connection::close())
|
||||||
.send() {
|
.send().ok()
|
||||||
Err(_) => { return None; },
|
.and_then(|mut s| s.read_to_string(&mut body).ok())
|
||||||
Ok(mut s) => s.read_to_string(&mut body),
|
.and_then(|_| Json::from_str(&body).ok())
|
||||||
} {
|
.and_then(|json| json.find_path(&["result", "ethusd"])
|
||||||
Err(_) => { return None; },
|
.and_then(|obj| match obj {
|
||||||
_ => { Json::from_str(&body) }
|
&Json::String(ref s) => Some(PriceInfo {
|
||||||
} {
|
ethusd: FromStr::from_str(&s).unwrap()
|
||||||
Err(_) => { return None; },
|
}),
|
||||||
Ok(json) => {
|
_ => None
|
||||||
let ethusd: f32 = if let Some(&Json::String(ref s)) = json.find_path(&["result", "ethusd"]) {
|
}))
|
||||||
FromStr::from_str(&s).unwrap()
|
|
||||||
} else {
|
|
||||||
return None;
|
|
||||||
};
|
|
||||||
Some(PriceInfo {
|
|
||||||
ethusd: ethusd,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user