mirror of
https://github.com/HeyPuter/puter.git
synced 2026-02-19 21:21:23 -06:00
dev: begin implementing driver for newsdata.io
This commit is contained in:
@@ -9,6 +9,10 @@ class ExternalExtrasModule extends AdvancedBase {
|
||||
const { IPGeoService } = require('./IPGeoService');
|
||||
services.registerService('ipgeo', IPGeoService);
|
||||
}
|
||||
if ( !! config?.services?.newsdata ) {
|
||||
const { NewsDataService } = require('./NewsDataService');
|
||||
services.registerService('newsdata', NewsDataService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
58
src/backend/src/modules/external-extras/NewsDataService.js
Normal file
58
src/backend/src/modules/external-extras/NewsDataService.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const APIError = require("../../api/APIError");
|
||||
const BaseService = require("../../services/BaseService");
|
||||
|
||||
class NewsDataService extends BaseService {
|
||||
async ['__on_driver.register.interfaces'] () {
|
||||
const svc_registry = this.services.get('registry');
|
||||
const col_interfaces = svc_registry.get('interfaces');
|
||||
|
||||
col_interfaces.set('newsdata', {
|
||||
description: 'NewsData.io',
|
||||
methods: {
|
||||
newsdata: {
|
||||
description: 'Report geolocation information',
|
||||
parameters: {
|
||||
'*': {
|
||||
type: 'json',
|
||||
},
|
||||
},
|
||||
result: {
|
||||
type: 'json'
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static IMPLEMENTS = {
|
||||
newsdata: {
|
||||
async newsdata (parameters) {
|
||||
// doing this makes vscode recognize what's being required
|
||||
const require = this.require;
|
||||
|
||||
const axios = require('axios');
|
||||
const querystring = require('querystring');
|
||||
|
||||
const qstr = querystring.stringify({
|
||||
...parameters,
|
||||
|
||||
// Yep, API key reall does go in the query string.
|
||||
// This is what the docs say to do.
|
||||
apikey: this.config.apiKey,
|
||||
size: 10,
|
||||
});
|
||||
|
||||
const resp = await axios.request({
|
||||
method: 'GET',
|
||||
url: 'https://newsdata.io/api/1/latest?' + qstr,
|
||||
});
|
||||
|
||||
return resp.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
NewsDataService,
|
||||
};
|
||||
Reference in New Issue
Block a user