From f8c7f4d40c3079f4e37d54a8e27b6809ab93ff14 Mon Sep 17 00:00:00 2001 From: yuenmichelle1 Date: Mon, 20 Nov 2023 14:52:28 -0600 Subject: [PATCH] add eras-client for projects stats callouts --- lib/config.js | 9 +++++++++ lib/eras-client.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 lib/eras-client.js diff --git a/lib/config.js b/lib/config.js index 25613aa..69a8995 100644 --- a/lib/config.js +++ b/lib/config.js @@ -42,11 +42,19 @@ var STAT_HOSTS = { test: 'https://stats-staging.zooniverse.org' }; +var ERAS_HOSTS = { + production: 'https://eras.zooniverse.org', + staging: 'https://eras-staging.zooniverse.org', + development: 'https://eras-staging.zooniverse.org', + test: 'https://eras-staging.zooniverse.org' +}; + var hostFromShell = process.env.PANOPTES_API_HOST; var appFromShell = process.env.PANOPTES_API_APPLICATION; var talkFromShell = process.env.TALK_HOST; var sugarFromShell = process.env.SUGAR_HOST; var statFromShell = process.env.STAT_HOST; +var erasFromShell = process.env.ERAS_HOST; var oauthFromShell = process.env.OAUTH_HOST; var envFromBrowser = locationMatch(/\W?env=(\w+)/); @@ -88,6 +96,7 @@ module.exports = { talkHost: talkFromShell || TALK_HOSTS[env], sugarHost: sugarFromShell || SUGAR_HOSTS[env], statHost: statFromShell || STAT_HOSTS[env], + erasHost: erasFromShell || ERAS_HOSTS[env], oauthHost: oauthFromShell || OAUTH_HOSTS[env], params: defaultParams, jsonHeaders: JSON_HEADERS diff --git a/lib/eras-client.js b/lib/eras-client.js new file mode 100644 index 0000000..c028425 --- /dev/null +++ b/lib/eras-client.js @@ -0,0 +1,31 @@ +var config = require('./config'); +var JSONAPIClient = require('./json-api-client'); +var makeHTTPRequest = JSONAPIClient.makeHTTPRequest; + +var erasClient = { + query: function (params) { + if (params.type === undefined) { + return Promise.reject(new Error('Missing required parameter: type (either classifications or comments) must be specified.')); + } + + var data = {}; + if (params.workflowID) { + data['workflow_id'] = params.workflowID; + } + if (params.projectID) { + data['project_id'] = params.projectID; + } + if (params.period) { + data['period'] = params.period; + } + + var erasURL = [config.erasHost, params.type].join('/'); + + return makeHTTPRequest('GET', erasURL, data).then(function (response) { + var results = JSON.parse(response.text); + return results; + }); + } +}; + +module.exports = erasClient;