Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sunsetwx/sunburst.js
This library provides authorization handling and methods for accessing the Sunburst API.
https://github.com/sunsetwx/sunburst.js
api client client-library color geolocation nature nodejs photography prediction react-native sunburst sunburst-api sunburst-js sunrise sunset sunsetwx sunsetwx-api tourism weather
Last synced: about 1 month ago
JSON representation
This library provides authorization handling and methods for accessing the Sunburst API.
- Host: GitHub
- URL: https://github.com/sunsetwx/sunburst.js
- Owner: sunsetwx
- License: isc
- Created: 2017-05-27T05:42:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-26T01:43:19.000Z (over 5 years ago)
- Last Synced: 2024-06-16T17:56:54.723Z (3 months ago)
- Topics: api, client, client-library, color, geolocation, nature, nodejs, photography, prediction, react-native, sunburst, sunburst-api, sunburst-js, sunrise, sunset, sunsetwx, sunsetwx-api, tourism, weather
- Language: JavaScript
- Homepage: https://sunburst.sunsetwx.com/v1/docs
- Size: 215 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sunburst.js
### Sunburst API client library for JavaScript
This library provides authorization handling and methods for accessing the Sunburst API from [SunsetWx](https://sunsetwx.com/).
* Supports Node.js, React Native, and popular web browsers.
### Platform Support
Platform | Version
------------ | -------
Node.js | 6.5+
React Native | 0.54+## Installation and usage
JavaScript in-browser script tag usage:
* Place `dist/sunburst.iife.js` into your website's files.
```html
```
Installation using npm:
```sh
npm i sunburst.js
```Node.js 8.10+ usage:
```js
const SunburstJS = require('sunburst.js');
```Node.js 6.5+ usage:
```js
const SunburstJS = require('sunburst.js/dist/sunburst.node.js');
```Usage with React Native or your favorite module bundler:
```js
import SunburstJS from 'sunburst.js';
```## Getting started
Create a session pair. Also known as `clientId` and `clientSecret`, which are our API keys:
```js
(async () => {
try {
const sunburst = new SunburstJS();const session = await sunburst.createSession({
email: '[email protected]',
password: 'hunter2',
type: 'permanent',
scope: ['predictions']
});
console.log(session);
} catch (ex) {
// Handle general network or parsing errors.
return console.error(ex);
}
})();
```Now you can make API requests:
```js
let sunburst = new SunburstJS({
clientId: 'f78fe615-8eb1-48c4-be21-e5f4f437e8ba',
clientSecret: '18qwl0htsPX|[!NGQ@[qK{X;[&^EVzaH',
scope: ['predictions']
});
```Here is an example of making four quality prediction requests:
```js
(async () => {
try {
const now = new Date();
const thisTimeTomorrow = now.setDate(now.getDate() + 1);const resp = await sunburst.batchQuality([
{
geo: [40.7933949, -77.8600012],
type: 'sunrise'
},
{
geo: [40.7933949, -77.8600012],
type: 'sunset'
},
{
geo: [40.7933949, -77.8600012],
type: 'sunrise',
after: thisTimeTomorrow
},
{
geo: [40.7933949, -77.8600012],
type: 'sunset',
after: thisTimeTomorrow
}
]);resp.forEach(({ collection, error }) => {
if (error) {
// Handle individual query errors separately,
// as some queries may have still succeeded.
return console.error(error);
}
collection.features.forEach(({ properties }) => {
console.log(properties);
});
});
} catch (ex) {
// Handle general network or parsing errors.
return console.error(ex);
}
})();
```More examples, for each endpoint: [https://sunburst.sunsetwx.com/v1/docs](https://sunburst.sunsetwx.com/v1/docs?javascript=)
## License
The source code is available under the [ISC License](https://opensource.org/licenses/ISC).