Skip to content

Instantly share code, notes, and snippets.

@claytonzaugg
Created June 14, 2016 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claytonzaugg/a2780eadefbfbb045ee04b9d27d9e0c8 to your computer and use it in GitHub Desktop.
Save claytonzaugg/a2780eadefbfbb045ee04b9d27d9e0c8 to your computer and use it in GitHub Desktop.
var amazon = Meteor.npmRequire('amazon-product-api');
var client = amazon.createClient({
awsId: "#####",
awsSecret: "#####",
awsTag: "#####"
});
Meteor.methods({
'searchAmazon': function(searchParameters) {
check(searchParameters, String);
console.log(searchParameters);
return client.itemSearch({
keywords: searchParameters,
searchIndex: 'All',
responseGroup: 'ItemAttributes,Offers,Images'
}).then(function(results) {
// console.log(results[4].DetailPageURL);
return results;
}).catch(function(err) {
console.log(err);
});
},
'addToAmazonCart': function(itemsToAdd) {
check(itemsToAdd, String);
console.log(itemsToAdd);
client.cartCreate({
'Item.1.ASIN': 'itemsToAdd.data.ASIN[[0]',
'Item.1.Quantity': '1'
}).then(function(results) {
console.log(results);
return results;
}).catch(function(err) {
console.log(err);
});
}
});
Template.itemTile.events({
'click .add-to-cart': function() {
var that = this;
Meteor.call('addToAmazonCart', that.ASIN, function (error, result) {
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment