Crate spaceapi [] [src]

Space API definitions and serialization.

This crate contains all data-related definitions that are present in the Space API. It also handles serializing and deserializing of that data from/to JSON by implementing the Serde Serialize and Deserialize traits for all structs.

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

If you want to implement a Space API server on top of these types, you might want to take a look at the spaceapi_server crate.

This library requires Rust 1.20.0 or newer.

Examples

Serializing

You can create a new Status instance by using the StatusBuilder.

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

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

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(IssueReportChannel::Email)
    .add_issue_report_channel(IssueReportChannel::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 Serde:

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

Builder for the Status object.

Enums

IssueReportChannel

Functions

get_version

Return own crate version. Used in API responses.