103 lines
2.9 KiB
Plaintext
103 lines
2.9 KiB
Plaintext
IMPORT util
|
|
IMPORT com
|
|
IMPORT os
|
|
IMPORT security
|
|
|
|
TYPE t_sync_cmd RECORD
|
|
oper STRING,
|
|
data STRING
|
|
END RECORD
|
|
DEFINE s, cmd,usuario,clave STRING
|
|
MAIN
|
|
CONNECT TO 'smarmotech' USER 'jsoto' USING 'lmmjvsd2014'
|
|
CALL categorias()
|
|
END MAIN
|
|
FUNCTION categorias()
|
|
DEFINE metodo,url,selec,ret,res STRING,
|
|
categoria RECORD
|
|
NAME,IMAGE STRING
|
|
END RECORD,
|
|
http_req com.HTTPRequest,
|
|
http_resp com.HTTPResponse,
|
|
data t_sync_cmd
|
|
|
|
|
|
LET url = 'https://shop.marmotech.com.do/wp-json/wc/v3/products/categories'
|
|
|
|
LET selec = "SELECT a.descripcion_esp FROM categorias a ORDER BY a.id_categoria"
|
|
|
|
PREPARE comando FROM selec
|
|
DECLARE busca_cat CURSOR FOR comando
|
|
|
|
LET data.oper = 'products/categories'
|
|
|
|
FOREACH busca_cat INTO categoria.*
|
|
LET data.data = util.JSON.stringify(categoria)
|
|
LET cmd= util.JSON.stringify(data)
|
|
LET cmd = url CLIPPED,"?name=",categoria.NAME CLIPPED
|
|
|
|
CALL sync_send_command(url,cmd) RETURNING ret,res
|
|
DISPLAY "RESPUESTA ",ret," ",res
|
|
END FOREACH
|
|
|
|
END FUNCTION
|
|
|
|
|
|
FUNCTION sync_send_command(url, cmd)
|
|
|
|
DEFINE url, cmd STRING
|
|
DEFINE result, tmp STRING
|
|
DEFINE http_req com.HTTPRequest
|
|
DEFINE http_resp com.HTTPResponse
|
|
|
|
LET usuario = "ck_f41ca9ba9ec888d82243a7c24717af625c26f834"
|
|
LET clave = "cs_dbd762cb45184e3badc5a114b8f4a30c19f114fc"
|
|
|
|
TRY LET http_req = com.HTTPRequest.Create(cmd)
|
|
CALL http_req.setAuthentication(usuario,clave,"Basic",NULL)
|
|
CALL http_req.setKeepConnection(TRUE)
|
|
|
|
|
|
CALL http_req.setConnectionTimeout(40)
|
|
CALL http_req.setTimeout(40)
|
|
CALL http_req.setMethod("POST")
|
|
CALL http_req.setCharset("UTF-8")
|
|
|
|
|
|
DISPLAY "data ",cmd
|
|
# CALL http_req.doTextRequest(cmd)
|
|
CALL http_req.doRequest()
|
|
LET http_resp=http_req.getResponse()
|
|
IF http_resp.getStatusCode() != 200 THEN
|
|
RETURN http_resp.getStatusCode(), http_resp.getStatusDescription()
|
|
END IF
|
|
LET tmp = http_resp.getStatusDescription()
|
|
IF (tmp == "OK" || tmp == "no error" ) THEN
|
|
RETURN -1, SFMT("HTTP request status description: %1 ",tmp)
|
|
END IF
|
|
LET result = http_resp.getTextResponse()
|
|
CATCH
|
|
RETURN -2, SFMT("HTTP request error: STATUS=%1 (%2)",STATUS,SQLCA.SQLERRM)
|
|
END TRY
|
|
|
|
RETURN 0, result
|
|
|
|
END FUNCTION
|
|
|
|
FUNCTION show_sync_err(msg)
|
|
DEFINE msg STRING
|
|
CALL fgl_winmessage(%"ERROR", msg, "exclamation")
|
|
END FUNCTION
|
|
|
|
FUNCTION b64_to_file(str_b64,f_sal)
|
|
|
|
DEFINE f_sal,str_b64,str_aux STRING
|
|
|
|
TRY
|
|
CALL security.Base64.SaveBinary(f_sal,str_b64)
|
|
CATCH
|
|
DISPLAY " data ",str_b64
|
|
LET str_aux="Unable to convert Base64 String to file :",STATUS
|
|
CALL fgl_winmessage("Error",str_aux,"stop")
|
|
END TRY
|
|
END FUNCTION |