-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.rs
More file actions
403 lines (366 loc) · 13.1 KB
/
client.rs
File metadata and controls
403 lines (366 loc) · 13.1 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
//! Comprehensive Gamma API endpoint explorer.
//!
//! This example dynamically tests all Gamma API endpoints by:
//! 1. Fetching lists first (events, markets, tags, etc.)
//! 2. Extracting real IDs/slugs from responses
//! 3. Using those IDs for subsequent lookups
//!
//! Run with tracing enabled:
//! ```sh
//! RUST_LOG=info,hyper_util=off,hyper=off,reqwest=off,h2=off,rustls=off cargo run --example gamma --features gamma,tracing
//! ```
//!
//! Optionally log to a file:
//! ```sh
//! LOG_FILE=gamma.log RUST_LOG=info,hyper_util=off,hyper=off,reqwest=off,h2=off,rustls=off cargo run --example gamma --features gamma,tracing
//! ```
use std::fs::File;
use kuest_client_sdk::gamma::Client;
use kuest_client_sdk::gamma::types::ParentEntityType;
use kuest_client_sdk::gamma::types::request::{
CommentsByIdRequest, CommentsByUserAddressRequest, CommentsRequest, EventByIdRequest,
EventBySlugRequest, EventTagsRequest, EventsRequest, MarketByIdRequest, MarketBySlugRequest,
MarketTagsRequest, MarketsRequest, PublicProfileRequest, RelatedTagsByIdRequest,
RelatedTagsBySlugRequest, SearchRequest, SeriesByIdRequest, SeriesListRequest, TagByIdRequest,
TagBySlugRequest, TagsRequest, TeamsRequest,
};
use tracing::{debug, info};
use tracing_subscriber::EnvFilter;
use tracing_subscriber::layer::SubscriberExt as _;
use tracing_subscriber::util::SubscriberInitExt as _;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
if let Ok(path) = std::env::var("LOG_FILE") {
let file = File::create(path)?;
tracing_subscriber::registry()
.with(EnvFilter::from_default_env())
.with(
tracing_subscriber::fmt::layer()
.with_writer(file)
.with_ansi(false),
)
.init();
} else {
tracing_subscriber::fmt::init();
}
let client = Client::default();
match client.status().await {
Ok(s) => info!(endpoint = "status", result = %s),
Err(e) => debug!(endpoint = "status", error = %e),
}
match client.sports().await {
Ok(v) => info!(endpoint = "sports", count = v.len()),
Err(e) => debug!(endpoint = "sports", error = %e),
}
match client.sports_market_types().await {
Ok(v) => info!(
endpoint = "sports_market_types",
count = v.market_types.len()
),
Err(e) => debug!(endpoint = "sports_market_types", error = %e),
}
match client
.teams(&TeamsRequest::builder().limit(5).build())
.await
{
Ok(v) => info!(endpoint = "teams", count = v.len()),
Err(e) => debug!(endpoint = "teams", error = %e),
}
let tags_result = client.tags(&TagsRequest::builder().limit(10).build()).await;
match &tags_result {
Ok(v) => info!(endpoint = "tags", count = v.len()),
Err(e) => debug!(endpoint = "tags", error = %e),
}
// Use "politics" tag - known to have related tags
let tag_slug = "politics";
let tag_result = client
.tag_by_slug(&TagBySlugRequest::builder().slug(tag_slug).build())
.await;
let tag_id = match &tag_result {
Ok(tag) => {
info!(endpoint = "tag_by_slug", slug = tag_slug, id = %tag.id);
Some(tag.id.clone())
}
Err(e) => {
debug!(endpoint = "tag_by_slug", slug = tag_slug, error = %e);
None
}
};
if let Some(id) = &tag_id {
match client
.tag_by_id(&TagByIdRequest::builder().id(id).build())
.await
{
Ok(_) => info!(endpoint = "tag_by_id", id = %id),
Err(e) => debug!(endpoint = "tag_by_id", id = %id, error = %e),
}
match client
.related_tags_by_id(&RelatedTagsByIdRequest::builder().id(id).build())
.await
{
Ok(v) => info!(endpoint = "related_tags_by_id", id = %id, count = v.len()),
Err(e) => debug!(endpoint = "related_tags_by_id", id = %id, error = %e),
}
match client
.tags_related_to_tag_by_id(&RelatedTagsByIdRequest::builder().id(id).build())
.await
{
Ok(v) => info!(endpoint = "tags_related_to_tag_by_id", id = %id, count = v.len()),
Err(e) => debug!(endpoint = "tags_related_to_tag_by_id", id = %id, error = %e),
}
}
match client
.related_tags_by_slug(&RelatedTagsBySlugRequest::builder().slug(tag_slug).build())
.await
{
Ok(v) => info!(
endpoint = "related_tags_by_slug",
slug = tag_slug,
count = v.len()
),
Err(e) => debug!(endpoint = "related_tags_by_slug", slug = tag_slug, error = %e),
}
match client
.tags_related_to_tag_by_slug(&RelatedTagsBySlugRequest::builder().slug(tag_slug).build())
.await
{
Ok(v) => info!(
endpoint = "tags_related_to_tag_by_slug",
slug = tag_slug,
count = v.len()
),
Err(e) => debug!(endpoint = "tags_related_to_tag_by_slug", slug = tag_slug, error = %e),
}
let events_result = client
.events(
&EventsRequest::builder()
.active(true)
.limit(20)
.order(vec!["volume".to_owned()])
.ascending(false)
.build(),
)
.await;
// Find an event with comments
let (event_with_comments, any_event) = match &events_result {
Ok(events) => {
info!(endpoint = "events", count = events.len());
let with_comments = events
.iter()
.find(|e| e.comment_count.unwrap_or(0) > 0)
.map(|e| (e.id.clone(), e.slug.clone(), e.comment_count.unwrap_or(0)));
let any = events.first().map(|e| (e.id.clone(), e.slug.clone()));
(with_comments, any)
}
Err(e) => {
debug!(endpoint = "events", error = %e);
(None, None)
}
};
if let Some((event_id, event_slug)) = &any_event {
match client
.event_by_id(&EventByIdRequest::builder().id(event_id).build())
.await
{
Ok(_) => info!(endpoint = "event_by_id", id = %event_id),
Err(e) => debug!(endpoint = "event_by_id", id = %event_id, error = %e),
}
match client
.event_tags(&EventTagsRequest::builder().id(event_id).build())
.await
{
Ok(v) => info!(endpoint = "event_tags", id = %event_id, count = v.len()),
Err(e) => debug!(endpoint = "event_tags", id = %event_id, error = %e),
}
if let Some(slug) = event_slug {
match client
.event_by_slug(&EventBySlugRequest::builder().slug(slug).build())
.await
{
Ok(_) => info!(endpoint = "event_by_slug", slug = %slug),
Err(e) => debug!(endpoint = "event_by_slug", slug = %slug, error = %e),
}
}
}
let markets_result = client
.markets(&MarketsRequest::builder().closed(false).limit(10).build())
.await;
let (market_id, market_slug) = match &markets_result {
Ok(markets) => {
info!(endpoint = "markets", count = markets.len());
markets
.first()
.map_or((None, None), |m| (Some(m.id.clone()), m.slug.clone()))
}
Err(e) => {
debug!(endpoint = "markets", error = %e);
(None, None)
}
};
// Test multiple slugs - verifies repeated query params work (issue #147)
if let Ok(markets) = &markets_result {
let slugs: Vec<String> = markets
.iter()
.filter_map(|m| m.slug.clone())
.take(3)
.collect();
if slugs.len() >= 2 {
match client
.markets(&MarketsRequest::builder().slug(slugs.clone()).build())
.await
{
Ok(v) => info!(
endpoint = "markets_multiple_slugs",
slugs = ?slugs,
count = v.len(),
"verified repeated query params work"
),
Err(e) => debug!(endpoint = "markets_multiple_slugs", slugs = ?slugs, error = %e),
}
}
}
if let Some(id) = &market_id {
match client
.market_by_id(&MarketByIdRequest::builder().id(id).build())
.await
{
Ok(_) => info!(endpoint = "market_by_id", id = %id),
Err(e) => debug!(endpoint = "market_by_id", id = %id, error = %e),
}
match client
.market_tags(&MarketTagsRequest::builder().id(id).build())
.await
{
Ok(v) => info!(endpoint = "market_tags", id = %id, count = v.len()),
Err(e) => debug!(endpoint = "market_tags", id = %id, error = %e),
}
}
if let Some(slug) = &market_slug {
match client
.market_by_slug(&MarketBySlugRequest::builder().slug(slug).build())
.await
{
Ok(_) => info!(endpoint = "market_by_slug", slug = %slug),
Err(e) => debug!(endpoint = "market_by_slug", slug = %slug, error = %e),
}
}
let series_result = client
.series(
&SeriesListRequest::builder()
.limit(10)
.order("volume".to_owned())
.ascending(false)
.build(),
)
.await;
let series_id = match &series_result {
Ok(series) => {
info!(endpoint = "series", count = series.len());
series.first().map(|s| s.id.clone())
}
Err(e) => {
debug!(endpoint = "series", error = %e);
None
}
};
if let Some(id) = &series_id {
match client
.series_by_id(&SeriesByIdRequest::builder().id(id).build())
.await
{
Ok(_) => info!(endpoint = "series_by_id", id = %id),
Err(e) => debug!(endpoint = "series_by_id", id = %id, error = %e),
}
}
let (comment_id, user_address) = if let Some((event_id, _, comment_count)) =
&event_with_comments
{
let comments_result = client
.comments(
&CommentsRequest::builder()
.parent_entity_type(ParentEntityType::Event)
.parent_entity_id(event_id)
.limit(10)
.build(),
)
.await;
match &comments_result {
Ok(comments) => {
info!(endpoint = "comments", event_id = %event_id, expected = comment_count, count = comments.len());
comments
.first()
.map_or((None, None), |c| (Some(c.id.clone()), c.user_address))
}
Err(e) => {
debug!(endpoint = "comments", event_id = %event_id, error = %e);
(None, None)
}
}
} else {
debug!(
endpoint = "comments",
"skipped - no event with comments found"
);
(None, None)
};
if let Some(id) = &comment_id {
match client
.comments_by_id(&CommentsByIdRequest::builder().id(id).build())
.await
{
Ok(v) => info!(endpoint = "comments_by_id", id = %id, count = v.len()),
Err(e) => debug!(endpoint = "comments_by_id", id = %id, error = %e),
}
}
if let Some(addr) = user_address {
match client
.comments_by_user_address(
&CommentsByUserAddressRequest::builder()
.user_address(addr)
.limit(5)
.build(),
)
.await
{
Ok(v) => info!(endpoint = "comments_by_user_address", address = %addr, count = v.len()),
Err(e) => debug!(endpoint = "comments_by_user_address", address = %addr, error = %e),
}
}
// Use the user_address from comments if available
if let Some(profile_address) = user_address {
match client
.public_profile(
&PublicProfileRequest::builder()
.address(profile_address)
.build(),
)
.await
{
Ok(p) => {
let name = p.pseudonym.as_deref().unwrap_or("anonymous");
info!(endpoint = "public_profile", address = %profile_address, name = %name);
}
Err(e) => debug!(endpoint = "public_profile", address = %profile_address, error = %e),
}
}
let query = "trump";
match client
.search(&SearchRequest::builder().q(query).build())
.await
{
Ok(r) => {
let events = r.events.map_or(0, |e| e.len());
let tags = r.tags.map_or(0, |t| t.len());
let profiles = r.profiles.map_or(0, |p| p.len());
info!(
endpoint = "search",
query = query,
events = events,
tags = tags,
profiles = profiles
);
}
Err(e) => debug!(endpoint = "search", query = query, error = %e),
}
Ok(())
}