Browse Source

Swap factory function for wrapper function in reduce callback

Looks simpler and saves a level of indentation
pull/15/head
Luke Childs 8 years ago
parent
commit
d4b4f42c25
  1. 6
      src/index.js

6
src/index.js

@ -30,15 +30,14 @@ class Onionoo {
// Return object containing endpoint methods
return this.options.endpoints.reduce((onionoo, endpoint) => {
onionoo[endpoint] = this.createEndpointMethod(endpoint);
onionoo[endpoint] = options => this.get(endpoint, options);
return onionoo;
}, {});
}
// Returns a function to make requests to a given endpoint
createEndpointMethod(endpoint) {
return options => {
get(endpoint, options) {
// Build query string (don't encode ':' for search filters)
const qs = querystring.encode(options).replace(/%3A/g, ':');
@ -86,7 +85,6 @@ class Onionoo {
return response;
});
});
};
}
// Returns a promise for a request

Loading…
Cancel
Save