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

Bill number -> bill id #31

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion src/commands/bill/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const database = require('../../database');
const legiscan = require('../../services/legiscan');

exports.handle = async function(args, message, client) {
const billId = args[0];
const billId = args.join(' ');

if (billId) {
const bill = await legiscan.getBill(billId);
Expand Down
31 changes: 27 additions & 4 deletions src/services/legiscan.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ const endpoint = 'https://api.legiscan.com';
const sortBills = bills => bills.sort((a, b) => b.history[0].timestamp - a.history[0].timestamp);

exports.getBill = async function(id) {
// A bill number was passed in instead of an id
if (id.includes(' ')) {
const result = await axios.get(endpoint, {
params: {
key: credentials.key,
op: 'search',
query: id.split(' ')[1],
state: parser.state(id.split(' ')[0]),
year: 1
}
});

const response = result.data;

if (result.status === 'OK') {
console.log(response);
} else {
logger.error('API error:');
logger.error(response.searchresult);
return null;
}
}

const result = await axios.get(endpoint, {
params: {
key: credentials.key,
Expand All @@ -34,11 +57,11 @@ exports.getBill = async function(id) {
})
};
return returnBill;
} else {
logger.error('API error:');
logger.error(response);
return null;
}

logger.error('API error:');
logger.error(response);
return null;
};

exports.search = async function(state, query) {
Expand Down