Skip to content

Commit

Permalink
Request#get callback now receives both err and res
Browse files Browse the repository at this point in the history
  • Loading branch information
hakanensari committed Feb 7, 2012
1 parent 5b3edfa commit 3627800
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -34,7 +34,7 @@ req
operation: 'ItemSearch'
keywords: 'Deleuze'
searchIndex: 'All'
.get (res) ->
.get (err, res) ->
for item in res.find 'Item'
console.dir item
```
Expand Down
2 changes: 1 addition & 1 deletion examples/batch_lookup.coffee
Expand Up @@ -23,5 +23,5 @@ req.add
'ItemLookup.1.ItemId': asins[0..9]
'ItemLookup.2.ItemId': asins[10..19]

req.get (res) ->
req.get (err, res) ->
console.log util.inspect res.toObject(), false, null
2 changes: 1 addition & 1 deletion examples/item_lookup.coffee
Expand Up @@ -10,5 +10,5 @@ req.add
operation: 'ItemLookup'
itemId: '0816614024'

req.get (res) ->
req.get (err, res) ->
console.log util.inspect res.find('Item'), false, null
2 changes: 1 addition & 1 deletion examples/item_search.coffee
Expand Up @@ -11,5 +11,5 @@ req.add
keywords: 'Deleuze'
searchIndex: 'All'

req.get (res) ->
req.get (err, res) ->
console.log util.inspect res.find('Item'), false, null
2 changes: 1 addition & 1 deletion examples/multiple_country_lookup.coffee
Expand Up @@ -10,5 +10,5 @@ for locale in Object.keys Hoover::HOSTS
.add
operation: 'ItemLookup'
itemId: '0816614024'
.get (res) ->
.get (err, res) ->
console.log util.inspect res.find('Item'), false, null
6 changes: 3 additions & 3 deletions examples/remote_cart.coffee
Expand Up @@ -11,7 +11,7 @@ req
operation: 'ItemLookup'
itemId: '0816614024'
responseGroup: 'Offers'
.get (res) ->
.get (err, res) ->
id = res.find('OfferListingId')[0]
req
.reset()
Expand All @@ -20,5 +20,5 @@ req
'Item.1.OfferListingId': id
'Item.1.Quantity': 1

req.get (res) ->
console.log util.inspect res.find('Cart'), false, null
req.get (err, res) ->
console.log inspect res.find('Cart'), false, null
8 changes: 4 additions & 4 deletions lib/hoover/request.js
Expand Up @@ -48,21 +48,21 @@
return this;
};

Request.prototype.get = function(callback, errback) {
Request.prototype.get = function(callback) {
var options;
options = {
host: this.host(),
path: "/onca/xml?" + (this._query())
};
return http.get(options, function(res) {
http.get(options, function(res) {
var data;
data = '';
return res.on('data', function(chunk) {
return data += chunk;
}).on('end', function() {
return callback(new Response(data, res.statusCode));
return callback(null, new Response(data, res.statusCode));
}).on('error', function(e) {
if (errback) return errback(e);
return callback(e);
});
});
};
Expand Down
11 changes: 7 additions & 4 deletions src/hoover/request.coffee
Expand Up @@ -50,8 +50,9 @@ class Request

this

# Performs a request and returns a [Response](./response.html).
get: (callback, errback) ->
# Performs a request and takes a callback that will receive either a
# [Response](./response.html) or an error.
get: (callback) ->
options =
host: @host()
path: "/onca/xml?#{@_query()}"
Expand All @@ -62,9 +63,11 @@ class Request
.on 'data', (chunk) ->
data += chunk
.on 'end', ->
callback new Response data, res.statusCode
callback null, new Response data, res.statusCode
.on 'error', (e) ->
errback e if errback
callback e

return

# The Amazon endpoint.
host: ->
Expand Down

0 comments on commit 3627800

Please sign in to comment.