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
72
73
74
75
76
77
78
79
80
81
82
83
use crate::endpoints::text_search::TextSearch;
use crate::endpoints::nearby_search::NearbySearch;
use crate::endpoints::place_details::PlaceDetails;
use reqwest::Client;
use crate::endpoints::find_place::FindPlace;
use crate::endpoints::place_photos::PlacePhotos;
pub struct PlaceSearch<'a> {
api_key: String,
client: &'a Client,
}
impl<'a> PlaceSearch<'a> {
/// Constructs a new `PlaceSearch` instance.
///
/// ## DO NOT USE THIS ALONE, USE THE `GooglePlacesAPI` STRUCT.
///
/// # Arguments
///
/// * `api_key` - A string slice that holds the API key for accessing the Google Places API.
/// * `client` - A reference to a `reqwest::Client` for executing HTTP requests.
///
/// # Returns
///
/// A new instance of `PlaceSearch`.
pub fn new(api_key: &str, client: &'a Client) -> Self {
Self {
api_key: String::from(api_key),
client,
}
}
/// Returns a new `TextSearch` instance that can be used to execute a
/// Text Search request.
///
/// # Returns
///
/// A new instance of `TextSearch`.
pub fn text_search(&mut self) -> TextSearch {
let text_search_object: TextSearch = TextSearch::new(self.api_key.as_str(), self.client);
text_search_object
}
/// Returns a new `NearbySearch` instance that can be used to execute a
/// Nearby Search request.
///
/// # Returns
///
/// A new instance of `NearbySearch`.
pub fn nearby_search(&mut self) -> NearbySearch {
let nearby_search_object: NearbySearch =
NearbySearch::new(self.api_key.as_str(), self.client);
nearby_search_object
}
/// Returns a new `PlaceDetails` instance that can be used to execute a
/// Place Details request.
///
/// # Returns
///
/// A new instance of `PlaceDetails`.
pub fn place_details(&mut self) -> PlaceDetails {
let details_object: PlaceDetails = PlaceDetails::new(self.api_key.as_str(), self.client);
details_object
}
/// Returns a new `FindPlace` instance that can be used to execute a
/// Find Place request.
///
/// # Returns
///
/// A new instance of `FindPlace`.
pub fn find_place(&mut self) -> FindPlace {
let find_place_object: FindPlace = FindPlace::new(self.api_key.as_str(), self.client);
find_place_object
}
pub fn place_photos(&mut self) -> PlacePhotos {
let place_photos_object: PlacePhotos = PlacePhotos::new(self.api_key.as_str(), self.client);
place_photos_object
}
}