Crates.io | open_notify |
lib.rs | open_notify |
version | 0.1.9 |
source | src |
created_at | 2021-05-25 18:02:40.638453 |
updated_at | 2021-06-06 15:32:50.418562 |
description | fetches information about spotting International Space Station from open-notify.org |
homepage | https://open_notify.thats-software.com |
repository | |
max_upload_size | |
id | 401929 |
size | 21,629 |
Fetch information about spotting International Space Station from open-notify.org.
...is a rust crate which lets you easily access current spotting information from open-notify.org. This is an unofficial extension I have made to learn rust a little but I hope you have fun with it.
First add this crate to your dependencies in you Cargo.toml
file:
[dependencies]
open_notify = "0.1.7"
Then use the crate in your rust source file by calling open_notify::init()
which returns a receiver object.
You can then use this receiver object to call open_notify::update()
to get ISS spotting updates like in the following example:
extern crate open_notify;
use open_notify::{find_current, init, update};
fn main() {
// start our observatory via OWM
let receiver = &init(52.520008, 13.404954, 0.0, 90);
loop {
match update(receiver) {
Some(response) => match response {
Ok(spots) => println!(
"ISS is {}",
match find_current(spots,None) {
Some(_s) => "visible",
None => "invisible",
}
),
Err(e) => println!("Could not fetch ISS spotting info because: {}", e),
},
None => (),
}
}
}
init()
spawns a thread which then will periodically poll api.open-notify.org for the current ISS position.
You then can use update()
to ask for it.
There are three possible kinds of result you get from update()
which you will have to face:
None
update()
returns None
if there is currently no new update available.
Which means: You wont get any update twice!
In other words: update()
is not caching the last update for you.
Vec<Spot>
If a new update was downloaded by the polling thread update()
returns some Vec<Spot>
object.
Vec<Spot>
includes a list of spotting events.
Err
On error update()
returns some String
object which includes a brief error description.
Errors may occur...
Err
which includes exactly the String "loading..."
(predefined in open_notify::LOADING
).500 Internal Server Error
if an invalid API key was used).If you just need the current ISS spotting events just once you may use the method spot()
which envelopes init()
and update()
into one single synchronous or asynchronous call.
After the first successful spotting update the spawned thread will stop immediately and you get the result in return.
extern crate open_notify;
use open_notify::blocking::spot;
fn main() {
// start our observatory via OWM
match &spot(52.520008, 13.404954, 0.0) {
Ok(spots) => println!(
"ISS is {}",
match find_current(spots,None) {
Some(_s) => "visible",
None => "invisible",
}
),
Err(e) => println!("Could not fetch ISS spotting info because: {}", e),
}
}
There is a blocking and a non-blocking variant of spot()
:
open_notify::blocking::spot
which wont return until there is a new update.open_notify::spot
and asynchronously await the result until there is any.Beside this introduction there is a reference documentation which can be found here.
This README tastes better at open_notify.thats-software.com.
For the source code see this repository at github.com.
Published at crates.io.
open_notify is licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)