1.0.2 • Published 5 years ago

airnow v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

airnow.js

airnow is a module for making HTTP requests to the airnowapi.org webservices API.

Installation

npm install airnow --save

Quick Examples

var airnow = require('airnow');

var client = airnow({ apiKey: 'my airnow.org key' });

// get the forecast by zip
client.getForecastByZipCode({ zipCode: "53703" }, function(err, forecast){
	
});

// get the forecast by latitude and longitude
client.getForecastByLatLong({ latitude: 39.0509, longitude: -121.4453}, function(err, forecast){
	
});

// get the observations by zip
client.getObservationsByZipCode({ zipCode: "53703" }, function(err, observations){
	
});

// get the observations by latitude and longitude
client.getObservationsByLatLng({ latitude: 39.0509, longitude:-121.4453 }, function(err, observations){
	
});

// get the observations by a bounded box monitoring site
client.getObservationsByMonitoringSite({ bbox:{ minX: -122.715607, minY: 38.181254, maxX: -120.012970, maxY: 39.022646}, parameters:["pm25","o3"], datatype:"C"}, function(err, observations){
	
});

// get historical observations by a zip code
client.getHistoricalObservationsByZipCode({ zipCode:"53703", date: new Date(1448984256072) }, function(err, observations){
	
});

// get historical observations by latitude and longitude
client.getHistoricalObservationsByLatLng({ latitude: 39.0509, longitude:-121.4453, date: new Date(1448984256072) }, function(err, observations){
	
});

Features

  1. Forecasts
  2. Observations (current & historical)
  3. Brute force retries of the HTTP calls

getForecastByZipCode

Get a forecast for a zip code on a particular date.

example

var airnow = require('airnow');

var client = airnow({ apiKey: 'my airnow.org key' });

// build my options
var options = {
	zipCode: "53703",
	date: new Date(),
	distance: 100,
	format: "application/json"
};

// get the forecast by zip
client.getForecastByZipCode(options, function(err, forecast){
	if (err){
		console.log('derp! an error calling getForecastByZipCode: ' + err);
	} else {
		// the world is good! start processing the forecast
	}
});

options

ParameterDescriptionTypeRequired
zipCodeZip codeStringYes
dateDate of forecast. If date is omitted, the current forecast is returned.DateNo
distanceIf no reporting area is associated with the specified Zip Code, return a forecast from a nearby reporting area within this distance (in miles).NumberNo
formatFormat of the payload returned. Defaults to "application/json" and the response will be a parsed JSON object. "text/csv" "application/json" "application/xml"StringNo

getForecastByLatLong

Get a forecast for a latitude and longitude pair for a particular date

example

var airnow = require('airnow');

var client = airnow({ apiKey: 'my airnow.org key' });

// build my options
var options = {
	latitude: 38.33,
	longitude: -122.28,
	date: new Date(),
	distance: 100,
	format: "application/json"
};

// get the forecast by latitude and longitude
client.getForecastByLatLong(options, function(err, forecast){
	if (err){
		console.log('derp! an error calling getForecastByZipCode: ' + err);
	} else {
		// the world is good! start processing the forecast
	}
});

options

ParameterDescriptionTypeRequired
latitudeLatitude in decimal degreesNumberYes
longitudeLongitude in decimal degreesNumberYes
dateDate of forecast. If date is omitted, the current forecast is returned.DateNo
distanceIf no reporting area is associated with the specified latitude and longitude, return a forecast from a nearby reporting area within this distance (in miles).NumberNo
formatFormat of the payload returned. Defaults to "application/json" and the response will be a parsed JSON object. "text/csv" "application/json" "application/xml"StringNo

getObservationsByZipCode

Gets the current observations for a single zip code.

example

var airnow = require('airnow');

var client = airnow({ apiKey: 'my airnow.org key' });

// build my options
var options = {
	zipCode: "53703",
	distance: 100,
	format: "application/json"
};

// get the current observations by zip
client.getObservationsByZipCode(options, function(err, observations){
	if (err){
		console.log('derp! an error calling getObservationsByZipCode: ' + err);
	} else {
		// the world is good! start processing the observations
	}
});

options

ParameterDescriptionTypeRequired
zipCodeZip CodeStringYes
distanceIf no reporting area is associated with the specified Zip Code, return a forecast from a nearby reporting area within this distance (in miles).NumberNo
formatFormat of the payload returned. Defaults to "application/json" and the response will be a parsed JSON object. "text/csv" "application/json" "application/xml"StringNo

