elastic_responses/
ping.rs

1/*! 
2Response types for a cluster ping request.
3*/
4
5use parsing::{HttpResponseHead, IsOk, MaybeOkResponse, ResponseBody, Unbuffered};
6use error::*;
7
8/** Response for a cluster ping request. */
9#[derive(Deserialize, Debug)]
10pub struct PingResponse {
11    name: String,
12    cluster_name: String,
13    tagline: String,
14    version: ClusterVersion,
15}
16
17#[doc(hidden)]
18#[derive(Deserialize, Debug)]
19pub struct ClusterVersion {
20    number: String,
21    build_hash: String,
22    build_date: String,
23    build_snapshot: bool,
24    lucene_version: String,
25}
26
27impl PingResponse {
28    /** The name of the pinged node. */
29    pub fn name(&self) -> &str {
30        &self.name
31    }
32
33    /** The name of the cluster the pinged node belongs to. */
34    pub fn cluster_name(&self) -> &str {
35        &self.cluster_name
36    }
37
38    /** The Elasticsearch version metadata. */
39    pub fn version(&self) -> &ClusterVersion {
40        &self.version
41    }
42}
43
44impl ClusterVersion {
45    /** The builder number. */
46    pub fn number(&self) -> &str {
47        &self.number
48    }
49
50    /** The build hash. */
51    pub fn hash(&self) -> &str {
52        &self.build_hash
53    }
54
55    /** The build date. */
56    pub fn date(&self) -> &str {
57        &self.build_date
58    }
59
60    /** Whether or not the build is a snapshot. */
61    pub fn snapshot(&self) -> bool {
62        self.build_snapshot
63    }
64
65    /** The underlying Lucene version. */
66    pub fn lucene_version(&self) -> &str {
67        &self.lucene_version
68    }
69}
70
71impl IsOk for PingResponse {
72    fn is_ok<B: ResponseBody>(head: HttpResponseHead, body: Unbuffered<B>) -> Result<MaybeOkResponse<B>, ParseResponseError> {
73        match head.status() {
74            200...299 => Ok(MaybeOkResponse::ok(body)),
75            _ => Ok(MaybeOkResponse::err(body)),
76        }
77    }
78}