Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

info result #13

Closed
vid opened this Issue Jan 28, 2013 · 8 comments

Comments

Projects
None yet
2 participants

vid commented Jan 28, 2013

I'd like to implement support for Semantic Mediawiki's ask.

http://semantic-mediawiki.org/wiki/Ask_API

however, while the action is ask, it doesn't populate data[ask] as api.js expects. it uses data[results].

is there a good way to resolve this?

thanks!

Owner

macbre commented Jan 29, 2013

Take a look at https://github.com/macbre/nodemw/blob/master/lib/api.js#L170

Callback passed to this.api.call is provided with a following parameters:

callback(info, next, data);

data contains "raw" data returned by API. That's the one with data you're interested to get from the server.

@macbre macbre closed this Jan 29, 2013

vid commented Jan 29, 2013

I'm sorry that I don't quite understand this, maybe it's because of my head cold. =) Does one of the other API calls provide an example?

I did implement a solution for this in my own code.

    getAsk: function(params, callback) {
        params.action = 'ask';
        params.resultKW = 'query';

        this.api.call(params).then(function(res) {
            callback && callback(res);
        });
    },

then in api.php:

                info = data && data[params.resultKW || actionName];
Owner

macbre commented Jan 29, 2013

If you're using a promise pattern, you should do the following:

    function(params, callback) {
        params.action = 'ask';
        params.resultKW = 'query';

        this.api.call(params).then(function(res) {
            callback && callback(res.data && res.data.results);
        });
    }

https://github.com/macbre/nodemw/blob/master/lib/api.js#L182

vid commented Jan 30, 2013

is code as intended?

https://github.com/macbre/nodemw/blob/master/lib/api.js#L171

shouldn't it be something like:

data[actionName] || data ?

otherwise it doesn't seem like the following block will get executed if the actionName doesn't match the return key.

https://github.com/macbre/nodemw/blob/master/lib/api.js#L178-L187

Owner

macbre commented Jan 31, 2013

Yeah, good point!

An if block at line 178 should be changed to allow that kind of responses to pass.

vid commented Feb 4, 2013

is this a change you can make? I don't quite understand the intent of this section of code (if there's going to be an else to pass it through anyway, why make an if at all). If you can do that, I can commit some additional actions.

I would like to add some code supporting emerging SMW javascript support, would this be ok to add to nodemw or can it be made modular?

thanks!

@macbre macbre reopened this Feb 5, 2013

Owner

macbre commented Feb 5, 2013

Sure, I'll make this change.

Then, fell free to add SMW specific actions :)

Owner

macbre commented Feb 6, 2013

Done in f12f420

@macbre macbre closed this Feb 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment