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
use error::Result;
use api::{self, ResourceState, AccessToken};
use http;
#[derive(Debug, RustcDecodable)]
pub struct Gear {
pub id: String,
pub primary: bool,
pub name: String,
pub distance: f32,
pub resource_state: ResourceState,
pub brand_name: Option<String>,
pub model_name: Option<String>,
pub frame_type: Option<FrameType>,
pub description: Option<String>,
}
impl Gear {
pub fn get(token: &AccessToken, id: String) -> Result<Gear> {
let url = api::v3(token, format!("gear/{}", id));
http::get::<Gear>(&url[..])
}
}
#[derive(Debug, RustcDecodable)]
#[allow(non_camel_case_types)]
pub enum FrameType {
MTB,
Cross,
Road,
TimeTrial
}
#[cfg(feature = "api_test")]
#[cfg(test)]
mod api_tests {
use super::Gear;
use api::AccessToken;
#[test]
#[test]
#[test]
fn get_gear() {
let id = "g2164144".to_string();
let token = AccessToken::new_from_env().unwrap();
let gear = Gear::get(&token,id);
println!("{:?}",gear);
}
}