From 3504facc2e82539dc791d22ec9681946056f25cb Mon Sep 17 00:00:00 2001 From: Leonardo Domingues Date: Thu, 25 Nov 2021 10:50:33 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Corre=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dataapi/lib.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/api/dataapi/lib.go b/api/dataapi/lib.go index bb1e1ba..a9918e2 100644 --- a/api/dataapi/lib.go +++ b/api/dataapi/lib.go @@ -47,21 +47,6 @@ func NewCli(apikey string) *Cli { return ret } -func LCR_Create() { - c := NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") - - _, err := c.Do(&DataAPIRequest{ - Col: "LCR_Bot", - Op: CREATE, - Data: map[string]interface{}{ - "Registro": "1", - }, - }) - if err != nil { - panic(err) - } -} - func RegistrarExec(table string, check bool) { //Para robôs, age como contador e registra cada repetição no mês c := NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") From 17d68433dc3f02d7344c448082e456802f6a4c98 Mon Sep 17 00:00:00 2001 From: Leonardo Domingues Date: Thu, 25 Nov 2021 13:51:25 -0300 Subject: [PATCH 2/2] =?UTF-8?q?Elimina=C3=A7=C3=A3o=20do=20lib=5Ftest=20e?= =?UTF-8?q?=20atualiza=C3=A7=C3=A3o=20da=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dataapi/lib.go | 10 ++- api/dataapi/lib_test.go | 145 ---------------------------------------- 2 files changed, 8 insertions(+), 147 deletions(-) delete mode 100644 api/dataapi/lib_test.go diff --git a/api/dataapi/lib.go b/api/dataapi/lib.go index a9918e2..d1c6bf2 100644 --- a/api/dataapi/lib.go +++ b/api/dataapi/lib.go @@ -5,6 +5,7 @@ import ( "time" "go.digitalcircle.com.br/open/httpcli" + "go.digitalcircle.com.br/open/replaycli-go/api/replay" ) type DataApiOp string @@ -40,8 +41,13 @@ func (c *Cli) Do(request *DataAPIRequest) (response *DataAPIResponse, err error) return } -func NewCli(apikey string) *Cli { +func NewCli() *Cli { ret := &Cli{Httpcli: httpcli.NewCli()} + rcon := replay.NewCli() + apikey, err := rcon.ConfigGet("API_KEY") + if err != nil { + panic(err) + } ret.Httpcli.AddHeader("X-API-KEY", apikey) ret.Httpcli.SetBasePath("https://dataapi.digitalcircle.com.br") return ret @@ -49,7 +55,7 @@ func NewCli(apikey string) *Cli { func RegistrarExec(table string, check bool) { //Para robôs, age como contador e registra cada repetição no mês - c := NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") + c := NewCli() var registros int var erro int current := time.Now().Format("2006-01") diff --git a/api/dataapi/lib_test.go b/api/dataapi/lib_test.go deleted file mode 100644 index 7893da8..0000000 --- a/api/dataapi/lib_test.go +++ /dev/null @@ -1,145 +0,0 @@ -package dataapi_test - -import ( - "log" - "strconv" - "testing" - "time" - - "go.digitalcircle.com.br/open/replaycli-go/api/dataapi" -) - -func TestAPIRetrieve(t *testing.T) { - c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") - res, err := c.Do(&dataapi.DataAPIRequest{ - Col: "teste3", - Op: dataapi.RETRIEVE, - }) - if err != nil { - t.Fatal(err.Error()) - } - - log.Printf("%#v", res) -} - -func TestAPIRetrieveWQuery(t *testing.T) { - c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") - res, err := c.Do(&dataapi.DataAPIRequest{ - Col: "C1", - Op: dataapi.RETRIEVE, - Q: "@[?ID==`2`]", - }) - if err != nil { - t.Fatal(err.Error()) - } - - log.Printf("%#v", res) -} - -func TestAPIUpdate(t *testing.T) { - c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") - res, err := c.Do(&dataapi.DataAPIRequest{ - Col: "C1", - Op: dataapi.UPDATE, - Id: "2", - Data: map[string]interface{}{ - "F2": "Novo Campo", - }, - }) - if err != nil { - t.Fatal(err.Error()) - } - - log.Printf("%#v", res) -} - -func TestAPIDelete(t *testing.T) { - c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") - res, err := c.Do(&dataapi.DataAPIRequest{ - Col: "C1", - Op: dataapi.DELETE, - Id: "2", - }) - if err != nil { - t.Fatal(err.Error()) - } - - log.Printf("%#v", res) -} - -func TestAPICreate(t *testing.T) { - if true { - print("a") - print("b") - } - c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") - var registros int - var erro int - current := time.Now().Format("2006-01") - res, err := c.Do(&dataapi.DataAPIRequest{ - Col: "teste3", - Op: dataapi.RETRIEVE, - Q: "@[?date=='" + current + "']", - }) - if err != nil { - panic(err) - } - check := false - if len(res.Data) > 0 { - if check { - result := res.Data[0].(map[string]interface{}) - registros = int(result["exec"].(float64)) - registros = registros + 1 - ident := strconv.Itoa(int(result["ID"].(float64))) - - _, err = c.Do(&dataapi.DataAPIRequest{ - Col: "teste3", - Op: dataapi.UPDATE, - Id: ident, - Data: map[string]interface{}{ - "exec": registros, - }, - }) - if err != nil { - panic(err) - } - } else { - result := res.Data[0].(map[string]interface{}) - registros = int(result["err"].(float64)) - registros = registros + 1 - ident := strconv.Itoa(int(result["ID"].(float64))) - - _, err = c.Do(&dataapi.DataAPIRequest{ - Col: "teste3", - Op: dataapi.UPDATE, - Id: ident, - Data: map[string]interface{}{ - "err": registros, - }, - }) - if err != nil { - panic(err) - } - } - } else { - if check { - registros = 1 - erro = 0 - } else { - registros = 0 - erro = 1 - } - _, err = c.Do(&dataapi.DataAPIRequest{ - Col: "teste3", - Op: dataapi.CREATE, - Data: map[string]interface{}{ - "date": current, - "exec": registros, - "err": erro, - }, - }) - if err != nil { - panic(err) - } - } -}