package Ġby . dev . mad head . dok tor . con fluence Ċ Ċ import Ġby . dev . mad head . dok tor . model . Resolved Con fluence Server Ċ import Ġby . dev . mad head . dok tor . model . con fluence . Content Reference Ċ import Ġby . dev . mad head . dok tor . model . con fluence . Find Page Response Ċ import Ġcom . github . kit tin un f . fuel . http Get Ċ import Ġcom . github . kit tin un f . fuel . rx . rx _ object Ċ import Ġcom . github . kit tin un f . result . Result Ċ import Ġcom . google . gson . Gson Ċ import Ġio . reactivex . Maybe Ċ import Ġjava . net . URL Ċ Ċ fun Ġfind Page ( con fluence Server : ĠResolved Con fluence Server , Ġtitle : ĠString ): ĠMaybe < Content Reference > Ġ{ Ċ ĉ return ĠURL ( URL ( con fluence Server . url ), Ġ"/ rest / api / content "). toString () Ċĉ ĉ . http Get ( Ċĉĉ ĉ listOf ( Ċĉĉĉ ĉ " space Key " Ġto Ġcon fluence Server . space , Ċĉĉĉ ĉ " title " Ġto Ġtitle Ċĉĉ ĉ ) Ċĉ ĉ ) Ċĉ ĉ . apply Ġ{ Ċĉĉ ĉ if Ġ(! con fluence Server . user . isNull Or Blank ()) Ġ{ Ċĉĉĉ ĉ authenticate ( con fluence Server . user !! , Ġcon fluence Server . password Ġ?: Ġ"") Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ . rx _ object ( Find Page Response . Deserializer ()) Ċĉ ĉ . flatMap Maybe Ġ{ Ċĉĉ ĉ when Ġ( it ) Ġ{ Ċĉĉĉ ĉ is ĠResult . Success Ġ-> Ġ{ Ċĉĉĉĉ ĉ if Ġ( it . value . size Ġ> Ġ 0 ) Ġ{ Ċĉĉĉĉĉ ĉ Maybe . just ( it . value . results [ 0 ]) Ċĉĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉĉ ĉ Maybe . empty < Content Reference >() Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉĉ ĉ is ĠResult . Failure Ġ-> Ġ{ Ċĉĉĉĉ ĉ try Ġ{ Ċĉĉĉĉĉ ĉ val Ġexception Ġ= ĠGson (). fromJson ( it . error . response . data . toString ( Charsets . UTF _ 8 ), ĠCon fluence Exception :: class . java ) ĊĊĉĉĉĉĉ ĉ if Ġ(! exception . message . isBlank ()) Ġ{ Ċĉĉĉĉĉĉ ĉ Maybe . error < Content Reference >( exception ) Ċĉĉĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉĉĉ ĉ throw ĠIllegalArgumentException () Ċĉĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ } Ġcatch Ġ( e : ĠThrowable ) Ġ{ Ċĉĉĉĉĉ ĉ Maybe . error < Content Reference >( Con fluence Exception ( it . error . exception . message Ġ?: Ġit . error . message Ġ?: Ġit . error . response . response Message )) Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċ } Ċ