package Ġcom . st as bar . app . g play api Ċ Ċ import Ġcom . st as bar . app . google books . Google Books Service Ċ import Ġgoogle books . Google Books SearchResult Ċ import Ġkotlinx . coroutines . Deferred Ċ import Ġkotlinx . coroutines . coroutine Scope Ċ import Ġmu . Kotlin Logging Ċ import Ġretrofit 2 . http . GET Ċ import Ġretrofit 2 . http . Headers Ċ import Ġretrofit 2 . http . Path Ċ import Ġretrofit 2 . http . Query ĊĊ Ċ interface ĠGoogle Books Service Ġ{ ĊĠ Ġ@ Headers (" Accept : Ġ*/ * ") ĊĠ Ġ@ GET ("/ books / v 1 / volumes ") ĊĠ Ġfun Ġget Book By Is bn Async ( ĊĠĠĠ Ġ@ Query (" q ") Ġq : ĠString , ĊĠĠĠ Ġ@ Query (" key ") Ġkey : ĠString , ĊĠĠĠ Ġ@ Query (" default ") Ġdefault : ĠBoolean Ġ= Ġfalse , ĊĠĠĠ Ġ@ Query (" fields ") Ġfields : ĠString Ġ= Ġ" items ( volume Info / image Links )" ĊĠ Ġ): ĠDeferred < Google Books SearchResult > Ċ } Ċ Ċ class ĠGoogle Books Api ( private Ġval Ġservice : ĠGoogle Books Service , Ġprivate Ġval ĠapiKey : ĠString ) Ġ{ ĊĠ Ġfun Ġget Book By Is bn ( isbn : ĠString ) Ġ= Ġservice . get Book By Is bn (" isbn :$ isbn ", ĠapiKey ) Ċ } Ċ Ċ interface ĠG Play Service Ġ{ ĊĠ Ġ@ GET ("/ api / apps /{ packageName }/ ") ĊĠ Ġfun Ġget Book By Is bn Async ( ĊĠĠĠ Ġ@ Path (" packageName ") ĠpackageName : ĠString ĊĠ Ġ): ĠDeferred < App Details > ĊĊĠ Ġ@ GET ("/ api / developers /{ developer Name }/ ") ĊĠ Ġfun Ġget Developer Apps Async ( ĊĠĠĠ Ġ@ Path (" developer Name ") Ġdeveloper Name : ĠString ĊĠ Ġ): ĠDeferred < Developer Apps > Ċ } Ċ Ċ class ĠG Play Api ( private Ġval Ġservice : ĠG Play Service ) Ġ{ ĊĠ Ġprivate Ġval Ġlogger Ġ= ĠKotlin Logging . logger Ġ{} ĊĠ Ġsuspend Ġfun Ġget App Downloads ( packageName : ĠString ): ĠApp Stat Ġ{ ĊĠĠĠ Ġval Ġresponse Ġ= Ġservice . get Book By Is bn Async ( packageName ). await () ĊĠĠĠ Ġreturn ĠApp Stat ( response . min Install s , Ġresponse . score ) ĊĠ Ġ} ĊĊĠ Ġsuspend Ġfun ĠgetTotal Developer Apps Downloads ( developer Name : ĠString ): ĠApp Stat Ġ{ ĊĠĠĠ Ġval Ġresponse Ġ= Ġservice . get Developer Apps Async ( developer Name ). await () ĊĠĠĠ Ġval Ġapp Downloads Ġ= Ġcoroutine Scope Ġ{ ĊĠĠĠĠĠ Ġresponse . apps . map Ġ{ ĊĠĠĠĠĠĠĠ Ġget App Downloads ( it . appId ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġtotal Downloads Ġ= Ġapp Downloads . sum By Ġ{ Ġit . downloads Ġ} ĊĠĠĠ Ġval Ġweighted Avg Score Ġ= ĊĠĠĠĠĠ Ġapp Downloads . sum By Double Ġ{ Ġit . downloads Ġ* Ġit . score Ġ} Ġ/ ĊĠĠĠĠĠĠĠ Ġtotal Downloads ĊĊĠĠĠ Ġreturn ĠApp Stat ( total Downloads , Ġweighted Avg Score ) ĊĠ Ġ} Ċ } Ċ