1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*! 
Response types for a cluster ping request.
*/

use parsing::{IsOk, HttpResponseHead, ResponseBody, Unbuffered, MaybeOkResponse};
use error::*;

/** Response for a cluster ping request. */
#[derive(Deserialize, Debug)]
pub struct PingResponse {
    name: String,
    cluster_name: String,
    tagline: String,
    version: ClusterVersion,
}

#[doc(hidden)]
#[derive(Deserialize, Debug)]
pub struct ClusterVersion {
    number: String,
    build_hash: String,
    build_date: String,
    build_snapshot: bool,
    lucene_version: String
}

impl PingResponse {
    /** The name of the pinged node. */
    pub fn name(&self) -> &str {
        &self.name
    }

    /** The name of the cluster the pinged node belongs to. */
    pub fn cluster_name(&self) -> &str {
        &self.cluster_name
    }

    /** The Elasticsearch version metadata. */
    pub fn version(&self) -> &ClusterVersion {
        &self.version
    }
}

impl ClusterVersion {
    /** The builder number. */
    pub fn number(&self) -> &str {
        &self.number
    }

    /** The build hash. */
    pub fn hash(&self) -> &str {
        &self.build_hash
    }

    /** The build date. */
    pub fn date(&self) -> &str {
        &self.build_date
    }

    /** Whether or not the build is a snapshot. */
    pub fn snapshot(&self) -> bool {
        self.build_snapshot
    }

    /** The underlying Lucene version. */
    pub fn lucene_version(&self) -> &str {
        &self.lucene_version
    }
}

impl IsOk for PingResponse {
    fn is_ok<B: ResponseBody>(head: HttpResponseHead, body: Unbuffered<B>) -> Result<MaybeOkResponse<B>, ParseResponseError> {
        match head.status() {
            200...299 => Ok(MaybeOkResponse::ok(body)),
            _ => Ok(MaybeOkResponse::err(body)),
        }
    }
}