Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metno-client

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metno-client - npm Package Compare versions

Comparing version 0.1.2 to 0.1.4

55

lib/api_request.js
'use strict';
var debug = require('debug')('metno:request');
var request = require('request');
var xml2js = require('xml2js');
var utils = require('./utils');
var request = require('request');
var OPTIONS = { timeout: 5000, method: 'GET' };
var OPTIONS = { timeout: 5000, method: 'GET', gzip: true };

@@ -17,3 +17,2 @@ /**

options = utils.defaults({}, options, OPTIONS);
// console.log(options);

@@ -25,35 +24,27 @@ if (typeof format === 'function') {

var now = Date.now();
// debug('request options', options);
return request(options, function(err, res, body) {
var sc = res && res.statusCode;
debug('got request body in ' + (Date.now() - now), options.qs);
if (err) {
return callback(err);
} else if (sc === 203 || sc === 200) {
if (format === 'xml') {
new xml2js.Parser({
async: true,
mergeAttrs: true,
explicitArray: false
}).parseString(body, function(parseError, json) {
if (parseError) {
return callback(parseError);
}
// console.log('parsed request body in', Date.now() - time);
return callback(null, json);
});
} else {
return callback(null, body);
}
request(options, function(error, response, body) {
debug('got request response');
// var sc = res && res.statusCode;
// if(~[200, 203].indexOf(sc)){
// req.abort();
// }
if (format === 'xml') {
new xml2js.Parser({
async: true,
mergeAttrs: true,
explicitArray: false
}).parseString(body, function(parseError, json) {
if (parseError) {
return callback(parseError);
}
debug('parsed response from xml');
return callback(null, json);
});
} else {
return callback({
body: body,
statusCode: sc || 'No response received'
});
return callback(null, body);
}
}).on('response', function(response) {
debug('got request response in ' + (Date.now() - now), options.qs);
now = Date.now();
});
};

@@ -19,3 +19,5 @@ 'use strict';

if (options.params) {
opts.qs = options.params;
opts.url += '?' + Object.keys(options.params).map(function(key) {
return key + '=' + encodeURIComponent(options.params[key]);
}).join('&');
}

@@ -27,4 +29,2 @@

// debug('calling %s', url);
return apiRequest(opts, options.format, callback);

@@ -31,0 +31,0 @@ };

'use strict';
var debug = require('debug')('metno:get_weather');
var api = require('./api');

@@ -74,4 +75,6 @@ var utils = require('./utils');

}
debug('got weather report');
try {
data = formatData(data, options);
debug('formated weather report');
} catch (e) {

@@ -78,0 +81,0 @@ return callback(e);

{
"name": "metno-client",
"version": "0.1.2",
"version": "0.1.4",
"description": "met.no node.js client",

@@ -34,5 +34,5 @@ "main": "./lib/client.js",

"debug": "^2.2.0",
"request": "^2.69.0",
"request": "^2.72.0",
"xml2js": "^0.4.16"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc