Skip to content

Commit 40dfafa

Browse files
Initial release
1 parent 5165d71 commit 40dfafa

13 files changed

Lines changed: 288 additions & 155 deletions

File tree

src/api/client.rs

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl Client {
2424
pub async fn get_featured_calendars(&self) -> Result<Root> {
2525
let url = Url::parse("https://api.lu.ma/calendar/get-featured-calendars").unwrap();
2626
let response = self.client.get(url).send().await?;
27+
response.error_for_status_ref()?;
2728
Ok(response.json::<Root>().await?)
2829
}
2930

@@ -32,16 +33,32 @@ impl Client {
3233
Url::parse("https://api.lu.ma/discover/category/list-categories?pagination_limit=20")
3334
.unwrap();
3435
let response = self.client.get(url).send().await?;
36+
response.error_for_status_ref()?;
3537
Ok(response.json::<Pagination>().await?)
3638
}
3739

3840
pub async fn list_places(&self) -> Result<Root> {
3941
let url = Url::parse("https://api.lu.ma/discover/list-places").unwrap();
4042
let response = self.client.get(url).send().await?;
43+
response.error_for_status_ref()?;
4144
Ok(response.json::<Root>().await?)
4245
}
4346

44-
pub async fn get_category_page<S>(&self, slug: S) -> Result<String>
47+
pub async fn get_category_by_id<S>(&self, id: S) -> Result<serde_json::Value>
48+
where
49+
S: AsRef<str>,
50+
{
51+
let url = Url::parse(&format!(
52+
"https://api.lu.ma/discover/category/get-page?discover_category_api_id={}",
53+
id.as_ref()
54+
))
55+
.unwrap();
56+
let response = self.client.get(url).send().await?;
57+
response.error_for_status_ref()?;
58+
Ok(response.json().await?)
59+
}
60+
61+
pub async fn get_category_by_slug<S>(&self, slug: S) -> Result<serde_json::Value>
4562
where
4663
S: AsRef<str>,
4764
{
@@ -51,10 +68,11 @@ impl Client {
5168
))
5269
.unwrap();
5370
let response = self.client.get(url).send().await?;
54-
Ok(response.text().await?)
71+
response.error_for_status_ref()?;
72+
Ok(response.json().await?)
5573
}
5674

57-
pub async fn get_calendars_for_place<S>(&self, place: S) -> Result<String>
75+
pub async fn get_calendars_for_place<S>(&self, place: S) -> Result<serde_json::Value>
5876
where
5977
S: AsRef<str>,
6078
{
@@ -64,35 +82,51 @@ impl Client {
6482
))
6583
.unwrap();
6684
let response = self.client.get(url).send().await?;
67-
Ok(response.text().await?)
85+
response.error_for_status_ref()?;
86+
Ok(response.json().await?)
6887
}
6988

70-
pub async fn get_place<S>(&self, place: S) -> Result<String>
89+
pub async fn get_place_by_id<S>(&self, id: S) -> Result<serde_json::Value>
7190
where
7291
S: AsRef<str>,
7392
{
7493
let url = Url::parse(&format!(
7594
"https://api.lu.ma/discover/get-place-v2?discover_place_api_id={}",
76-
place.as_ref()
95+
id.as_ref()
96+
))
97+
.unwrap();
98+
let response = self.client.get(url).send().await?;
99+
response.error_for_status_ref()?;
100+
Ok(response.json().await?)
101+
}
102+
103+
pub async fn get_place_by_slug<S>(&self, slug: S) -> Result<serde_json::Value>
104+
where
105+
S: AsRef<str>,
106+
{
107+
let url = Url::parse(&format!(
108+
"https://api.lu.ma/discover/get-place-v2?slug={}",
109+
slug.as_ref()
77110
))
78111
.unwrap();
79112
let response = self.client.get(url).send().await?;
80-
Ok(response.text().await?)
113+
response.error_for_status_ref()?;
114+
Ok(response.json().await?)
81115
}
82116

