wundergrounded
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -146,4 +146,15 @@ 'use strict'; | ||
var apiEndpoint = function(service, query, callback) { | ||
_requests.push(service); | ||
var apiEndpoint = function(service, query, callback) { | ||
var requestExists = function(request) { | ||
for(var i = 0; i < _requests.length; i++) { | ||
var _request = _requests[i]; | ||
if(_request === request) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
if(!requestExists(service)) { | ||
_requests.push(service); | ||
} | ||
if(query && callback) { | ||
@@ -169,7 +180,9 @@ request(query, callback); | ||
else { | ||
var doRequest = function() { | ||
// Copy requests value and clear | ||
var services = _requests; | ||
_requests = []; | ||
// Function that actually does the request... used later | ||
var doRequest = function(_services, _query, _callback) { | ||
// Generate URL | ||
var url = 'http://api.wunderground.com/api/' + _apiKey + '/' + _requests.join('/') + '/q/' + query + '.json'; | ||
// Clear requests queue | ||
_requests = []; | ||
var url = 'http://api.wunderground.com/api/' + _apiKey + '/' + _services.join('/') + '/q/' + _query + '.json'; | ||
// Try to pull the data from the cache | ||
@@ -180,3 +193,3 @@ if(_cache) { | ||
if(_debug) log('[' + url + '] Returning cached response.'); | ||
callback(false, json); | ||
_callback(false, json); | ||
return this; | ||
@@ -199,3 +212,3 @@ } | ||
if(_debug) log('[' + url + '] Returning API response.'); | ||
callback(false, json); | ||
_callback(false, json); | ||
} | ||
@@ -205,3 +218,3 @@ // If this is a sad-path response, return an error | ||
if(_debug) log('[' + url + '] Request failed!'); | ||
callback(json, 'An error occurred while communicating with the Weather Underground API.'); | ||
_callback(json, 'An error occurred while communicating with the Weather Underground API.'); | ||
} | ||
@@ -212,3 +225,3 @@ } | ||
if(_debug) log('[' + url + '] Request failed!'); | ||
callback(error, 'Received an error when trying to connect to ' + url); | ||
_callback(error, 'Received an error when trying to connect to ' + url); | ||
} | ||
@@ -221,3 +234,3 @@ }); | ||
if(!error) { | ||
doRequest(); | ||
doRequest(services, query, callback); | ||
} | ||
@@ -228,3 +241,3 @@ }); | ||
else { | ||
doRequest(); | ||
doRequest(services, query, callback); | ||
} | ||
@@ -276,2 +289,2 @@ } | ||
}; | ||
}; |
{ | ||
"name": "wundergrounded", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/wundergrounded.js", |
@@ -215,3 +215,4 @@ # Wundergrounded | ||
* 0.1.4 Fixing race condition in limited requests | ||
* 0.1.3 Minor updates to README | ||
* 0.1.0 Initial release | ||
* 0.1.3 Minor updates to README |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21139
5
261
218