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 rustc_serialize;
extern crate spaceapi;

use spaceapi::{Status, Location, Contact};
use spaceapi::optional::Optional::{Absent, Value};
use rustc_serialize::json::ToJson;

let status = Status::new(
    "coredump",
    "https://www.coredump.ch/logo.png",
    "https://www.coredump.ch/",
    Location {
        address: Value(
            "Spinnereistrasse 2, 8640 Rapperswil, Switzerland".into()),
        lat: 47.22936,
        lon: 8.82949,
    },
    Contact {
        phone: Absent,
        sip: Absent,
        keymasters: Absent,
        irc: Value("irc://freenode.net/#coredump".into()),
        twitter: Value("@coredump_ch".into()),
        facebook: Absent,
        google: Absent,
        identica: Absent,
        foursquare: Value("525c20e5498e875d8231b1e5".into()),
        email: Value("danilo@coredump.ch".into()),
        ml: Absent,
        jabber: Absent,
        issue_mail: Absent,
    },
    vec![
        "email".into(),
        "twitter".into(),
    ],
);

let jsonstatus = status.to_json();
let stringstatus = jsonstatus.to_string();

Deserializing

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

extern crate rustc_serialize;
extern crate spaceapi;

use rustc_serialize::json;
use spaceapi::Location;

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

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

Reexports

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

Modules

optional

Implementation of the custom Optional type. See Optional docs for more information.

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.

Functions

get_version

Return own crate version. Used in API responses.