Skip to content

Commit

Permalink
add eras-client for projects stats callouts (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuenmichelle1 authored Nov 29, 2023
1 parent 10e0ccf commit 0758126
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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+)/);
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions lib/eras-client.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0758126

Please sign in to comment.