davidchambers / tutor

JavaScript interface for the Gatherer card database
https://gatherer.wizards.com/
Do What The F*ck You Want To Public License
149 stars 18 forks source link

Requesting card id as string fails #56

Closed bernatfortet closed 11 years ago

bernatfortet commented 11 years ago

I keep getting these error where the request understands the id, but the tutor.card methods doesn't.

I am not sure what else should I say about it. I can give you more information if needed.

Thanks in advance.

app.get('/api/v1/cards/:id', (request, response) ->

    console.log( request.params.id.toString() ) 

    tutor.card request.params.id, (err, card) ->
        console.log( card ) 

)
C:\Users\BernatMBPWin\Desktop\card-fight-club\node>coffee app
   info  - socket.io started
Initializing Multiplayer
Express server listening on port 8080
172783

C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\lib\tutor.js:51
      return legality = data.legality, versions = data.versions, data;
                            ^
TypeError: Cannot read property 'legality' of undefined
    at tutor.card (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\lib\tutor.js:51:29)
    at tutor.card.get (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\lib\tutor.js:32:9)
    at Request.module.exports [as _callback] (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\lib\gatherer\printings.js:25:16)
    at Request.init.self.callback (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\node_modules\request\main.js:122:22)
    at Request.EventEmitter.emit (events.js:99:17)
    at Request.<anonymous> (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\node_modules\request\main.js:661:16)
    at Request.EventEmitter.emit (events.js:126:20)
    at IncomingMessage.Request.start.self.req.self.httpModule.request.buffer (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\node_modules\request\main.js:623:14)
    at IncomingMessage.EventEmitter.emit (events.js:126:20)
    at IncomingMessage._emitEnd (http.js:366:10)

C:\Users\BernatMBPWin\Desktop\card-fight-club\node>
robdennis commented 11 years ago

I feel like you've checked the fact that you're searching for a good name, but isn't this a similar message to searching for a non-existent card name using the command line interface? Thanks, -Rob

On Mon, Jun 10, 2013 at 4:12 AM, Bernat Fortet notifications@github.com wrote:

I keep getting these error where the request understands the id, but the tutor.card methods doesn't. I am not sure what else should I say about it. I can give you more information if needed. Thanks in advance.

app.get('/api/v1/cards/:id', (request, response) ->
  console.log( request.params.id.toString() ) 
  tutor.card request.params.id, (err, card) ->
      console.log( card ) 
)
C:\Users\BernatMBPWin\Desktop\card-fight-club\node>coffee app
   info  - socket.io started
Initializing Multiplayer
Express server listening on port 8080
172783
C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\lib\tutor.js:51
      return legality = data.legality, versions = data.versions, data;
                            ^
TypeError: Cannot read property 'legality' of undefined
    at tutor.card (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\lib\tutor.js:51:29)
    at tutor.card.get (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\lib\tutor.js:32:9)
    at Request.module.exports [as _callback] (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\lib\gatherer\printings.js:25:16)
    at Request.init.self.callback (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\node_modules\request\main.js:122:22)
    at Request.EventEmitter.emit (events.js:99:17)
    at Request.<anonymous> (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\node_modules\request\main.js:661:16)
    at Request.EventEmitter.emit (events.js:126:20)
    at IncomingMessage.Request.start.self.req.self.httpModule.request.buffer (C:\Users\BernatMBPWin\Desktop\card-fight-club\node\node_modules\tutor\node_modules\request\main.js:623:14)
    at IncomingMessage.EventEmitter.emit (events.js:126:20)
    at IncomingMessage._emitEnd (http.js:366:10)
C:\Users\BernatMBPWin\Desktop\card-fight-club\node>

Reply to this email directly or view it on GitHub: https://github.com/davidchambers/tutor/issues/56

davidchambers commented 11 years ago

tutor.card has a shorthand form where the first argument is either a number or a string. I suspect the problem here is that you're passing something like '123' rather than 123, so Tutor's interpreting it as a card name rather than as a Gatherer id. Try this:

-    tutor.card request.params.id, (err, card) ->
+    tutor.card +request.params.id, (err, card) ->
bernatfortet commented 11 years ago

@davidchambers thank you very much that + helped a lot. It works like a charm.

davidchambers commented 11 years ago

Great. The other option is to be explicit, in which case it doesn't matter whether the value is a string or a number:

tutor.card id: request.params.id, (err, card) ->
  # ...