1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
PROCEDURE AppelWS_RechercheProduit(sID est une chaîne)
sUrl est une chaîne = gsURLOFF+"/api/v0/produit/%1.json"
sUrl = ChaîneConstruit(sUrl,SansEspace(sID))
stReponseTemp est un STREPONSE
bufImage est un Buffer
tabIngédrients est un tableau de chaîne
sTMPRes est une chaîne
nPos1 est un entier
nPos2 est un entier
nPos3 est un entier
sUrl="http://fr.openfoodfacts.org/api/v0/produit/3560070718542.json"
// Requête au WebService
SI PAS HTTPRequête(sUrl,"","","","","","") ALORS
//ExécuteThreadPrincipal(CallbackWS,Vrai,"Impossible de contacter la base de données." + RC + "Vérifiez votre connexion à internet.")
SINON
// Récupération du résultat
buf est un Buffer = HTTPDonneRésultat()
SI buf ~= "" ALORS
ExécuteThreadPrincipal(CallbackWS,Vrai,"Impossible de contacter la base de données." + RC + "Vérifiez votre connexion à internet.")
SINON
// Désérialisation
Désérialise(stReponseTemp,buf,psdJSON)
// Produit inconnu : propose de l'ajouter
SI stReponseTemp.status = 0 ALORS
ExécuteThreadPrincipal(CallbackProduitInconnu,sID)
SINON
SI stReponseTemp.product.image_url <> "" _ET_ HTTPRequête(stReponseTemp.product.image_url) ALORS
bufImage = HTTPDonneRésultat()
FIN
// Analyse des ingrédients
sTMPRes = stReponseTemp.product.ingredients_text
TANTQUE sTMPRes <> ""
nPos1 = Position(sTMPRes,",")
nPos2 = Position(sTMPRes,"(")
SI nPos1 > nPos2 _ET_ nPos2 > 0 ALORS
nPos3 = Position(sTMPRes,")")
nPos1 = Position(sTMPRes,",",nPos3)
FIN
SI nPos1 = 0 ALORS
TableauAjoute(tabIngédrients,SansEspace(sTMPRes))
sTMPRes = ""
SINON
TableauAjoute(tabIngédrients,SansEspace(sTMPRes[[1 A (nPos1-1)]]))
sTMPRes = sTMPRes[[(nPos1+1) A]]
FIN
FIN
// Affichage des ingrédients
ExécuteThreadPrincipal(CallbackWS,Faux,"",stReponseTemp.product.product_name,bufImage,tabIngédrients)
FIN
FIN
FIN |
Partager