Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { URLSearchParams } from 'url';
import defineAction from '../../../../helpers/define-action.js';

export default defineAction({
name: 'Agricultural Economic Data',
key: 'agricultural-economic-data',
description: '',
arguments: [
{
label: 'Category',
key: 'category',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listCategories',
},
],
},
},
{
label: 'Year',
key: 'year',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listYears',
},
],
},
},
{
label: 'State',
key: 'state',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listStates',
},
],
},
},
{
label: 'Report',
key: 'report',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listReports',
},
],
},
},
],

async run($) {
const searchParams = new URLSearchParams($.step.parameters);
const response = await $.http.get(`/surveydata?${searchParams.toString()}`);
$.setActionItem({ raw: response.data });
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import agriculturalEconomicData from './agricultural-economic-data/index.js';

export default [agriculturalEconomicData];
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions packages/backend/src/apps/usda-economic-research/auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';

export default {
fields: [
{
key: 'screenName',
label: 'Screen Name',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'Screen name of your connection to be used on Automatisch UI.',
clickToCopy: false,
},
{
key: 'apiKey',
label: 'API Key',
type: 'string',
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'API key of your account.',
clickToCopy: false,
},
],

verifyCredentials,
isStillVerified,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import verifyCredentials from './verify-credentials.js';

const isStillVerified = async ($) => {
await verifyCredentials($);
return true;
};

export default isStillVerified;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const verifyCredentials = async ($) => {
await $.http.get('/state');

await $.auth.set({
screenName: $.auth.data.screenName,
apiKey: $.auth.data.apiKey,
});
};

export default verifyCredentials;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const addAuthHeader = ($, requestConfig) => {
if ($.auth.data?.apiKey) {
requestConfig.params = {
...requestConfig.params,
api_key: $.auth.data.apiKey,
};
}

return requestConfig;
};

export default addAuthHeader;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import listCategories from './list-categories/index.js';
import listYears from './list-years/index.js';
import listStates from './list-states/index.js';
import listReports from './list-reports/index.js';

export default [listCategories, listYears, listStates, listReports];
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
name: 'List Categories',
key: 'listCategories',

async run($) {
const categories = {
data: [],
};
const { data } = await $.http.get('/category');
if (data) {
for (const category of data.data) {
categories.data.push({
value: category.header,
name: category.header,
});
}
}
return categories;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
name: 'List reports',
key: 'listReports',

async run($) {
const reports = {
data: [],
};
const { data } = await $.http.get('/report');
if (data) {
for (const report of data.data) {
reports.data.push({
value: report.header,
name: report.header,
});
}
}
return reports;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
name: 'List States',
key: 'listStates',

async run($) {
const states = {
data: [],
};
const { data } = await $.http.get('/state');
if (data) {
for (const state of data.data) {
states.data.push({
value: state.code,
name: state.name,
});
}
}
return states;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
name: 'List years',
key: 'listYears',

async run($) {
const years = {
data: [],
};
const { data } = await $.http.get('/year');
if (data) {
for (const year of data.data) {
years.data.push({
value: year.toString(),
name: year.toString(),
});
}
}
return years;
},
};
20 changes: 20 additions & 0 deletions packages/backend/src/apps/usda-economic-research/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';
import actions from './actions/index.js';
import dynamicData from './dynamic-data/index.js';

export default defineApp({
name: 'USDA Economic Research',
key: 'usda-economic-research',
iconUrl: '{BASE_URL}/apps/usda-economic-research/assets/favicon.svg',
authDocUrl: '',
supportsConnections: true,
baseUrl: 'https://api.ers.usda.gov/data/arms',
apiBaseUrl: 'https://api.ers.usda.gov/data/arms',
primaryColor: '#6f42c1',
beforeRequest: [addAuthHeader],
auth,
actions,
dynamicData,
});