node-sunsetwx is a Node.js wrapper for SunsetWx's Sunburst API, which provides sunset and sunrise quality forecasts.
Currently, the API is in beta. To get started you need to email team@sunsetwx.com to get a registration key.
You'll want to reference the Sunburst API docs for more detailed info on parameters and responses.
$ npm install node-sunsetwx
Before you interact with the API, you need to register your email address and password using the registration key you received. This is a one-time task. An email confirmation will be sent, which you need to acknowledge before you'll be able to log in.
Since you'll only be doing this once, you might as well do it in the interactive Node.js REPL:
$ node
Load the library:
var SunsetWx = require('node-sunsetwx');
Create the API object, including your email, a password (longer than six characters, at least one uppercase, one lowercase, and one number), and your registration key:
var sunsetwx = new SunsetWx({
email: 'you@example.com',
password: '12345Ab',
key: 'fOd2dUpB3L5oq42CKOq7NPsX'
});
Call the .register
method, with a callback to print the response:
sunsetwx.register(function(err, response, body){
console.log(body);
});
You should see this:
{
"message": "Verification email sent"
}
Click the link in the verification email before continuing.
Note: all callbacks are passed directly to the requests
library, which handles the actual https request. Thus, callbacks will receive the following as described by requests
:
- An
error
, if applicable - An
http.IncomingMessage
object - The
response
body, as a JSON object
For much more detail on API parameters and responses, please read the Sunburst API Docs.
Creates a new API object with (minimally) your email and password. Automatically handles login, authentication, and auth token refresh.
var sunsetwx = new SunsetWx({
email: 'you@example.com',
password: '12345Ab'
});
email
: (required) the email you signed up withpassword
: (required) the password you chose when registeringkey
: (optional) your registration key, only required for registrationrequest_options
: (optional) options to pass to the defaultrequest
object. Available options are listed on the library's github page.
Registers the email
and password
using the key
provided to the constructor.
sunsetwx.register(callback)
Logs in using the email
and password
provided to the constructor, storing the auth token for use during subsequent API calls. This is handled automatically, so you should actually never have to call .login()
manually.
sunsetwx.login(callback)
Logs out the current auth token and destroys it.
sunsetwx.logout(callback)
Triggers a password reset request. You will receive an email with a link to complete the process.
sunsetwx.passwordReset(callback)
Deletes the current account. Note: this cannot be undone.
sunsetwx.deleteAccount(callback)
Returns longitude and latitude coordinates for the given location
string.
sunsetwx.coordinates({
location: 'Rochester, NY'
}, callback)
location
: (required) a string that contains a location name
Returns a location name for the coordinates in coords
sunsetwx.location({
coords: '-77.331536,43.271152'
}, callback)
coords
: (required) a string that contains valid longitude and latitude, separated by only a comma.
sunsetwx.quality({
coords: '-77.331536,43.271152',
type: 'sunset',
location: 'northamerica',
radius: '24.02',
limit: '42',
timestamp: '2016-07-07T16:26:08Z'
}, callback)
coords
: (required) a string that contains valid longitude and latitude, separated by only a comma.type
: (required) a string to indicate 'sunrise' or 'sunset'location
: (optional) a string containing a valid model location of 'global' or 'northamerica'radius
: (optional) a number that limits the returned points to the indicated radius in kilometers.limit
: (optional) an integer that limits the number of returned pointstimestamp
: (optional) a valid RFC3339 timestamp within the next three days, for prediction of future sunrises and sunsets.
Sure.
This software is licensed under the MIT License. See the LICENSE file for details.