From 9fcc1cccd7e2721802e4ddc810fccdab69ce7d59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20Sima=CC=83o?= Date: Fri, 5 Nov 2021 10:13:48 -0300 Subject: [PATCH] added dataapi --- api/dataapi/lib.go | 3 ++- api/dataapi/lib_test.go | 15 +++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/api/dataapi/lib.go b/api/dataapi/lib.go index 415319f..ab5815b 100644 --- a/api/dataapi/lib.go +++ b/api/dataapi/lib.go @@ -37,8 +37,9 @@ func (c *Cli) Do(request *DataAPIRequest) (response *DataAPIResponse, err error) return } -func NewCli() *Cli { +func NewCli(apikey string) *Cli { ret := &Cli{Httpcli: httpcli.NewCli()} + ret.Httpcli.AddHeader("X-API-KEY", apikey) ret.Httpcli.SetBasePath("https://dataapi.digitalcircle.com.br") return ret } diff --git a/api/dataapi/lib_test.go b/api/dataapi/lib_test.go index 0276226..a4b0dab 100644 --- a/api/dataapi/lib_test.go +++ b/api/dataapi/lib_test.go @@ -7,8 +7,7 @@ import ( ) func TestAPIRetrieve(t *testing.T) { - c := dataapi.NewCli() - c.Httpcli.AddHeader("X-API-KEY", "RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") + c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") res, err := c.Do(&dataapi.DataAPIRequest{ Col: "C1", Op: dataapi.RETRIEVE, @@ -21,8 +20,7 @@ func TestAPIRetrieve(t *testing.T) { } func TestAPIRetrieveWQuery(t *testing.T) { - c := dataapi.NewCli() - c.Httpcli.AddHeader("X-API-KEY", "RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") + c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") res, err := c.Do(&dataapi.DataAPIRequest{ Col: "C1", Op: dataapi.RETRIEVE, @@ -36,8 +34,7 @@ func TestAPIRetrieveWQuery(t *testing.T) { } func TestAPIUpdate(t *testing.T) { - c := dataapi.NewCli() - c.Httpcli.AddHeader("X-API-KEY", "RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") + c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") res, err := c.Do(&dataapi.DataAPIRequest{ Col: "C1", Op: dataapi.UPDATE, @@ -54,8 +51,7 @@ func TestAPIUpdate(t *testing.T) { } func TestAPIDelete(t *testing.T) { - c := dataapi.NewCli() - c.Httpcli.AddHeader("X-API-KEY", "RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") + c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") res, err := c.Do(&dataapi.DataAPIRequest{ Col: "C1", Op: dataapi.DELETE, @@ -69,8 +65,7 @@ func TestAPIDelete(t *testing.T) { } func TestAPICreate(t *testing.T) { - c := dataapi.NewCli() - c.Httpcli.AddHeader("X-API-KEY", "RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") + c := dataapi.NewCli("RnJpIDA1IE5vdiAyMDIxIDExOjE1OjIyIEFNIFVUQwo") res, err := c.Do(&dataapi.DataAPIRequest{ Col: "C1",