eibbors / mws-js

Complete Amazon marketplace web services client for Node.js.
86 stars 102 forks source link

Fail to get even simple example to work #6

Open homanchou opened 11 years ago

homanchou commented 11 years ago

Can you please update the read me with some examples on how to create a product feed? I'm not even sure how to include the modules so that they can see each other. When I try to use new mws.feeds.requests.GetServiceStatus() I get an error that MWS_ORDERS is not defined.

danfinlay commented 11 years ago

I wrote instructions on this, but my pull request was never accepted: https://github.com/flyswatter/mws-js

homanchou commented 11 years ago

I saw your pull request, but my bug was related to the "unstable branch". I think my issue was a typo, MWS_ORDERS should have been MWS_FEEDS.

On Wed, Jun 26, 2013 at 8:03 AM, Dan Finlay notifications@github.comwrote:

I wrote instructions on this, but my pull request was never accepted: https://github.com/flyswatter/mws-js

— Reply to this email directly or view it on GitHubhttps://github.com/eibbors/mws-js/issues/6#issuecomment-20053725 .

danfinlay commented 11 years ago

My pull request did indeed explain this, as it was a README update. "Feeds" is not defined because it is not imported into mws.js by default. Go ahead and dig through mws.js yourself, you'll notice exports.feeds is not definend anywhere. I assume this is to minimize the memory overhead associated with importing resources you aren't using.

To add a resource (I'll use feeds as my example, since that's what you're looking for), you need to require it and export it from the mws.js file. So at the end of the mws.js file, you could write:

exports.feeds = require('./feeds')

Then calling mws.feeds will work, because you are importing the feeds.js file and exporting it as mws.feeds.

homanchou commented 11 years ago

Hmm... I think you're still referring to the master branch. If you git checkout unstable, there is a file called index.js ( https://github.com/eibbors/mws-js/blob/unstable/index.js) that already includes all the individual apis as you say.

Even if they are all exported, they are separate closures. So MWS_ORDERS, which is defined in lib/orders.js is not accessible from lib/feeds.js as line #111 attempts to do: https://github.com/flyswatter/mws-js/blob/unstable/lib/feeds.js#L111

By changing MWS_ORDERS to MWS_FEEDS, which IS defined in lib/feeds.js, then the following code will work:

var mws = require('mws-js/index.js');

var client = new mws.feeds.Client({merchantId:'...',accessKeyId:'...',secretAccessKey:'...'});

client.getServiceStatus(function(s,r){console.log(s,r);})

On Wed, Jun 26, 2013 at 8:56 AM, Dan Finlay notifications@github.comwrote:

My pull request did indeed explain this, as it was a README update. "Feeds" is not defined because it is not imported into mws.js by default. Go ahead and dig through mws.js yourself, you'll notice exports.feeds is not definend anywhere. I assume this is to minimize the memory overhead associated with importing resources you aren't using.

To add a resource (I'll use feeds as my example, since that's what you're looking for), you need to require it and export it from the mws.js file. So at the end of the mws.js file, you could write:

`exports.feeds = require('./feeds')

Then calling mws.feeds will work, because you are importing the feeds.js file and exporting it as mws.feeds.

— Reply to this email directly or view it on GitHubhttps://github.com/eibbors/mws-js/issues/6#issuecomment-20058895 .

danfinlay commented 11 years ago

Oh, I hadn't even seen that branch. I see the closure you mean, but don't have time to muck through it myself. Good luck getting a response here! Out of curiosity, why not use the stable branch?

homanchou commented 11 years ago

The master branch has no attention at all, the unstable branch has from forks and patches going on from other authors, some of them have added examples in a test folder. The unstable branch is a rewrite of the master branch using coffeescript, which makes it easier to read and write classes. The rewrite seems to have better structure, it uses inheritance and the api's are subclassed from the emitter. Neither of them can really be considered "stable".

On Wed, Jun 26, 2013 at 9:17 AM, Dan Finlay notifications@github.comwrote:

Oh, I hadn't even seen that branch. I see the closure you mean, but don't have time to muck through it myself. Good luck getting a response here! Out of curiosity, why not use the stable branch?

— Reply to this email directly or view it on GitHubhttps://github.com/eibbors/mws-js/issues/6#issuecomment-20060377 .