artifact-app 0.6.3

Artifact is a design doc tool made for developers. It allows anyone to easily write and link their design docs both to each other and to source code, making it easy to track how complete their project is. Documents are revision controllable, can be rendered as a static web page and have a full suite of command line tools for searching, formatting and displaying them.
Documentation

use dev_prefix::*;
use jsonrpc_core::{IoHandler, RpcMethodSync, Params, Error as RpcError};
use jsonrpc_core;
use serde_json;

use core::prefix::*;

use super::ARTIFACTS;

/// the rpc initializer that implements the API spec
fn init_rpc_handler() -> IoHandler {
    // partof: #SPC-rpc-artifacts
    let mut handler = IoHandler::new();
    handler.add_method("GetArtifacts", GetArtifacts);
    // TODO: update is disabled until it is feature complete
    // (specifically security needs to be added)
    // handler.add_method("UpdateArtifacts", update::UpdateArtifacts);
    handler
}

lazy_static! {
    pub static ref RPC_HANDLER: IoHandler = init_rpc_handler();
}

/// `GetArtifacts` API Handler
struct GetArtifacts;
impl RpcMethodSync for GetArtifacts {
    fn call(&self, _: Params) -> result::Result<jsonrpc_core::Value, RpcError> {
        info!("GetArtifacts called");
        let locked = ARTIFACTS.lock().unwrap();
        let artifacts: &Vec<ArtifactData> = locked.as_ref();
        let out = {
            // FIXME: when jsonrpc-core uses serde 0.9
            let value = serde_json::to_value(artifacts).unwrap();
            let s = serde_json::to_string(&value).unwrap();
            jsonrpc_core::Value::from_str(&s).unwrap()
        };
        Ok(out)
    }
}