package Ġmacro . dashboard . ne pt unes Ċ Ċ import Ġcom . google . gson . Gson Builder Ċ import Ġk ong . un ire st . HttpResponse Ċ import Ġk ong . un ire st . JsonNode Ċ import Ġk ong . un ire st . Un ire st Ċ import Ġk ong . un ire st . Un ire st Exception Ċ import Ġmacro . dashboard . ne pt unes . config . Config Ċ import Ġorg . apache . logging . log 4 j . Level Ċ import Ġorg . apache . logging . log 4 j . Log Manager Ċ import Ġorg . jetbrains . ex posed . sql . Database Ċ import Ġorg . jetbrains . ex posed . sql . transactions . Transaction Manager Ċ import Ġjava . sql . Connection Ċ Ċ /** Ċ Ġ* ĠCreated Ġby ĠMacro 3 0 3 Ġon Ġ 2 0 1 8 - Nov - 1 2 . Ċ Ġ*/ Ċ object ĠUtil Ġ{ Ċ ĉ private Ġval ĠLOGGER Ġ= ĠLog Manager . getLogger ( Util :: class . java ) Ċ ĉ internal Ġval Ġdatabase Ġ= ĠDatabase . connect ( url Ġ= Ġ" jdbc : sqlite : Ne pt unes - Dashboard . sqlite ", Ġdriver Ġ= Ġ" org . sqlite . JDBC ") Ċ ĉ internal Ġval ĠHEAD ERS Ġ= Ġmap Of ( Ċĉ ĉ " Accept " Ġto Ġ" application / json ; Ġcharset = UTF - 8 ", Ċĉ ĉ " Content - Type " Ġto Ġ" application / json ; Ġcharset = UTF - 8 ", Ċĉ ĉ " User - Agent " Ġto Ġ" Ne pt une 's ĠDashboard " Ċ ĉ ) Ċ ĉ internal Ġval ĠG SON Ġ= ĠGson Builder () Ċĉ ĉ . set Pretty Print ing () Ċĉ ĉ . serialize Null s () Ċĉ ĉ . disable Html Esc aping () Ċĉ ĉ . create () ĊĊ ĉ init Ġ{ Ċĉ ĉ Transaction Manager . manager . default Isolation Level Ġ= ĠConnection . TRANSACTION _ SERIAL IZ ABLE Ċĉ ĉ Un ire st . config (). enable Cookie Management ( false ) Ċĉ ĉ if Ġ( Config . INSTANCE . proxy . host Name Ġ!= Ġnull Ġ&& ĠConfig . INSTANCE . proxy . port Ġ!= Ġnull ) Ċĉĉ ĉ Un ire st . config (). proxy ( Config . INSTANCE . proxy . host Name , ĠConfig . INSTANCE . proxy . port !! ) Ċ ĉ } ĊĊ ĉ internal Ġfun Ġpost Request ( url : ĠString , Ġgame Id : ĠLong , Ġcode : ĠString ): ĠJsonNode ? Ġ{ Ċĉ ĉ val Ġboundary Ġ= Ġ" === ${ System . currentTimeMillis ()} == =" Ċĉ ĉ val Ġrequest Ġ= ĠUn ire st . post ( url ) Ċĉĉ ĉ . header (" content - type ", Ġ" multipart / form - data ; Ġboundary =$ boundary ") Ċĉĉ ĉ . header (" User - Agent ", Ġ" Ne pt une 's ĠDashboard ") Ċĉĉ ĉ . body ("-- $ boundary \ r \ n Content - Disposition : Ġform - data ; Ġname =\" api _ version \"\ r \ n \ r \ n 0 . 1 \ r \ n -- $ boundary \ r \ n Content - Disposition : Ġform - data ; Ġname =\" game _ number \"\ r \ n \ r \ n $ game Id \ r \ n -- $ boundary \ r \ n Content - Disposition : Ġform - data ; Ġname =\" code \"\ r \ n \ r \ n $ code \ r \ n -- $ boundary -- ") Ċĉ ĉ LOGGER . debug (" GET Ġ: Ġ>>> Ġ- Ġ${ request . url }") Ċĉ ĉ val Ġresponse : ĠHttpResponse < JsonNode > Ċĉ ĉ try Ġ{ Ċĉĉ ĉ response Ġ= Ġrequest . as Json () Ċĉ ĉ } Ġcatch Ġ( ue : ĠUn ire st Exception ) Ġ{ Ċĉĉ ĉ LOGGER . error (" Unable Ġto Ġload ĠURL : Ġ$ ue ") Ċĉĉ ĉ return Ġnull Ċĉ ĉ } ĊĊĉ ĉ var Ġlevel Ġ= ĠLevel . ERROR Ċĉ ĉ when Ġ{ Ċĉĉ ĉ response . status Ġ< Ġ 1 0 0 Ġ-> Ġlevel Ġ= ĠLevel . ERROR Ċĉĉ ĉ response . status Ġ< Ġ 2 0 0 Ġ-> Ġlevel Ġ= ĠLevel . INFO Ċĉĉ ĉ response . status Ġ< Ġ 3 0 0 Ġ-> Ġlevel Ġ= ĠLevel . INFO Ċĉĉ ĉ response . status Ġ< Ġ 4 0 0 Ġ-> Ġlevel Ġ= ĠLevel . WARN Ċĉĉ ĉ response . status Ġ< Ġ 5 0 0 Ġ-> Ġlevel Ġ= ĠLevel . WARN Ċĉ ĉ } Ċĉ ĉ LOGGER . log ( level , Ġ" GET : Ġ${ response . status } Ġ${ response . status Text } Ġ- Ġ${ request . url }") Ċĉ ĉ LOGGER . debug (" Response : Ġ${ response . body }") Ċĉ ĉ return Ġif Ġ( response . status Ġ!= Ġ 2 0 0 ) Ġnull Ġelse Ġresponse . body Ċ ĉ } Ċ }