Skip to content

Move "url" attributes to fix endpoint selection #236

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2016

Conversation

g-may
Copy link
Contributor

@g-may g-may commented Apr 26, 2016

Summary

getFormat in helper.js should not immediately associate the "url" parameter with an Alchemy URL API call. Alchemy HTML and Text APIs can also pass "url" parameters.

Other Information

helper.js

  /**
   * Returns the first match from formats that is key the params map
   * otherwise null
   * @param  {Object}  params   The parameters
   * @param  {Array}  requires The keys we want to check
    */
  getFormat: function(params, formats) {
    if (!formats || !params)
      return null;

    for(var i = 0; i < formats.length; i++) {
      if (formats[i] in params)
        return formats[i];
    }
    return null;
  }

alchemy_language/v1.js

var endpoints      = require('../../lib/alchemy_endpoints.json');
...
function createRequest(method) {
  return function(_params, callback ) {
    var params = _params || {};
    var accepted_formats = Object.keys(endpoints[method]);
    var format = helper.getFormat(params, accepted_formats);

getFormat in helper.js should not immediately associate the "url" parameter with a URL API call. HTML and Text APIs can also pass "url" parameters
@nfriedly
Copy link
Contributor

I think this is OK to merge since it fixes a real bug, but it feels like it might get broken again fairly easily. Do you think you could also add in some unit tests and comments to validate the correct behavior and explain what's going on there?

Or, alternatively, could we make a change (perhaps rename url to endpoint_url) to make this a little safer?

@germanattanasio
Copy link
Contributor

can you do this @g-may ?

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

Successfully merging this pull request may close these issues.

3 participants