8000 WAD · nickolasclarke/openaq@d33b2b4 · GitHub
[go: up one dir, main page]

Skip to content

Commit d33b2b4

Browse files
WAD
1 parent d965676 commit d33b2b4

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

.gitignore

100644100755
File mode changed.

LICENSE

100644100755
File mode changed.

README.md

100644100755
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,64 @@
11
# openaq
22
A ES6 promise-based JS client for the [OpenAQ](https://openaq.org) API
3+
4+
## Install:
5+
6+
`npm install openaq`
7+
8+
## API:
9+
10+
### getCities([options])
11+
- example:
12+
```javascript
13+
14+
getCities().then(results => {
15+
//results here
16+
})
17+
18+
```
19+
20+
getCountries([options])
21+
- example:
22+
```javascript
23+
getCountries().then(results => {
24+
//results here
25+
})
26+
27+
```
28+
getFetches([options])
29+
- example:
30+
```javascript
31+
getFetches.then(results = {
32+
//results here
33+
})
34+
```
35+
36+
getLatest([options])
37+
- example:
38+
```javascript
39+
40+
```
41+
42+
getLocations([options])
43+
- example:
44+
```javascript
45+
46+
```
47+
48+
getMeasurments([options])
49+
- example:
50+
```javascript
51+
52+
```
53+
54+
getParams()
55+
- example:
56+
```javascript
57+
58+
```
59+
60+
getSources([options])
61+
- example:
62+
```javascript
63+
64+
```

app.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const babel = ('babel')
2+
const fetch = require('isomorphic-fetch')
3+
4+
const url = '//api.openaq.org'
5+
const get = (endpoint, options) => {
6+
if (!options) {
7+
return fetch(url + endpoint)
8+
.then(response => {
9+
if (response.status >= 400) {
10+
throw new Error("Bad response from server")
11+
}
12+
return response.json()
13+
})
14+
}
15+
return fetch(url + endpoint + options)
16+
.then(response => {
17+
if (response.status >= 400) {
18+
throw new Error("Bad response from server")
19+
}
20+
return response.json()
21+
})
22+
}
23+
24+
export default class OpenAQ {
25+
cities(options) {
26+
options => {
27+
if (options) return get('/v1/cities/' + options)
28+
return get('/v1/cities/')
29+
}
30+
}
31+
32+
countries(options) {
33+
options => {
34+
if (options) return get('/v1/countries/' + options)
35+
return get('/v1/countries/')
36+
}
37+
}
38+
fetches(options) {
39+
options => {
40+
if (options) return get('/v1/fetches/' + options)
41+
return get('/v1/fetches/')
42+
}
43+
}
44+
latest(options) {
45+
options => {
46+
if (options) return get('/v1/latest/' + options)
47+
return get('/v1/latest/')
48+
}
49+
}
50+
locations(options){
51+
options => {
52+
if (options) return get('/v1/locations/' + options)
53+
return get('/v1/locations/')
54+
}
55+
}
56+
measurements(options){
57+
options => {
58+
if (options) return get('/v1/measurements/' + options)
59+
return get('/v1/measurements/')
60+
}
61+
}
62+
params(){
63+
options => {
64+
if (options) return get('/v1/params/' + options)
65+
return get('/v1/params/')
66+
}
67+
}
68+
sources(options){
69+
options => {
70+
if (options) return get('/v1/sources/' + options)
71+
return get('/v1/sources/')
72+
}
73+
}
74+
}

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "openaq",
3+
"version": "0.0.1",
4+
"description": "A JS client for the OpenAQ API",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/nickolasclarke/openaq.git"
12+
},
13+
"keywords": [
14+
"openAQ",
15+
"air",
16+
"quality",
17+
"AQ",
18+
"AQI"
19+
],
20+
"author": "Nick Clarke <nickolasclarke@gmail.com>",
21+
"license": "MIT",
22+
"bugs": {
23+
"url": "https://github.com/nickolasclarke/openaq/issues"
24+
},
25+
"homepage": "https://github.com/nickolasclarke/openaq#readme"
26+
}

0 commit comments

Comments
 (0)
0