From 706b1f32ce988599e1abfd77c5395b3a54e3c14e Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 11:13:06 -0300 Subject: [PATCH 01/16] Create .gitignore --- harbour/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 harbour/.gitignore diff --git a/harbour/.gitignore b/harbour/.gitignore new file mode 100644 index 0000000..ca463c1 --- /dev/null +++ b/harbour/.gitignore @@ -0,0 +1 @@ +api.ini \ No newline at end of file From af125c7ac7df60354daf2bd467d329fa242832ff Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 11:47:30 -0300 Subject: [PATCH 02/16] =?UTF-8?q?Criado=20as=20estruturas=20das=20fun?= =?UTF-8?q?=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- harbour/api.prg | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 harbour/api.prg diff --git a/harbour/api.prg b/harbour/api.prg new file mode 100644 index 0000000..2f6146e --- /dev/null +++ b/harbour/api.prg @@ -0,0 +1,24 @@ +FUNCTION main + LOCAL hParams := {=>} + + //Parametros que serão enviados + hParams['pagina'] := 1 + hParams['registros_por_pagina'] = 50 + + //Exemplo de chamada para listar cidades + API_Omie("https://app.omie.com.br/api/v1/geral/cidades/",; + "PesquisarCidades",; + hParams) +RETURN NIL + + +/* Comunica com a API da Omie*/ +FUNCTION API_Omie + PARAM cEndpointURI, cMetodo, hParams + LOCAL hIniData := HB_ReadIni( "api.ini" ) + LOCAL cHost := AllTrim(hIniData["AUTH"]["APP_KEY"]) + LOCAL cPort := AllTrim(hIniData["AUTH"]["APP_SECRET"]) + LOCAL hResult := {=>} + + //Construir Requisição POST +RETURN hResult \ No newline at end of file From f1f5652a489799ca07f61895a77decffd8980d1e Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 11:49:06 -0300 Subject: [PATCH 03/16] Update api.prg --- harbour/api.prg | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/harbour/api.prg b/harbour/api.prg index 2f6146e..6eb79a3 100644 --- a/harbour/api.prg +++ b/harbour/api.prg @@ -1,14 +1,15 @@ FUNCTION main LOCAL hParams := {=>} + LOCAL hResult := {=>} //Parametros que serão enviados hParams['pagina'] := 1 hParams['registros_por_pagina'] = 50 //Exemplo de chamada para listar cidades - API_Omie("https://app.omie.com.br/api/v1/geral/cidades/",; - "PesquisarCidades",; - hParams) + hResult := API_Omie("https://app.omie.com.br/api/v1/geral/cidades/", ; + "PesquisarCidades", ; + hParams) RETURN NIL From 3f53218e5a9cf90f9527f75dc68c139657167e8e Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 11:58:37 -0300 Subject: [PATCH 04/16] Readme --- harbour/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 harbour/README.md diff --git a/harbour/README.md b/harbour/README.md new file mode 100644 index 0000000..52767b7 --- /dev/null +++ b/harbour/README.md @@ -0,0 +1,20 @@ +# Acessando a API utilizando Harbour + +Para realizar uma requisição na API, utilize a função "API_Omie" + +Parâmetros da Função: + +## cEndpointURI : + - *Tipo:* Caracter (String) + - *Esperado:* Url do Endpoint da API Omie + - *Obrigatório*: Sim + +## cMetodo : + - *Tipo:* Caracter (String) + - *Esperado:* Método da API Omie + - *Obrigatório*: Sim + +## hParams : + - *Tipo:* Hash + - *Esperado:* Parâmetros da Requisição + - *Obrigatório*: Sim \ No newline at end of file From 7898faea38a83c0118e417ec468f113c39d5cdd6 Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 12:00:17 -0300 Subject: [PATCH 05/16] Readme --- harbour/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/harbour/README.md b/harbour/README.md index 52767b7..efee7ba 100644 --- a/harbour/README.md +++ b/harbour/README.md @@ -4,17 +4,17 @@ Para realizar uma requisição na API, utilize a função "API_Omie" Parâmetros da Função: -## cEndpointURI : +** cEndpointURI :** - *Tipo:* Caracter (String) - *Esperado:* Url do Endpoint da API Omie - *Obrigatório*: Sim -## cMetodo : +** cMetodo :** - *Tipo:* Caracter (String) - *Esperado:* Método da API Omie - *Obrigatório*: Sim -## hParams : +** hParams :** - *Tipo:* Hash - *Esperado:* Parâmetros da Requisição - *Obrigatório*: Sim \ No newline at end of file From 52e0bd5b4d8a54e36e6d3a5804a9ec23de219cd4 Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 12:01:09 -0300 Subject: [PATCH 06/16] Readme --- harbour/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/harbour/README.md b/harbour/README.md index efee7ba..8786638 100644 --- a/harbour/README.md +++ b/harbour/README.md @@ -1,20 +1,20 @@ # Acessando a API utilizando Harbour -Para realizar uma requisição na API, utilize a função "API_Omie" +Para realizar uma requisição na API, utilize a função **"API_Omie"** Parâmetros da Função: -** cEndpointURI :** +**cEndpointURI :** - *Tipo:* Caracter (String) - *Esperado:* Url do Endpoint da API Omie - *Obrigatório*: Sim -** cMetodo :** +**cMetodo :** - *Tipo:* Caracter (String) - *Esperado:* Método da API Omie - *Obrigatório*: Sim -** hParams :** +**hParams :** - *Tipo:* Hash - *Esperado:* Parâmetros da Requisição - *Obrigatório*: Sim \ No newline at end of file From 87fc72a403dcba294c580df1f0ce3529db8cf784 Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 12:06:09 -0300 Subject: [PATCH 07/16] Readme --- harbour/README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/harbour/README.md b/harbour/README.md index 8786638..41f61ac 100644 --- a/harbour/README.md +++ b/harbour/README.md @@ -2,7 +2,7 @@ Para realizar uma requisição na API, utilize a função **"API_Omie"** -Parâmetros da Função: +## Parâmetros da Função: **cEndpointURI :** - *Tipo:* Caracter (String) @@ -17,4 +17,11 @@ Parâmetros da Função: **hParams :** - *Tipo:* Hash - *Esperado:* Parâmetros da Requisição - - *Obrigatório*: Sim \ No newline at end of file + - *Obrigatório*: Sim + +## Retorno da Função + - *Tipo:* Array + - *Esperado:* + - - \[1\] : *Tipo:* Lógico | *Houve Erro:* .T. ou .F. + - - \[2\] : *Tipo:* Hash | *Conteúdo retornado no JSON* + - - \[3\] : *Tipo:* Caracter | *Conteúdo retornado no Body da Resposta* \ No newline at end of file From c7c5a39366a976eec0e47b084ee744eacc7f5cfe Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 13:16:52 -0300 Subject: [PATCH 08/16] . --- harbour/.gitignore | 13 ++++++++++++- harbour/api.prg | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/harbour/.gitignore b/harbour/.gitignore index ca463c1..d0d54ae 100644 --- a/harbour/.gitignore +++ b/harbour/.gitignore @@ -1 +1,12 @@ -api.ini \ No newline at end of file +api.ini +*.c +*.obj +*.map +*.exe +*.bat +*.log +*.ppo +*.dbf +*.dbt +*.ntx +xbuild.windows.ini \ No newline at end of file diff --git a/harbour/api.prg b/harbour/api.prg index 6eb79a3..d66aa0e 100644 --- a/harbour/api.prg +++ b/harbour/api.prg @@ -20,6 +20,8 @@ FUNCTION API_Omie LOCAL cHost := AllTrim(hIniData["AUTH"]["APP_KEY"]) LOCAL cPort := AllTrim(hIniData["AUTH"]["APP_SECRET"]) LOCAL hResult := {=>} + LOCAL cJson := hb_jsonEncode(hParams) + ? cJson //Construir Requisição POST RETURN hResult \ No newline at end of file From e53b0189e77581d0b157127ba4df4e8c753db79b Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Fri, 19 Aug 2022 13:23:00 -0300 Subject: [PATCH 09/16] gitignore --- harbour/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/harbour/.gitignore b/harbour/.gitignore index d0d54ae..e43e4cc 100644 --- a/harbour/.gitignore +++ b/harbour/.gitignore @@ -9,4 +9,5 @@ api.ini *.dbf *.dbt *.ntx +*.xbp xbuild.windows.ini \ No newline at end of file From 742bb0fddb3fc16d411ae08c9c556cca773aa0c7 Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Mon, 22 Aug 2022 10:35:02 -0300 Subject: [PATCH 10/16] . --- harbour/api.prg | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/harbour/api.prg b/harbour/api.prg index d66aa0e..cc69f1f 100644 --- a/harbour/api.prg +++ b/harbour/api.prg @@ -7,9 +7,12 @@ FUNCTION main hParams['registros_por_pagina'] = 50 //Exemplo de chamada para listar cidades - hResult := API_Omie("https://app.omie.com.br/api/v1/geral/cidades/", ; + //hResult := API_Omie("https://app.omie.com.br/api/v1/geral/cidades/", ; + // "PesquisarCidades", ; + // hParams) + hResult := API_Omie("http://localhost/api/v1/geral/cidades/", ; "PesquisarCidades", ; - hParams) + hParams) RETURN NIL @@ -17,11 +20,30 @@ RETURN NIL FUNCTION API_Omie PARAM cEndpointURI, cMetodo, hParams LOCAL hIniData := HB_ReadIni( "api.ini" ) - LOCAL cHost := AllTrim(hIniData["AUTH"]["APP_KEY"]) - LOCAL cPort := AllTrim(hIniData["AUTH"]["APP_SECRET"]) + LOCAL cKey := AllTrim(hIniData["AUTH"]["APP_KEY"]) + LOCAL cSecret := AllTrim(hIniData["AUTH"]["APP_SECRET"]) LOCAL hResult := {=>} - LOCAL cJson := hb_jsonEncode(hParams) + LOCAL oUrl := TUrl():new(cEndpointURI, .T.) + LOCAL oHttp := TIpClientHttp():new(oUrl) + LOCAL cJson + cJson := '{' + ; + '"call": "' + cMetodo + '",' + ; + '"app_key": "' + cKey + '",' + ; + '"app_secret": "' + cSecret + '",' + ; + '"param": [' + hb_jsonEncode(hParams) + ']' + ; + '}' ? cJson - //Construir Requisição POST + + + IF oHttp:open() + oHttp:post(cJson) + cJson := oHttp:readAll() + oHttp:close() + HB_JsonDecode(cJson , @hResult) + ? cJson + ELSE + ? "Connection error:", oHttp:lastErrorMessage() + ENDIF + RETURN hResult \ No newline at end of file From 15f97af3f21d66a04cd63632478dfa7cb03dfb92 Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Mon, 22 Aug 2022 10:51:22 -0300 Subject: [PATCH 11/16] Corrigido o Content-Type --- harbour/api.prg | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/harbour/api.prg b/harbour/api.prg index cc69f1f..041506c 100644 --- a/harbour/api.prg +++ b/harbour/api.prg @@ -27,23 +27,23 @@ FUNCTION API_Omie LOCAL oHttp := TIpClientHttp():new(oUrl) LOCAL cJson - cJson := '{' + ; - '"call": "' + cMetodo + '",' + ; + cJson := '{' + ; + '"call": "' + cMetodo + '",' + ; '"app_key": "' + cKey + '",' + ; '"app_secret": "' + cSecret + '",' + ; - '"param": [' + hb_jsonEncode(hParams) + ']' + ; + '"param": [' + hb_jsonEncode(hParams) + ']' + ; '}' - ? cJson - - + IF oHttp:open() + oHttp:hFields["Content-Type"] := "application/json" oHttp:post(cJson) cJson := oHttp:readAll() oHttp:close() + HB_JsonDecode(cJson , @hResult) ? cJson ELSE - ? "Connection error:", oHttp:lastErrorMessage() + ? "Erro de Conexão:", oHttp:lastErrorMessage() ENDIF RETURN hResult \ No newline at end of file From 9c562c04197ee118eecf8660a1b04358a50e585a Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:35:08 -0300 Subject: [PATCH 12/16] =?UTF-8?q?Comunica=C3=A7=C3=A3o=20com=20a=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- harbour/api.prg | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/harbour/api.prg b/harbour/api.prg index 041506c..3f105c6 100644 --- a/harbour/api.prg +++ b/harbour/api.prg @@ -7,12 +7,11 @@ FUNCTION main hParams['registros_por_pagina'] = 50 //Exemplo de chamada para listar cidades - //hResult := API_Omie("https://app.omie.com.br/api/v1/geral/cidades/", ; - // "PesquisarCidades", ; - // hParams) - hResult := API_Omie("http://localhost/api/v1/geral/cidades/", ; + hResult := API_Omie("https://app.omie.com.br/api/v1/geral/cidades/", ; "PesquisarCidades", ; - hParams) + hParams) + + ? ValToPrg(hResult) RETURN NIL @@ -23,10 +22,15 @@ FUNCTION API_Omie LOCAL cKey := AllTrim(hIniData["AUTH"]["APP_KEY"]) LOCAL cSecret := AllTrim(hIniData["AUTH"]["APP_SECRET"]) LOCAL hResult := {=>} - LOCAL oUrl := TUrl():new(cEndpointURI, .T.) - LOCAL oHttp := TIpClientHttp():new(oUrl) LOCAL cJson + TRY + oHttp := CreateObject("MSXML2.ServerXMLHTTP.6.0") + CATCH + ? "Não foi possível iniciar o objeto MSXML" + QUIT + END + cJson := '{' + ; '"call": "' + cMetodo + '",' + ; '"app_key": "' + cKey + '",' + ; @@ -34,16 +38,18 @@ FUNCTION API_Omie '"param": [' + hb_jsonEncode(hParams) + ']' + ; '}' - IF oHttp:open() - oHttp:hFields["Content-Type"] := "application/json" - oHttp:post(cJson) - cJson := oHttp:readAll() - oHttp:close() + oHttp:Open("POST", cEndpointURI, .F.) + oHttp:SetRequestHeader("Content-Type", "application/json") + oHttp:Send( cJson ) - HB_JsonDecode(cJson , @hResult) - ? cJson + cResponse := oHttp:ResponseText + IF oHttp:ReadyState = 4 .AND. oHttp:Status = 200 + hResult[1] := .F. + hResult[2] := hb_jsonDecode(cResponse) + hResult[3] := cResponse ELSE - ? "Erro de Conexão:", oHttp:lastErrorMessage() + hResult[1] := .T. + hResult[2] := "{}" + hResult[3] := cResponse ENDIF - RETURN hResult \ No newline at end of file From 8ba945e5dea26420379b920f76c526c21746ef86 Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:44:33 -0300 Subject: [PATCH 13/16] Corrigido README --- harbour/README.md | 3 +++ harbour/api.prg | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/harbour/README.md b/harbour/README.md index 41f61ac..02cd2bf 100644 --- a/harbour/README.md +++ b/harbour/README.md @@ -2,6 +2,9 @@ Para realizar uma requisição na API, utilize a função **"API_Omie"** +Altere os parâmetros **APP_KEY** e **APP_SECRET** dentro do arquivo api.ini conforme as credenciais do seu aplicativo na Omie. +(http://docs.omie.com.br/m/20204/l/612759-obtendo-a-chave-de-acesso-para-integracoes-de-api)[http://docs.omie.com.br/m/20204/l/612759-obtendo-a-chave-de-acesso-para-integracoes-de-api] + ## Parâmetros da Função: **cEndpointURI :** diff --git a/harbour/api.prg b/harbour/api.prg index 3f105c6..2b617e3 100644 --- a/harbour/api.prg +++ b/harbour/api.prg @@ -40,9 +40,10 @@ FUNCTION API_Omie oHttp:Open("POST", cEndpointURI, .F.) oHttp:SetRequestHeader("Content-Type", "application/json") - oHttp:Send( cJson ) + oHttp:Send(cJson) - cResponse := oHttp:ResponseText + cResponse := oHttp:ResponseText + IF oHttp:ReadyState = 4 .AND. oHttp:Status = 200 hResult[1] := .F. hResult[2] := hb_jsonDecode(cResponse) From 30e95b33a73ee80e98b2bb7ea66f3ea81e69e00b Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:46:14 -0300 Subject: [PATCH 14/16] Update README.md --- harbour/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/harbour/README.md b/harbour/README.md index 02cd2bf..77ce4fd 100644 --- a/harbour/README.md +++ b/harbour/README.md @@ -3,7 +3,7 @@ Para realizar uma requisição na API, utilize a função **"API_Omie"** Altere os parâmetros **APP_KEY** e **APP_SECRET** dentro do arquivo api.ini conforme as credenciais do seu aplicativo na Omie. -(http://docs.omie.com.br/m/20204/l/612759-obtendo-a-chave-de-acesso-para-integracoes-de-api)[http://docs.omie.com.br/m/20204/l/612759-obtendo-a-chave-de-acesso-para-integracoes-de-api] +[http://docs.omie.com.br/m/20204/l/612759-obtendo-a-chave-de-acesso-para-integracoes-de-api](http://docs.omie.com.br/m/20204/l/612759-obtendo-a-chave-de-acesso-para-integracoes-de-api) ## Parâmetros da Função: @@ -27,4 +27,4 @@ Altere os parâmetros **APP_KEY** e **APP_SECRET** dentro do arquivo api.ini con - *Esperado:* - - \[1\] : *Tipo:* Lógico | *Houve Erro:* .T. ou .F. - - \[2\] : *Tipo:* Hash | *Conteúdo retornado no JSON* - - - \[3\] : *Tipo:* Caracter | *Conteúdo retornado no Body da Resposta* \ No newline at end of file + - - \[3\] : *Tipo:* Caracter | *Conteúdo retornado no Body da Resposta* From 1ed41b2f1cda5f422279a7acb4005be02a9975b8 Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:47:02 -0300 Subject: [PATCH 15/16] Create api.ini --- harbour/api.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 harbour/api.ini diff --git a/harbour/api.ini b/harbour/api.ini new file mode 100644 index 0000000..4fb1d18 --- /dev/null +++ b/harbour/api.ini @@ -0,0 +1,3 @@ +[AUTH] +APP_KEY = suakey +APP_SECRET = suasecret From 56d18f7949f4d68eabbb99d9e9628085dbe3964c Mon Sep 17 00:00:00 2001 From: "Steve C. Evangelista" <44708676+scevangelista@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:50:13 -0300 Subject: [PATCH 16/16] Update README.md --- harbour/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/harbour/README.md b/harbour/README.md index 77ce4fd..36795e5 100644 --- a/harbour/README.md +++ b/harbour/README.md @@ -26,5 +26,5 @@ Altere os parâmetros **APP_KEY** e **APP_SECRET** dentro do arquivo api.ini con - *Tipo:* Array - *Esperado:* - - \[1\] : *Tipo:* Lógico | *Houve Erro:* .T. ou .F. - - - \[2\] : *Tipo:* Hash | *Conteúdo retornado no JSON* - - - \[3\] : *Tipo:* Caracter | *Conteúdo retornado no Body da Resposta* + - - \[2\] : *Tipo:* Hash | *Conteúdo retornado na resposta JSON* + - - \[3\] : *Tipo:* Caracter | *Conteúdo retornado no Body da resposta*