Crate spaceapi [] [src]

Space API definitions and serialization.

This crate contains all data-related definitions that are present in the Space API (http://spaceapi.net/). It also handles serializing that data to JSON by implementing the ToJson trait for all structs.

The currently supported Space API version is 0.13. It is not yet fully implemented.

Examples

Serializing

You can create a new Status instance by using the new() constructor method.

To serialize the status to Json, use the ToJson trait implementation. You can then create a string from the resulting object.

extern crate serde;
extern crate serde_json;
extern crate spaceapi;

use spaceapi::{Status, StatusBuilder, Location, Contact};

let status = StatusBuilder::new("coredump")
    .logo("https://www.coredump.ch/logo.png")
    .url("https://www.coredump.ch/")
    .location(
        Location {
            address: None,
            lat: 47.22936,
            lon: 8.82949,
        })
    .contact(
        Contact {
            irc: Some("irc://freenode.net/#coredump".into()),
            twitter: Some("@coredump_ch".into()),
            foursquare: Some("525c20e5498e875d8231b1e5".into()),
            email: Some("danilo@coredump.ch".into()),
            ..Default::default()
        })
    .add_issue_report_channel("email")
    .add_issue_report_channel("twitter")
    .build()
    .expect("Creating status failed");
let serialized = serde_json::to_string(&status).unwrap();
let deserialized: Status = serde_json::from_str(&serialized).unwrap();

Deserializing

You can deserialize any struct of the Space API through rustc_serialize::json:

extern crate serde;
extern crate serde_json;
extern crate spaceapi;

use spaceapi::Location;

let location = "{\"lat\": 47.22936, \"lon\": 8.82949}";
let decoded: Location = serde_json::from_str(location).unwrap();
println!("{:?}", decoded);

// Output:
// Location { address: None, lat: 47.22936000000001, lon: 8.829490000000002 }

Reexports

pub use sensors::SensorTemplate;
pub use sensors::Sensors;
pub use sensors::TemperatureSensor;
pub use sensors::PeopleNowPresentSensor;

Modules

sensors

Module defining all sensor related structures.

Structs

Cache
Contact
Event
Feed
Feeds
GoogleContact
Icon
Keymaster
Location
RadioShow
Spacefed
State
Status

The main Space API status object.

StatusBuilder

Functions

get_version

Return own crate version. Used in API responses.