[][src]Crate spaceapi

SpaceAPI definitions and serialization.

This crate contains all data-related definitions that are present in the SpaceAPI. 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 SpaceAPI version is 0.13. It is not yet fully implemented.

If you want to implement a SpaceAPI 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.

use serde_json;
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 SpaceAPI through Serde:

use serde_json;
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 }

Re-exports

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

Modules

sensors

Module defining all sensor related structures.

Structs

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

The main SpaceAPI status object.

StatusBuilder

Builder for the Status object.

Stream

Enums

IssueReportChannel

Functions

get_version

Return own crate version. Used in API responses.