Skip to content

Commit

Permalink
api: don't force method to GET. #166
Browse files Browse the repository at this point in the history
  • Loading branch information
AlcaDesign committed Sep 9, 2016
1 parent 12d7e82 commit b954cac
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ var _ = require("./utils");

var api = function api(options, callback) {
// Set the url to options.uri or options.url..
var url = _.get(options.url, null) === null ? _.get(options.uri, null) : _.get(options.url, null);
var url = options.url || options.uri || null;

// Make sure it is a valid url..
if (!_.isURL(url)) { url = url.charAt(0) === "/" ? `https://api.twitch.tv/kraken${url}` : `https://api.twitch.tv/kraken/${url}`; }
if (_.isString(url) && !_.isURL(url)) {
url = `https://api.twitch.tv/kraken${url.charAt(0) === "/" ? "" : "/"}${url}`;
options.url = url;
}

// We are inside a Node application, so we can use the request module..
if (_.isNode()) {
request(_.merge(options, { url: url, method: "GET", json: true }), function (err, res, body) {
callback(err, res, body);
});
request(_.defaults(options, { url: url, method: "GET", json: true }), callback);
}
// Inside a web application, use jsonp..
else {
Expand Down

0 comments on commit b954cac

Please sign in to comment.