83117
pub async fn get_place_events<S1, S2>(
84118
&self,
85-
place: S1,
119+
place_id: S1,
86120
cursor: Option<S2>,
87121
limit: Option<u32>,
88-
) -> Result<String>
122+
) -> Result<serde_json::Value>
89123
where
90124
S1: AsRef<str>,
91125
S2: AsRef<str>,
92126
{
93127
let url = Url::parse(&format!(
94128
"https://api.lu.ma/discover/get-paginated-events?discover_place_api_id={}{}{}",
95-
place.as_ref(),
129+
place_id.as_ref(),
96130
if let Some(cursor) = cursor {
97131
format!("&pagination_cursor={}", cursor.as_ref())
98132
} else {
@@ -106,34 +140,35 @@ impl Client {
106140
))
107141
.unwrap();
108142
let response = self.client.get(url).send().await?;
109-
Ok(response.text().await?)
143+
response.error_for_status_ref()?;
144+
Ok(response.json().await?)
110145
}
111146

112-
pub async fn get_calendar<S>(&self, calendar: S) -> Result<String>
147+
pub async fn get_calendar_by_id<S>(&self, id: S) -> Result<serde_json::Value>
113148
where
114149
S: AsRef<str>,
115150
{
116151
let url = Url::parse(&format!(
117152
"https://api.lu.ma/calendar/get?api_id={}",
118-
calendar.as_ref()
153+
id.as_ref()
119154
))
120155
.unwrap();
121156
let response = self.client.get(url).send().await?;
122-
Ok(response.text().await?)
157+
Ok(response.json().await?)
123158
}
124159

125160
pub async fn get_calendar_events<S1, S2>(
126161
&self,
127162
calendar: S1,
128163
cursor: Option<S2>,
129164
limit: Option<u32>,
130-
) -> Result<String>
165+
) -> Result<serde_json::Value>
131166
where
132167
S1: AsRef<str>,
133168
S2: AsRef<str>,
134169
{
135170
let url = Url::parse(&format!(
136-
"https://api.lu.ma/calendar/get-paginated-events?api_id={}{}{}",
171+
"https://api.lu.ma/calendar/get-items?calendar_api_id={}{}{}&period=future",
137172
calendar.as_ref(),
138173
if let Some(cursor) = cursor {
139174
format!("&pagination_cursor={}", cursor.as_ref())
@@ -148,10 +183,11 @@ impl Client {
148183
))
149184
.unwrap();
150185
let response = self.client.get(url).send().await?;
151-
Ok(response.text().await?)
186+
response.error_for_status_ref()?;
187+
Ok(response.json().await?)
152188
}
153189

154-
pub async fn get_event<S>(&self, event: S) -> Result<String>
190+
pub async fn get_event<S>(&self, event: S) -> Result<serde_json::Value>
155191
where
156192
S: AsRef<str>,
157193
{
@@ -161,6 +197,25 @@ impl Client {
161197
))
162198
.unwrap();
163199
let response = self.client.get(url).send().await?;
164-
Ok(response.text().await?)
200+
response.error_for_status_ref()?;
201+
Ok(response.json().await?)
202+
}
203+
204+
pub async fn get_nearby_events<S>(&self, category: Option<S>) -> Result<serde_json::Value>
205+
where
206+
S: AsRef<str>,
207+
{
208+
let url = Url::parse(&format!(
209+
"https://api.lu.ma/discover/get-paginated-events?pagination_limit=50{}",
210+
if let Some(category) = category {
211+
format!("&slug={}", category.as_ref())
212+
} else {
213+
"".to_string()
214+
}
215+
))
216+
.unwrap();
217+
let response = self.client.get(url).send().await?;
218+
response.error_for_status_ref()?;
219+
Ok(response.json().await?)
165220
}
166221
}

src/api/models.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
// This is free and unencumbered software released into the public domain.
22

3-
// mod calendar;
4-
// pub use calendar::*;
5-
6-
// mod featured_calendar;
7-
// pub use featured_calendar::*;
8-
9-
mod shared;
10-
pub use shared::*;
3+
mod common;
4+
pub use common::*;

src/api/models/calendar.rs

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/api/models/category.rs

Whitespace-only changes.

src/api/models/featured_calendar.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)