@@ -60,20 +60,43 @@ pub async fn print_discover(client: &Client) -> Result<()> {
6060 } ) ;
6161
6262 let filter = jq:: discover ( ) ;
63- print_json ( result, filter) . await ?;
64- Ok ( ( ) )
63+ print_json ( result, filter) . await
6564}
6665
6766pub async fn print_category ( value : serde_json:: Value ) -> Result < ( ) > {
6867 let filter = jq:: category ( ) ;
69- print_json ( value, filter) . await ?;
70- Ok ( ( ) )
68+ print_json ( value, filter) . await
7169}
7270
73- pub async fn print_place ( value : serde_json:: Value ) -> Result < ( ) > {
71+ pub async fn print_place ( client : & Client , value : serde_json:: Value ) -> Result < ( ) > {
72+ let place = value. get ( "place" ) . ok_or ( "no place entry" ) ?;
73+ let api_id = place
74+ . get ( "api_id" )
75+ . ok_or ( "no api_id entry" ) ?
76+ . as_str ( )
77+ . ok_or ( "invalid api_id" ) ?;
78+ let mut events = vec ! [ ] ;
79+
80+ let mut cursor = None ;
81+ loop {
82+ let result = client. get_place_events ( api_id, cursor, Some ( 50 ) ) . await ?;
83+ events. extend ( result. entries ) ;
84+
85+ if !result. has_more {
86+ break ;
87+ }
88+
89+ cursor = result. next_cursor ;
90+ assert ! ( cursor. is_some( ) ) ;
91+ }
92+
93+ let value = json ! ( {
94+ "place" : place,
95+ "events" : events,
96+ } ) ;
97+
7498 let filter = jq:: place ( ) ;
75- print_json ( value, filter) . await ?;
76- Ok ( ( ) )
99+ print_json ( value, filter) . await
77100}
78101
79102#[ tokio:: main]
@@ -133,7 +156,7 @@ pub async fn main() -> Result<SysexitsError, Box<dyn Error>> {
133156 } ,
134157 FetchTarget :: Place ( name) => {
135158 let result = client. get_place_by_slug ( & name) . await ?;
136- print_place ( result) . await ?;
159+ print_place ( & client , result) . await ?;
137160 } ,
138161 // FetchTarget::Event(_) => {
139162 // unimplemented!();
@@ -145,7 +168,7 @@ pub async fn main() -> Result<SysexitsError, Box<dyn Error>> {
145168 }
146169
147170 if let Ok ( result) = client. get_place_by_slug ( & resource) . await {
148- print_place ( result) . await ?;
171+ print_place ( & client , result) . await ?;
149172 return Ok ( EX_OK ) ;
150173 }
151174
0 commit comments