Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add eras-client for projects stats callouts #227

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;