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
use crate::geocoding::reverse::ReverseRequest;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};

impl<'a> ReverseRequest<'a> {
    /// Builds the query string for the Google Maps Geocoding API based on the
    /// input provided by the client.
    ///
    /// ## Arguments
    ///
    /// This method accepts no arguments.

    pub fn build(&mut self) -> &'a mut ReverseRequest {
        // This section builds the "required parameters" portion of the query
        // string:

        let mut query = format!(
            "key={}&latlng={}",
            self.client.key,
            String::from(&self.latlng),
        ); // format!

        // This section builds the "optional parameters" portion of the query
        // string:

        // Language key/value pair:
        if let Some(language) = &self.language {
            query.push_str("&language=");
            query.push_str(&String::from(language));
        } // if

        // Location type(s) key/value pair:
        if !self.location_types.is_empty() {
            query.push_str("&location_type=");
            query.push_str(
                &utf8_percent_encode(
                    &self
                        .location_types
                        .iter()
                        .map(String::from)
                        .collect::<Vec<String>>()
                        .join("|"),
                    NON_ALPHANUMERIC,
                )
                .to_string(),
            ); // push_str
        } // if

        // Result type(s) key/value pair:
        if !self.result_types.is_empty() {
            query.push_str("&result_type=");
            query.push_str(
                &utf8_percent_encode(
                    &self
                        .result_types
                        .iter()
                        .map(String::from)
                        .collect::<Vec<String>>()
                        .join("|"),
                    NON_ALPHANUMERIC,
                )
                .to_string(),
            ); // push_str
        } // if

        // Set query string in ReverseRequest struct.
        self.query = Some(query);

        // Return modified ReverseRequest struct to caller.
        self
    } // fn
} // impl