getObservationsByLatLng

Gets the current observations for a latitude and longitude pair.

example

var airnow = require('airnow');

var client = airnow({ apiKey: 'my airnow.org key' });

// build my options
var options = {
	latitude: 38.33,
	longitude: -122.28,
	distance: 100,
	format: "application/json"
};

// get the current observations by latitude and longitude
client.getObservationsByLatLng(options, function(err, observations){
	if (err){
		console.log('derp! an error calling getObservationsByLatLng: ' + err);
	} else {
		// the world is good! start processing the observations
	}
});

options

ParameterDescriptionTypeRequired
latitudeLatitude in decimal degreesNumberYes
longitudeLongitude in decimal degreesNumberYes
distanceIf no reporting area is associated with the specified latitude and longitude, return a forecast from a nearby reporting area within this distance (in miles).NumberNo
formatFormat of the payload returned. Defaults to "application/json" and the response will be a parsed JSON object. "text/csv" "application/json" "application/xml"StringNo

getObservationsByMonitoringSite

Get observations for a bounded box monitoring site.

example

var airnow = require('airnow');

var client = airnow({ apiKey: 'my airnow.org key' });

// build my options
var options = {
	latitude: 38.33,
	longitude: -122.28,
	distance: 100,
	format: "application/json"
};

// get the observations by monitoring site
client.getObservationsByMonitoringSite(options, function(err, observations){
	if (err){
		console.log('derp! an error calling getObservationsByMonitoringSite: ' + err);
	} else {
		// the world is good! start processing the observations
	}
});

options

ParameterDescriptionTypeRequired
latitudeLatitude in decimal degreesNumberYes
longitudeLongitude in decimal degreesNumberYes
distanceIf no reporting area is associated with the specified latitude and longitude, return a forecast from a nearby reporting area within this distance (in miles).NumberNo
formatFormat of the payload returned. Defaults to "application/json" and the response will be a parsed JSON object. "text/csv" "application/json" "application/xml"StringNo

getHistoricalObservationsByZipCode

Get historical observations for a zip.

example

var airnow = require('airnow');

var client = airnow({ apiKey: 'my airnow.org key' });

// build my options
var options = {
	zipCode: "53703",
	date: new Date(1448984256072),
	distance: 100,
	format: "application/json"
};

// get the historical observations by zip code
client.getHistoricalObservationsByZipCode(options, function(err, observations){
	if (err){
		console.log('derp! an error calling getHistoricalObservationsByZipCode: ' + err);
	} else {
		// the world is good! start processing the observations
	}
});

options

ParameterDescriptionTypeRequired
zipCodeZip CodeStringYes
datedate of observationsDateYes
distanceIf no reporting area is associated with the specified Zip Code, return a forecast from a nearby reporting area within this distance (in miles).NumberNo
formatFormat of the payload returned. Defaults to "application/json" and the response will be a parsed JSON object. "text/csv" "application/json" "application/xml"StringNo

getHistoricalObservationsByLatLng

Get historical observations for a latitude and longitude pair.

example

var airnow = require('airnow');

var client = airnow({ apiKey: 'my airnow.org key' });

// build my options
var options = {
	latitude: 38.33,
	longitude: -122.28,
	date: new Date(1448984256072),
	distance: 100,
	format: "application/json"
};

// get the historical observations by latitude and longitude
client.getHistoricalObservationsByLatLng(options, function(err, observations){
	if (err){
		console.log('derp! an error calling getHistoricalObservationsByLatLng: ' + err);
	} else {
		// the world is good! start processing the observations
	}
});

options

ParameterDescriptionTypeRequired
latitudeLatitude in decimal degreesNumberYes
longitudeLongitude in decimal degreesNumberYes
datedate of observationsDateYes
distanceIf no reporting area is associated with the specified latitude and longitude, return a forecast from a nearby reporting area within this distance (in miles).NumberNo
formatFormat of the payload returned. Defaults to "application/json" and the response will be a parsed JSON object. "text/csv" "application/json" "application/xml"StringNo

Contributing

The more PRs the merrier. :-)

1.0.2

5 years ago

1.0.1

8 years ago

1.0.0

8 years ago