src: Add eBird v2.0 API Wrapper
This commit is contained in:
parent
dc7b06ae93
commit
44b71c5296
|
@ -130,3 +130,4 @@ dist
|
|||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
lib
|
|
@ -0,0 +1,2 @@
|
|||
test
|
||||
src
|
|
@ -0,0 +1,5 @@
|
|||
# Change log
|
||||
|
||||
## v0.0.0
|
||||
|
||||
-
|
|
@ -1,3 +1,8 @@
|
|||
# ebird.js
|
||||
|
||||
Damn small node.js library to deal with eBird v2 API
|
||||
Damn small node.js library to deal with eBird v2 API
|
||||
|
||||
## References
|
||||
|
||||
- [eBird API v2 documentation](https://documenter.getpostman.com/view/664302/S1ENwy59)
|
||||
- [ebird-js by ProjectBabbler on npm](https://www.npmjs.com/package/ebird-js)
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "ebird",
|
||||
"version": "0.0.0",
|
||||
"description": "Damn small node.js library to deal with eBird v2 API",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://forge.chapril.org/UncleSamulus/ebird.js"
|
||||
},
|
||||
"keywords": [
|
||||
"eBird",
|
||||
"API"
|
||||
],
|
||||
"author": "Samuel ORTION",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"devDependencies": {
|
||||
"jest": "^29.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"dotenv": "^16.0.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
const axios = require('axios');
|
||||
|
||||
const BASE_URL = "https://api.ebird.org/v2"
|
||||
const API_KEY = process.env.EBIRD_API_KEY;
|
||||
|
||||
function query(endpoint, params) {
|
||||
let data = undefined;
|
||||
axios.get(`${BASE_URL}/${endpoint}`, {
|
||||
headers: {
|
||||
'X-eBirdApiToken': API_KEY
|
||||
},
|
||||
params: {
|
||||
...params
|
||||
}
|
||||
}).then((response) => {
|
||||
console.log('GET response');
|
||||
data = response.data;
|
||||
}).catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
function get(endpoint) {
|
||||
return params => {
|
||||
query(endpoint, params);
|
||||
}
|
||||
}
|
||||
|
||||
const ebird = {
|
||||
data: {
|
||||
obs: {
|
||||
recent: {
|
||||
in: (regionCode) => get(`data/obs/${regionCode}/recent`),
|
||||
recent: {
|
||||
in: (regionCode) => {
|
||||
return {
|
||||
for: (speciesCode) => get(`data/obs/${regionCode}/recent/${speciesCode}`)
|
||||
}
|
||||
},
|
||||
notable: {
|
||||
in: (regionCode) => get(`data/obs/${regionCode}/recent/notable`),
|
||||
},
|
||||
},
|
||||
},
|
||||
geo: {
|
||||
recent: {
|
||||
in: get(`data/obs/geo/recent`),
|
||||
species: (speciesCode) => get(`data/obs/geo/recent/${speciesCode}`),
|
||||
},
|
||||
},
|
||||
historic: {
|
||||
in: (regionCode) => {
|
||||
return {
|
||||
on: (year, month, day) => get(`data/${regionCode}/historic/${year}/${month}/${day}`)
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
nearest: {
|
||||
geo: {
|
||||
recent: {
|
||||
species: (speciesCode) => get(`data/nearest/geo/recent/${speciesCode}`),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
product: {
|
||||
lists: {
|
||||
get: (regionCode) => get(`product/lists/${regionCode}`),
|
||||
in: (regionCode) => {
|
||||
return {
|
||||
on: (year, month, day) => get(`product/lists/${regionCode}/${year}/${month}/${day}`)
|
||||
}
|
||||
},
|
||||
},
|
||||
top100: {
|
||||
in: (regionCode) => {
|
||||
return {
|
||||
on: (year, month, day) => get(`product/top100/${regionCode}/${year}/${month}/${day}`),
|
||||
}
|
||||
},
|
||||
},
|
||||
stats: {
|
||||
in: (regionCode) => {
|
||||
return {
|
||||
on: (year, month, day) => get(`product/stats/${regionCode}/${year}/${month}/${day}`)
|
||||
}
|
||||
}
|
||||
},
|
||||
spplist: {
|
||||
in: (regionCode) => get(`product/spplist/${regionCode}`),
|
||||
},
|
||||
checklist: {
|
||||
view: (subId) => get(`product/checklist/view/${subId}`),
|
||||
},
|
||||
},
|
||||
ref: {
|
||||
geo: {
|
||||
adjacent: {
|
||||
of: (regionCode) => get(`ref/geo/adjacent/${regionCode}`),
|
||||
},
|
||||
},
|
||||
hotspot: {
|
||||
in: (regionCode) => get(`ref/hotspot/${regionCode}`),
|
||||
geo: get(`ref/hostspot/geo`),
|
||||
info: (locId) => get(`ref/hotspot/info/${locId}`),
|
||||
},
|
||||
taxonomy: {
|
||||
ebird: get(`ref/taxonomy/ebird`),
|
||||
versions: get(`ref/taxonomy/versions`),
|
||||
},
|
||||
taxon: {
|
||||
forms: (speciesCode) => get(`ref/taxon/${speciesCode}`),
|
||||
},
|
||||
taxa_locales: {
|
||||
ebird: get(`ref/taxa-locales/ebird`),
|
||||
},
|
||||
sppgroup: (speciesGrouping) => get(`ref/sppgroup/${speciesGrouping}`),
|
||||
region: {
|
||||
info: (regionCode) => get(`ref/region/${regionCode}`),
|
||||
list: (regionType, parentRegionCode) => get(`ref/region/list/${regionTypie}/${parentRegionCode}`),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = ebird;
|
|
@ -0,0 +1,20 @@
|
|||
const ebird = require('../src/index');
|
||||
require('dotenv').config;
|
||||
|
||||
test('/data/obs/${regionCode}/recent for location France', () => {
|
||||
let data = ebird.obs.recent.in('FR');
|
||||
expect(data.length).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
|
||||
// test('get subregions from region code and type', () => {
|
||||
// let regionType = "country";
|
||||
// let regionCode = "world";
|
||||
// let regions = ebird.get_regions(regionType, regionCode);
|
||||
// expect(regions).toContain({ code: 'FR', name: 'France' });
|
||||
// });
|
||||
|
||||
// test('get region code from coordinates', () => {
|
||||
// let regionCode = ebird.coordinates2region(47.87842, 0.21826);
|
||||
// console.log(regionCode);
|
||||
// });
|
Loading…
Reference in New Issue