Skip to content

Instantly share code, notes, and snippets.

@goldcaddy77
Created December 28, 2018 23:19
Show Gist options
  • Save goldcaddy77/df22bb57fd118ff5f046a32c27f4554c to your computer and use it in GitHub Desktop.
Save goldcaddy77/df22bb57fd118ff5f046a32c27f4554c to your computer and use it in GitHub Desktop.
Apollo datasource REST
const {
RESTDataSource
} = require('apollo-datasource-rest');
class TellusAPI extends RESTDataSource {
constructor() {
super();
this.baseURL = 'https://api.kernel.telluslabs.com/api/v1/';
}
// https://api.kernel.telluslabs.com/api/v1/metrics/?
async getMetrics() {
const res = await this.get('metrics', {
api_key: process.env.ENGINE_API_KEY,
country_iso: 'USA',
geo_level: 'level_1',
metric_code: 'TLUSM2SMTH',
geo_id: '00',
time_format: 'timestamp',
include_metadata: 'true',
start_date: '2018-04-01',
end_date: '2018-11-14',
crop: 'corn'
});
return res && res.length ? res : [];
}
}
module.exports = TellusAPI;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment