@@ -1225,60 +1225,14 @@ impl<'a> AuthenticatedApi<'a> {
12251225
12261226 Ok ( rv)
12271227 }
1228- }
1229-
1230- /// Options for fetching organization events
1231- #[ derive( Debug , Default ) ]
1232- pub struct FetchEventsOptions < ' a > {
1233- /// Project ID to filter events by
1234- pub project_id : Option < & ' a str > ,
1235- /// Cursor for pagination
1236- pub cursor : Option < & ' a str > ,
1237- /// Query string to filter events
1238- pub query : Option < & ' a str > ,
1239- /// Number of events per page (default: 100)
1240- pub per_page : Option < usize > ,
1241- /// Time period for stats (default: "1h")
1242- pub stats_period : Option < & ' a str > ,
1243- /// Sort order (default: "-timestamp")
1244- pub sort : Option < & ' a str > ,
1245- }
12461228
1247- impl < ' a > AuthenticatedApi < ' a > {
12481229 /// Fetch organization events from the specified dataset
12491230 pub fn fetch_organization_events (
12501231 & self ,
12511232 org : & str ,
1252- dataset : & str ,
1253- fields : & [ & str ] ,
1254- options : FetchEventsOptions ,
1233+ options : & FetchEventsOptions ,
12551234 ) -> ApiResult < Vec < LogEntry > > {
1256- let mut params = vec ! [ format!( "dataset={}" , QueryArg ( dataset) ) ] ;
1257-
1258- for field in fields {
1259- params. push ( format ! ( "field={}" , QueryArg ( field) ) ) ;
1260- }
1261-
1262- if let Some ( cursor) = options. cursor {
1263- params. push ( format ! ( "cursor={}" , QueryArg ( cursor) ) ) ;
1264- }
1265-
1266- if let Some ( project_id) = options. project_id {
1267- params. push ( format ! ( "project={}" , QueryArg ( project_id) ) ) ;
1268- }
1269-
1270- if let Some ( query) = options. query {
1271- params. push ( format ! ( "query={}" , QueryArg ( query) ) ) ;
1272- }
1273-
1274- params. push ( format ! ( "per_page={}" , options. per_page. unwrap_or( 100 ) ) ) ;
1275- params. push ( format ! (
1276- "statsPeriod={}" ,
1277- options. stats_period. unwrap_or( "1h" )
1278- ) ) ;
1279- params. push ( "referrer=sentry-cli-tail" . to_owned ( ) ) ;
1280- params. push ( format ! ( "sort={}" , options. sort. unwrap_or( "-timestamp" ) ) ) ;
1281-
1235+ let params = options. to_query_params ( ) ;
12821236 let url = format ! (
12831237 "/organizations/{}/events/?{}" ,
12841238 PathArg ( org) ,
@@ -1459,6 +1413,71 @@ impl<'a> AuthenticatedApi<'a> {
14591413 }
14601414}
14611415
1416+ /// Available datasets for fetching organization events
1417+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
1418+ pub enum Dataset {
1419+ /// Our logs dataset
1420+ OurLogs ,
1421+ }
1422+
1423+ impl Dataset {
1424+ /// Returns the string representation of the dataset
1425+ pub fn as_str ( & self ) -> & ' static str {
1426+ match self {
1427+ Dataset :: OurLogs => "ourlogs" ,
1428+ }
1429+ }
1430+ }
1431+ /// Options for fetching organization events
1432+ pub struct FetchEventsOptions < ' a > {
1433+ /// Dataset to fetch events from
1434+ pub dataset : Dataset ,
1435+ /// Fields to include in the response
1436+ pub fields : & ' a [ & ' a str ] ,
1437+ /// Project ID to filter events by
1438+ pub project_id : Option < & ' a str > ,
1439+ /// Cursor for pagination
1440+ pub cursor : Option < & ' a str > ,
1441+ /// Query string to filter events
1442+ pub query : Option < & ' a str > ,
1443+ /// Number of events per page (default: 100)
1444+ pub per_page : Option < usize > ,
1445+ /// Time period for stats (default: "1h")
1446+ pub stats_period : Option < & ' a str > ,
1447+ /// Sort order (default: "-timestamp")
1448+ pub sort : Option < & ' a str > ,
1449+ }
1450+
1451+ impl < ' a > FetchEventsOptions < ' a > {
1452+ /// Generate query parameters as a vector of strings
1453+ pub fn to_query_params ( & self ) -> Vec < String > {
1454+ let mut params = vec ! [ format!( "dataset={}" , QueryArg ( self . dataset. as_str( ) ) ) ] ;
1455+
1456+ for field in self . fields {
1457+ params. push ( format ! ( "field={}" , QueryArg ( field) ) ) ;
1458+ }
1459+
1460+ if let Some ( cursor) = self . cursor {
1461+ params. push ( format ! ( "cursor={}" , QueryArg ( cursor) ) ) ;
1462+ }
1463+
1464+ if let Some ( project_id) = self . project_id {
1465+ params. push ( format ! ( "project={}" , QueryArg ( project_id) ) ) ;
1466+ }
1467+
1468+ if let Some ( query) = self . query {
1469+ params. push ( format ! ( "query={}" , QueryArg ( query) ) ) ;
1470+ }
1471+
1472+ params. push ( format ! ( "per_page={}" , self . per_page. unwrap_or( 100 ) ) ) ;
1473+ params. push ( format ! ( "statsPeriod={}" , self . stats_period. unwrap_or( "1h" ) ) ) ;
1474+
1475+ params. push ( format ! ( "sort={}" , self . sort. unwrap_or( "-timestamp" ) ) ) ;
1476+
1477+ params
1478+ }
1479+ }
1480+
14621481impl RegionSpecificApi < ' _ > {
14631482 fn request ( & self , method : Method , url : & str ) -> ApiResult < ApiRequest > {
14641483 self . api
0 commit comments