goferito / node-bing-api

Node.js module for the Bing Search API (Cognitive Services)
MIT License
56 stars 28 forks source link

freshness #28

Closed xauxatz closed 7 years ago

xauxatz commented 7 years ago

Hi - does node-bing-api support the freshness parameter?

goferito commented 7 years ago

I think it should

xauxatz commented 7 years ago

In fact I verified the request in my debugger and it does not take "freshness" into account. What is worse, it doesn't take "skip" (offset) into account either... It is simply not build into the search string

ralyodio commented 7 years ago

I'm finding same things -- none of these are supported. Part of the problem with rewriting the api interface

        cc: 'US',
        freshness: 'Day',
        setLang: 'EN'
goferito commented 7 years ago

Ok, I'll look into it this week

ralyodio commented 7 years ago

for now you can get around it by doing this:

      bing.news(`javascript&freshness=Day&setLang=EN&cc=US`, {
        top: this.count,
        skip: this.skip
      }, (err, res, body) => {
        if (err) return reject(err);
        resolve(body);
      })

instead of mapping your custom option names to legit ones you should just take what we give you and turn them into key=value pairs in the query string. This is one liner with require('url').build(options)

anthonyettinger commented 7 years ago

any luck on this?

const querystring = require('querystring');
const qStr = querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' })

console.log(qStr); // returns 'foo=bar&baz=qux&baz=quux&corge='

https://nodejs.org/api/querystring.html#querystring_querystring_stringify_obj_sep_eq_options

ralyodio commented 7 years ago

submitted a pr:

https://github.com/goferito/node-bing-api/pull/32

goferito commented 7 years ago

Ok, I have accepted the PR and also refactored the code. Sorry it took so long, my account key was not valid any more and microsoft was failing when requesting a new one. I have merged the changes. I publish the new version. Let me know if everything is cool.

Btw, I'm planning to update the code to ES6 for the v4. As a tiny survey... would you find any inconvenience with that?

anthonyettinger commented 7 years ago

i'm already using es7 with --harmony-async-await flag so that's fine with me. I would avoid using babel on the server side though.

goferito commented 7 years ago

I would only use ES6 features supported on the stable version (6.9.5)

goferito commented 7 years ago

You can close this issue to confirm your satisfaction with the solution. An start on the repo would be also nice. Stars make developers happy :star: :smile:

xauxatz commented 7 years ago

Thanks :-)