*   *   *   *   *   *     #> ver. 2021-11-08 <#     *   *   *BEZ HADA*  *   *   *   *   *   *   *   *   *   *   *   *

#DEFINE CRLF         CHR(13)+CHR(10)

DO (LOWER(JUSTPATH(sys(16))) + "\ppgm_http") WITH "https://alto:1991.Altopraha@hajek-backend.production-a.asrv.cz/"

HTTP_READ_ONLY_MODE = .T.

ON KEY LABEL esc pokracovat = .F.
SET ESCAPE ON 
pokracovat = .T.
RAND(-99)
ACTIVATE SCREEN 
 
DO WHILE m.pokracovat
    doba_kopirovani = 999
    cislo_cloveka = ALLTRIM(STR(RAND() * 99999))

    LOCAL skin_oErr AS Exception
    TRY     
        zacatek = SECONDS()
        DO jeden_cyklus
        doba_kopirovani = krouhli_cas(SECONDS() - m.zacatek)
   CATCH TO skin_oErr 
        chybicka = chybicka + ALLTRIM(STR(skin_oErr.ErrorNo)) + " " + skin_oErr.Message + " Line:" + ALLTRIM(STR(skin_oErr.LineNo))
        DO sm_log WITH m.chybicka
    FINALLY
    ENDTRY 
    sm_log (STR(doba_kopirovani, 8,1))
    WAIT "" TIMEOUT (5 + 22 * RAND())
ENDDO 



************************************************************
PROCEDURE jeden_cyklus

http_get ("kredit/get_balances?client_id=88&at=2020-12-31T23:59")

http_get ("kredit/crud/clients/" + m.cislo_cloveka)
http_get ("kredit/crud/clients?filter{firstname.icontains}=ondra")

*http_get("kredit/crud/historic_transactions")

http_get("kredit/crud/transactions?filter{client}=" + m.cislo_cloveka + "&page_size=9")




************************************************************************
FUNCTION krouhli_cas(doba)
DO CASE 
CASE m.doba < 2.3
   RETURN ROUND(m.doba/2, 1)*2
CASE m.doba < 6
   RETURN ROUND(m.doba/5, 1)*5
CASE m.doba < 13
   RETURN ROUND(m.doba, 0)
CASE m.doba < 44
   RETURN ROUND(m.doba/3, 0)*3
OTHERWISE 
   RETURN ROUND(m.doba, -1)
ENDCASE 


*!*********************************************************************
FUNCTION sm_log (texticek)
PRIVATE bytes_zapsano, posledni_cas, jmeno_promenne

texticek = SUBSTR(TTOC(DATETIME(),3), 3, 14) + PADC(m.machine, 22) + m.gcpgm_id + " " + m.gcuser_id + " " + m.texticek + CRLF

soubor   = "zurnal_datastore_merka.txt"
TRY 
    bytes_zapsano = STRTOFILE(m.texticek, m.gchom_path + m.soubor, 1)
    IF bytes_zapsano = 0
        WAIT "Cekejte, oteviram " + m.gchom_path + m.soubor WIND TIME .5
        bytes_zapsano = STRTOFILE(m.texticek, m.gchom_path + m.soubor, 1)
        IF bytes_zapsano = 0
            bytes_zapsano = STRTOFILE(m.texticek,     ".\" + m.soubor, 1)
        ENDIF 
    ELSE 
        ? m.gchom_path + m.soubor, DATETIME()
    ENDIF 
CATCH
    STRTOFILE                        (m.texticek,     ".\" + m.soubor, 1)
ENDTRY 
