/** Ċ Ġ* ĠCopyright Ġ 2 0 2 1 ĠCar l - Phil ipp ĠH arm ant Ċ Ġ* Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġfr . c ph . ch icago . client Ċ Ċ import Ġfr . c ph . ch icago . Constants . AL ER TS _ BASE Ċ import Ġfr . c ph . ch icago . Constants . AL ER TS _ BASE _ PATH Ċ import Ġfr . c ph . ch icago . Constants . BU SES _ BASE Ċ import Ġfr . c ph . ch icago . Constants . BU SES _ BASE _ PATH Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ DIR Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ FORMAT Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ KEY Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ MAP _ ID Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ OUTPUT _ TYPE Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ ROUTE Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ ROUTE _ ID Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ RUN _ NUMBER Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ STOP _ ID Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ TYPE Ċ import Ġfr . c ph . ch icago . Constants . REQUEST _ VID Ċ import Ġfr . c ph . ch icago . Constants . TRAIN S _ BASE Ċ import Ġfr . c ph . ch icago . Constants . TRAIN S _ BASE _ PATH Ċ import Ġfr . c ph . ch icago . config . httpClient Ċ import Ġfr . c ph . ch icago . config . object Mapper Ċ import Ġfr . c ph . ch icago . entity . Alerts Route Response Ċ import Ġfr . c ph . ch icago . entity . Alerts Routes Response Ċ import Ġfr . c ph . ch icago . entity . Bus Arrival Response Ċ import Ġfr . c ph . ch icago . entity . Bus Direction Response Ċ import Ġfr . c ph . ch icago . entity . Bus Pattern Response Ċ import Ġfr . c ph . ch icago . entity . Bus Position Response Ċ import Ġfr . c ph . ch icago . entity . Bus Routes Response Ċ import Ġfr . c ph . ch icago . entity . Bus Stops Response Ċ import Ġfr . c ph . ch icago . entity . Train Arrival Response Ċ import Ġfr . c ph . ch icago . entity . Train Location Response Ċ import Ġfr . c ph . ch icago . redux . store Ċ import Ġio . reactivex . rx java 3 . core . Single Ċ import Ġio . reactivex . rx java 3 . schedul ers . Schedulers Ċ import Ġretrofit 2 . Ret rofit Ċ import Ġretrofit 2 . adapter . rx java 3 . Rx Java 3 Call Adapter Factory Ċ import Ġretrofit 2 . converter . jackson . Jack son Converter Factory Ċ import Ġretrofit 2 . http . GET Ċ import Ġretrofit 2 . http . Query Ċ Ċ /** Ċ Ġ* ĠClass Ġthat Ġbuild Ġurl Ġand Ġconnect Ġto ĠC TA ĠAPI Ċ Ġ* Ċ Ġ* Ġ@ author ĠCar l - Phil ipp ĠH arm ant Ċ Ġ* Ċ Ġ* Ġ@ version Ġ 1 Ċ Ġ*/ Ċ object ĠC ta Client Ġ{ ĊĊĠĠĠ Ġfun Ġget Train Ar ri vals ( station Ids : ĠList < String >): ĠSingle < Train Arrival Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Train Client . ar ri vals ( ids Ġ= Ġstation Ids ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Train Follow ( run Number : ĠString ): ĠSingle < Train Arrival Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Train Client . follow ( run Number Ġ= Ġrun Number ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Train Locations ( line : ĠString ): ĠSingle < Train Location Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Train Client . location ( line Ġ= Ġline ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Bus Routes (): ĠSingle < Bus Routes Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Bus Client . routes () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Bus Directions ( bus Route Id : ĠString ): ĠSingle < Bus Direction Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Bus Client . directions ( bus Route Id Ġ= Ġbus Route Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Bus Stops ( route : ĠString , Ġbound : ĠString ): ĠSingle < Bus Stops Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Bus Client . stops ( route Ġ= Ġroute , Ġbound Ġ= Ġbound ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Bus Veh icles ( bus Route Id : ĠString ): ĠSingle < Bus Position Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Bus Client . vehicles ( bus Route Id Ġ= Ġbus Route Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Bus Ar ri vals ( stop Ids : ĠList < String >? Ġ= Ġnull , Ġroutes : ĠList < String >? Ġ= Ġnull , Ġbus Id : ĠString ? Ġ= Ġnull ): ĠSingle < Bus Arrival Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Bus Client . ar ri vals ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġstop Ids Ġ= Ġstop Ids ?. join ToString ( separator Ġ= Ġ", "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġroutes Ġ= Ġroutes ?. join ToString ( separator Ġ= Ġ", "), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġbus Id Ġ= Ġbus Id ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Bus Patterns ( route : ĠString ): ĠSingle < Bus Pattern Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Bus Client . patterns ( route Ġ= Ġroute ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Alert Routes (): ĠSingle < Alerts Routes Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Alert Client . routes () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Alert Alerts ( route Id : ĠString ): ĠSingle < Alerts Route Response > Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġc ta Alert Client . alerts ( route Id Ġ= Ġroute Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Schedulers . computation ()) ĊĠĠĠ Ġ} Ċ } Ċ Ċ private Ġinterface ĠC ta Train Client Ġ{ ĊĠĠĠ Ġ@ GET ("${ TRAIN S _ BASE _ PATH }/ tt ar ri vals . aspx ") ĊĠĠĠ Ġfun Ġar ri vals ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Train Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ OUTPUT _ TYPE ) Ġoutput Type : ĠString Ġ= Ġ" JSON ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ MAP _ ID ) Ġids : ĠList < String > ĊĠĠĠ Ġ): ĠSingle < Train Arrival Response > ĊĊĠĠĠ Ġ@ GET ("${ TRAIN S _ BASE _ PATH }/ tt follow . aspx ") ĊĠĠĠ Ġfun Ġfollow ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Train Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ OUTPUT _ TYPE ) Ġoutput Type : ĠString Ġ= Ġ" JSON ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ RUN _ NUMBER ) Ġrun Number : ĠString ĊĠĠĠ Ġ): ĠSingle < Train Arrival Response > ĊĊĠĠĠ Ġ@ GET ("${ TRAIN S _ BASE _ PATH }/ ttp osition s . aspx ") ĊĠĠĠ Ġfun Ġlocation ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Train Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ OUTPUT _ TYPE ) Ġoutput Type : ĠString Ġ= Ġ" JSON ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ ROUTE ) Ġline : ĠString ĊĠĠĠ Ġ): ĠSingle < Train Location Response > Ċ } Ċ Ċ private Ġinterface ĠC ta Bus Client Ġ{ ĊĠĠĠ Ġ@ GET ("${ BU SES _ BASE _ PATH }/ get routes ") ĊĠĠĠ Ġfun Ġroutes ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Bus Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ FORMAT ) Ġoutput Type : ĠString Ġ= Ġ" json " ĊĠĠĠ Ġ): ĠSingle < Bus Routes Response > ĊĊĠĠĠ Ġ@ GET ("${ BU SES _ BASE _ PATH }/ get directions ") ĊĠĠĠ Ġfun Ġdirections ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Bus Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ FORMAT ) Ġoutput Type : ĠString Ġ= Ġ" json ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ ROUTE ) Ġbus Route Id : ĠString ĊĠĠĠ Ġ): ĠSingle < Bus Direction Response > ĊĊĠĠĠ Ġ@ GET ("${ BU SES _ BASE _ PATH }/ get stops ") ĊĠĠĠ Ġfun Ġstops ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Bus Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ FORMAT ) Ġoutput Type : ĠString Ġ= Ġ" json ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ ROUTE ) Ġroute : ĠString , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ DIR ) Ġbound : ĠString ĊĠĠĠ Ġ): ĠSingle < Bus Stops Response > ĊĊĠĠĠ Ġ@ GET ("${ BU SES _ BASE _ PATH }/ get vehicles ") ĊĠĠĠ Ġfun Ġvehicles ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Bus Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ FORMAT ) Ġoutput Type : ĠString Ġ= Ġ" json ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ ROUTE ) Ġbus Route Id : ĠString ĊĠĠĠ Ġ): ĠSingle < Bus Position Response > ĊĊĠĠĠ Ġ@ GET ("${ BU SES _ BASE _ PATH }/ get predictions ") ĊĠĠĠ Ġfun Ġar ri vals ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Bus Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ FORMAT ) Ġoutput Type : ĠString Ġ= Ġ" json ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ STOP _ ID ) Ġstop Ids : ĠString ? Ġ= Ġnull , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ ROUTE ) Ġroutes : ĠString ? Ġ= Ġnull , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ VID ) Ġbus Id : ĠString ? Ġ= Ġnull , ĊĠĠĠ Ġ): ĠSingle < Bus Arrival Response > ĊĊĠĠĠ Ġ@ GET ("${ BU SES _ BASE _ PATH }/ get patterns ") ĊĠĠĠ Ġfun Ġpatterns ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ KEY ) Ġkey : ĠString Ġ= Ġstore . state . cta Bus Key , ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ FORMAT ) Ġoutput Type : ĠString Ġ= Ġ" json ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ ROUTE ) Ġroute : ĠString , ĊĠĠĠ Ġ): ĠSingle < Bus Pattern Response > Ċ } Ċ Ċ private Ġinterface ĠC ta Alert Client Ġ{ ĊĠĠĠ Ġ@ GET ("${ AL ER TS _ BASE _ PATH }/ routes . aspx ") ĊĠĠĠ Ġfun Ġroutes ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ OUTPUT _ TYPE ) Ġkey : ĠString Ġ= Ġ" json ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ TYPE ) Ġr ail : ĠString Ġ= Ġ" rail ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ TYPE ) Ġbus : ĠString Ġ= Ġ" bus " ĊĠĠĠ Ġ): ĠSingle < Alerts Routes Response > ĊĊĠĠĠ Ġ@ GET ("${ AL ER TS _ BASE _ PATH }/ alerts . aspx ") ĊĠĠĠ Ġfun Ġalerts ( ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ OUTPUT _ TYPE ) Ġkey : ĠString Ġ= Ġ" json ", ĊĠĠĠĠĠĠĠ Ġ@ Query ( REQUEST _ ROUTE _ ID ) Ġroute Id : ĠString ĊĠĠĠ Ġ): ĠSingle < Alerts Route Response > Ċ } Ċ Ċ private Ġval Ġc ta Train Client : ĠC ta Train Client Ġby Ġlazy Ġ{ ĊĠĠĠ Ġval Ġretrofit Ġ= ĠRet rofit . Builder () ĊĠĠĠĠĠĠĠ Ġ. baseUrl ( TRAIN S _ BASE ) ĊĠĠĠĠĠĠĠ Ġ. add Call Adapter Factory ( Rx Java 3 Call Adapter Factory . create ()) ĊĠĠĠĠĠĠĠ Ġ. add Converter Factory ( Jack son Converter Factory . create ( object Mapper )) ĊĠĠĠĠĠĠĠ Ġ. client ( httpClient ) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġretrofit . create ( C ta Train Client :: class . java ) Ċ } Ċ Ċ private Ġval Ġc ta Bus Client : ĠC ta Bus Client Ġby Ġlazy Ġ{ ĊĠĠĠ Ġval Ġretrofit Ġ= ĠRet rofit . Builder () ĊĠĠĠĠĠĠĠ Ġ. baseUrl ( BU SES _ BASE ) ĊĠĠĠĠĠĠĠ Ġ. add Call Adapter Factory ( Rx Java 3 Call Adapter Factory . create ()) ĊĠĠĠĠĠĠĠ Ġ. add Converter Factory ( Jack son Converter Factory . create ( object Mapper )) ĊĠĠĠĠĠĠĠ Ġ. client ( httpClient ) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġretrofit . create ( C ta Bus Client :: class . java ) Ċ } Ċ Ċ private Ġval Ġc ta Alert Client : ĠC ta Alert Client Ġby Ġlazy Ġ{ ĊĠĠĠ Ġval Ġretrofit Ġ= ĠRet rofit . Builder () ĊĠĠĠĠĠĠĠ Ġ. baseUrl ( AL ER TS _ BASE ) ĊĠĠĠĠĠĠĠ Ġ. add Call Adapter Factory ( Rx Java 3 Call Adapter Factory . create ()) ĊĠĠĠĠĠĠĠ Ġ. add Converter Factory ( Jack son Converter Factory . create ( object Mapper )) ĊĠĠĠĠĠĠĠ Ġ. client ( httpClient ) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠ Ġretrofit . create ( C ta Alert Client :: class . java ) Ċ } Ċ