| 1 | use super::BaseApi; |
| 2 | use crate::{Client, Query, Location}; |
| 3 | |
| 4 | pub struct SearchApi<'a> { |
| 5 | client: &'a Client, |
| 6 | query: Option<Query>, |
| 7 | } |
| 8 | |
| 9 | impl<'a> SearchApi<'a> { |
| 10 | /// Use [`crate::Client`] |
| 11 | pub fn new(client: &'a Client) -> Self { |
| 12 | Self { |
| 13 | client, |
| 14 | query: None |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | /// Set up the query |
| 19 | /// |
| 20 | /// Query parameter based on which data is sent back |
| 21 | pub fn query(mut self, query: Query) -> Self { |
| 22 | self.query = Some(query); |
| 23 | self |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | impl<'a> BaseApi<'a> for SearchApi<'a> { |
| 28 | type Model = Vec<Location>; |
| 29 | |
| 30 | fn path(&self) -> &str { |
| 31 | "search" |
| 32 | } |
| 33 | |
| 34 | fn client(&self) -> &'a Client { |
| 35 | self.client |
| 36 | } |
| 37 | |
| 38 | fn params(&self) -> Vec<(&str, String)> { |
| 39 | let query: &Query = self.query.as_ref().unwrap(); |
| 40 | vec![("key" , self.client.api_key.clone()), ("q" , query.to_string())] |
| 41 | } |
| 42 | } |
| 43 | |