This code seems as a good start indeed, is this somewhere on GitHub ? so i could put some additional stuff or even some modifications !
2017-04-10 14:32 GMT+02:00 Gustavo Frederico < [email protected]>: > You can use this as a starting point. > > Gustavo > > > var _recommendationInner = { > baseAjaxPromise: function (theData, url) { > return new Promise(function (resolve, reject) { > $.ajax({ > type: 'POST', > url: url, > data: JSON.stringify(theData), > contentType: 'text/plain', > xhrFields: { > withCredentials: false > }, > dataType: "json", > success: function(data) { > resolve(data); > }, > failure: function(errorMsg) { > console.error('Error ' + errorMsg); > reject(); > } > }) > .done(function(data) { > resolve(data); > }) > .fail(function(jqXHR, textStatus) { > console.error("error : " + textStatus); > console.error("error status text: " + > jqXHR.statusText); > console.error("error status: " + jqXHR.status); > reject(); > }); > }); > } > > }; > > var Recommendations = new function() { > > this.set = function(accessKey, eventsUrl, queriesUrl) { > Recommendations.eventsUrl = eventsUrl + '/events.json?accessKey=' > + accessKey; > Recommendations.queriesUrl = queriesUrl + > '/queries.json?accessKey=' + accessKey; > }; > > /** Events **/ > var viewProductPromise = function(user,product) { > var data = { > "event": 'view', > "entityType": "user", > "entityId": user, > "targetEntityType": "item", > "targetEntityId": product, > "eventTime" : new Date().toISOString() > }; > return _recommendationInner.baseAjaxPromise(data, > Recommendations.eventsUrl); > }; > > var purchaseProductPromise = function (user,product) { > var data = { > "event": "purchase", > "entityType": "user", > "entityId": user, > "targetEntityType": "item", > "targetEntityId": product, > "eventTime" : new Date().toISOString() > }; > return _recommendationInner.baseAjaxPromise(data, > Recommendations.eventsUrl); > }; > > /** Queries **/ > var getGeneralRecommendationsPromise = function (number) { > var data = { > "num" : number > }; > return _recommendationInner.baseAjaxPromise(data, > Recommendations.queriesUrl); > }; > > var getRecommendationsForUserPromise = function (user) { > var data = { > "user" : user > }; > return _recommendationInner.baseAjaxPromise(data, > Recommendations.queriesUrl); > }; > > var getRecommendationsPromise = function > (user,contextProduct,category) { > var fields = []; > > if (category) { > fields.push({ > "name": "category", > "values": [category], > "bias": -1 > }); > } > > var data = { > "user" : user, > "item" : contextProduct, > "fields" : fields > }; > return _recommendationInner.baseAjaxPromise(data, > Recommendations.queriesUrl); > }; > > > /** Events **/ > this.purchase = function (user,product,quantity,amount) { > return purchaseProductPromise(user,product,quantity,amount) > .then(nil => { return nil; }) > .catch(error => { throw error; }); > }; > > this.viewProduct = function (user,product, isStrong = false) { > return viewProductPromise(user, product, isStrong); > }; > > /** Queries **/ > this.getGeneralRecommendations = function (number) { > return getGeneralRecommendationsPromise(number); > }; > > this.getRecommendationsForUser = function (user) { > return getRecommendationsForUserPromise(user); > }; > > this.getRecommendations = function (user,contextProduct,category) { > return getRecommendationsPromise(user,contextProduct,category); > }; > > }; > > > On Mon, Apr 10, 2017 at 8:31 AM, Vaghawan Ojha <[email protected]> > wrote: > >> Hi, >> >> Ok, in that case I am currently not aware of any js SDK like you wanted. >> Someone else may help. >> >> Thanks >> >> On Mon, Apr 10, 2017 at 6:14 PM, Mohamed Zouga <[email protected]> >> wrote: >> >>> @vaghawan : i don't want to go posting my accessKey allover my requests >>> and writing verbose code when all i might use is a function with one >>> parameter or so. >>> @ Marius : Why have 3 dependencies (3 more files, supposing those files >>> don't have additional dependencies...) when i can use just Ajax to send my >>> events and requests >>> so any JS SDK out there ? >>> >>> 2017-04-10 14:23 GMT+02:00 Marius Rabenarivo <[email protected] >>> >: >>> >>>> Hello, >>>> >>>> The NodeJS SDK has the following dependencies : >>>> >>>> lodash >>>> request >>>> bluebird >>>> >>>> You can download them if you want. >>>> >>>> Regards, >>>> >>>> Marius >>>> >>>> 2017-04-10 16:18 GMT+04:00 Mohamed Zouga <[email protected]>: >>>> >>>>> I'am using PredictionIO in a web site, and i want to send the event >>>>> using Javascript (instead of PHP) is there any know SDK JS for >>>>> PredictionIO >>>>> (lastest) ? >>>>> i found some outdated ones in Github, i didn't want to rush into >>>>> coding one from scratch until i'am sure there is no existing ones, thank >>>>> you >>>>> P.S : I know there is a NodeJS SDK, i don't have npm and i don't want >>>>> any dependencies. >>>>> -- >>>>> >>>>> *Mohamed ZOUGA*Stagiaire Data Scientist, Wizaplace >>>>> [email protected] <[email protected]> | http://www.wizaplace.com >>>>> [image: https://www.linkedin.com/in/zouga-mohamed-44b02974/] >>>>> <https://www.linkedin.com/in/zouga-mohamed-44b02974/> >>>>> >>>> >>>> >>> >>> >>> -- >>> >>> *Mohamed ZOUGA*Stagiaire Data Scientist, Wizaplace >>> [email protected] <[email protected]> | http://www.wizaplace.com >>> [image: https://www.linkedin.com/in/zouga-mohamed-44b02974/] >>> <https://www.linkedin.com/in/zouga-mohamed-44b02974/> >>> >> >> > -- > You received this message because you are subscribed to the Google Groups > "actionml-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/actionml-user/CAGRFSSOcpSctEN5up894VAbG_qorUOpUFE5FtA9ZTLFMdyXwGA% > 40mail.gmail.com > <https://groups.google.com/d/msgid/actionml-user/CAGRFSSOcpSctEN5up894VAbG_qorUOpUFE5FtA9ZTLFMdyXwGA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- *Mohamed ZOUGA*Stagiaire Data Scientist, Wizaplace [email protected] <[email protected]> | http://www.wizaplace.com [image: https://www.linkedin.com/in/zouga-mohamed-44b02974/] <https://www.linkedin.com/in/zouga-mohamed-44b02974/>
