telegram_bot_fork_raw/requests/
send_venue.rs1use std::{borrow::Cow, ops::Not};
2
3use requests::*;
4use types::*;
5
6#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
8#[must_use = "requests do nothing unless sent"]
9pub struct SendVenue<'t, 'a, 'f> {
10 chat_id: ChatRef,
11 latitude: Float,
12 longitude: Float,
13 title: Cow<'t, str>,
14 address: Cow<'a, str>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 foursquare_id: Option<Cow<'f, str>>,
17 #[serde(skip_serializing_if = "Not::not")]
18 disable_notification: bool,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 reply_to_message_id: Option<MessageId>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 reply_markup: Option<ReplyMarkup>,
23}
24
25impl<'t, 'a, 'f> Request for SendVenue<'t, 'a, 'f> {
26 type Type = JsonRequestType<Self>;
27 type Response = JsonIdResponse<Message>;
28
29 fn serialize(&self) -> Result<HttpRequest, Error> {
30 Self::Type::serialize(RequestUrl::method("sendVenue"), self)
31 }
32}
33
34impl<'t, 'a, 'f> SendVenue<'t, 'a, 'f> {
35 pub fn new<C, T, A>(chat: C, latitude: Float, longitude: Float, title: T, address: A) -> Self
36 where
37 C: ToChatRef,
38 T: Into<Cow<'t, str>>,
39 A: Into<Cow<'a, str>>,
40 {
41 SendVenue {
42 chat_id: chat.to_chat_ref(),
43 latitude,
44 longitude,
45 title: title.into(),
46 address: address.into(),
47 disable_notification: false,
48 foursquare_id: None,
49 reply_to_message_id: None,
50 reply_markup: None,
51 }
52 }
53
54 pub fn disable_notification(&mut self) -> &mut Self {
55 self.disable_notification = true;
56 self
57 }
58
59 pub fn foursquare_id<F>(&mut self, id: F) -> &mut Self
60 where
61 F: Into<Cow<'f, str>>,
62 {
63 self.foursquare_id = Some(id.into());
64 self
65 }
66
67 pub fn reply_to<R>(&mut self, to: R) -> &mut Self
68 where
69 R: ToMessageId,
70 {
71 self.reply_to_message_id = Some(to.to_message_id());
72 self
73 }
74
75 pub fn reply_markup<R>(&mut self, reply_markup: R) -> &mut Self
76 where
77 R: Into<ReplyMarkup>,
78 {
79 self.reply_markup = Some(reply_markup.into());
80 self
81 }
82}
83
84pub trait CanSendVenue<'t, 'a, 'f> {
86 fn venue<T, A>(
87 &self,
88 latitude: Float,
89 longitude: Float,
90 title: T,
91 address: A,
92 ) -> SendVenue<'t, 'a, 'f>
93 where
94 T: Into<Cow<'t, str>>,
95 A: Into<Cow<'a, str>>;
96}
97
98impl<'t, 'a, 'f, C> CanSendVenue<'t, 'a, 'f> for C
99where
100 C: ToChatRef,
101{
102 fn venue<T, A>(
103 &self,
104 latitude: Float,
105 longitude: Float,
106 title: T,
107 address: A,
108 ) -> SendVenue<'t, 'a, 'f>
109 where
110 T: Into<Cow<'t, str>>,
111 A: Into<Cow<'a, str>>,
112 {
113 SendVenue::new(self, latitude, longitude, title, address)
114 }
115}
116
117pub trait CanReplySendVenue {
119 fn venue_reply<'t, 'a, 'f, T, A>(
120 &self,
121 latitude: Float,
122 longitude: Float,
123 title: T,
124 address: A,
125 ) -> SendVenue<'t, 'a, 'f>
126 where
127 T: Into<Cow<'t, str>>,
128 A: Into<Cow<'a, str>>;
129}
130
131impl<M> CanReplySendVenue for M
132where
133 M: ToMessageId + ToSourceChat,
134{
135 fn venue_reply<'t, 'a, 'f, T, A>(
136 &self,
137 latitude: Float,
138 longitude: Float,
139 title: T,
140 address: A,
141 ) -> SendVenue<'t, 'a, 'f>
142 where
143 T: Into<Cow<'t, str>>,
144 A: Into<Cow<'a, str>>,
145 {
146 let mut rq = self
147 .to_source_chat()
148 .venue(latitude, longitude, title, address);
149 rq.reply_to(self.to_message_id());
150 rq
151 }
152}
153
154impl<'b> ToRequest<'b> for Venue {
155 type Request = SendVenue<'b, 'b, 'b>;
156
157 fn to_request<C>(&'b self, chat: C) -> Self::Request
158 where
159 C: ToChatRef,
160 {
161 let mut rq = chat.venue(
162 self.location.latitude,
163 self.location.longitude,
164 self.title.as_str(),
165 self.address.as_str(),
166 );
167 if let Some(ref foursquare_id) = self.foursquare_id {
168 rq.foursquare_id(foursquare_id.as_str());
169 }
170 rq
171 }
172}
173
174impl<'b> ToReplyRequest<'b> for Venue {
175 type Request = SendVenue<'b, 'b, 'b>;
176
177 fn to_reply_request<M>(&'b self, message: M) -> Self::Request
178 where
179 M: ToMessageId + ToSourceChat,
180 {
181 let mut rq = message.venue_reply(
182 self.location.latitude,
183 self.location.longitude,
184 self.title.as_str(),
185 self.address.as_str(),
186 );
187 if let Some(ref foursquare_id) = self.foursquare_id {
188 rq.foursquare_id(foursquare_id.as_str());
189 }
190 rq
191 }
192}