google_place_api/place/
request.rs

1use crate::SearchParams;
2use clap::ArgEnum;
3use strum_macros::Display;
4
5#[derive(Clone, ArgEnum, Display, Debug)]
6#[strum(serialize_all = "lowercase")]
7pub enum InputType {
8    TextQuery,
9    PhoneNumber,
10}
11
12#[derive(Debug, Default)]
13pub struct Request {
14    pub token: String,
15    pub input: String,
16    pub input_type: String,
17    pub fields: Vec<Field>,
18}
19
20#[derive(Clone, ArgEnum, Display, Debug)]
21#[strum(serialize_all = "snake_case")]
22pub enum Field {
23    // AddressComponent,
24    // AdrAddress,
25    // FormattedPhoneNumber,
26    // InternationalPhoneNumber,
27    // Review,
28    // Type,
29    // Url,
30    // UtcOffset,
31    // Website,
32    // Vicinity,
33    BusinessStatus,
34    FormattedAddress,
35    Geometry,
36    Icon,
37    IconMaskBaseUri,
38    IconBackgroundColor,
39    Name,
40    Photo,
41    PlaceId,
42    PlusCode,
43
44    OpeningHours,
45
46    PriceLevel,
47    Rating,
48    UserRatingsTotal,
49}
50
51impl Request {
52    pub fn add_field(&mut self, field: Field) -> &mut Self {
53        self.fields.push(field);
54
55        self
56    }
57
58    pub fn add_fields(&mut self, fields: Vec<Field>) -> &mut Self {
59        fields.into_iter().for_each(|field| {
60            self.add_field(field);
61        });
62
63        self
64    }
65}
66
67impl SearchParams for Request {
68    fn get_params(&self) -> Vec<(String, String)> {
69        let mut params = vec![];
70
71        params.push(("key".to_owned(), self.token.to_owned()));
72
73        params.push(("input".to_owned(), self.input.clone()));
74
75        params.push(("inputtype".to_owned(), self.input_type.clone()));
76
77        if self.fields.len() > 0 {
78            let fields = self
79                .fields
80                .iter()
81                .map(|field| field.to_string())
82                .collect::<Vec<_>>()
83                .join(",");
84
85            params.push(("fields".to_owned(), fields));
86        }
87
88        params
89    }
90}