Skip to content

Commit

Permalink
feat(utils): Upgrade to CourtListener v4 API
Browse files Browse the repository at this point in the history
Replaces API calls to CourtListener with the latest v4 version, ensuring compatibility with the newest features and improvements.
  • Loading branch information
ERosendo committed Sep 26, 2024
1 parent 686fb97 commit 9c3de6f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 62 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Features:
- None yet

Changes:
- None yet
- Upgrade to CourtListener v4 API([380](https://github.com/freelawproject/recap/issues/380))

Fixes:
- Corrected typo in build script, ensuring correct favicon path for Firefox releases([379](https://github.com/freelawproject/recap/issues/379), [397](https://github.com/freelawproject/recap-chrome/pull/397))
Expand Down
41 changes: 17 additions & 24 deletions src/appellate/appellate.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,13 @@ AppellateDelegate.prototype.handleAcmsDocket = async function () {
pacer_case_id: this.pacer_case_id,
},
});

if (docketData.count === 0) {
console.warn('RECAP: Zero results found for docket lookup.');
} else if (docketData.count > 1) {
console.error(
'RECAP: More than one result found for docket lookup. Found' +
`${result.count}`
);
} else {
let docketDataCount = docketData.results.length;
if (docketDataCount == 1){
addAlertButtonInRecapAction(this.court, this.pacer_case_id);
let cl_id = getClIdFromAbsoluteURL(docketData.results[0].absolute_url);
addSearchDocketInRecapAction(cl_id);
} else{
PACER.handleDocketAvailabilityMessages(docketDataCount);
}
};

Expand Down Expand Up @@ -654,7 +649,8 @@ AppellateDelegate.prototype.handleDocketReportFilter = async function () {
docket_number_core: docketNumberCore,
},
});
if (docketData.count === 1 && docketData.results) {
let docketDataCount = docketData.results.length;
if (docketDataCount === 1) {
let form = document.getElementsByTagName('form')[0];
let banner = recapBanner(docketData.results[0]);
form.after(banner);
Expand All @@ -667,7 +663,7 @@ AppellateDelegate.prototype.handleDocketReportFilter = async function () {
);
form.after(recapAlert);
} else {
PACER.handleDocketAvailabilityMessages(docketData);
PACER.handleDocketAvailabilityMessages(docketDataCount);
}
};

Expand Down Expand Up @@ -713,7 +709,8 @@ AppellateDelegate.prototype.handleCaseSelectionPage = async function () {
pacer_case_id: this.pacer_case_id,
},
});
if (appellateData.count === 1 && appellateData.results) {
let appellateDataCount = appellateData.results.length;
if (appellateDataCount == 1) {
PACER.removeBanners();

const footer = document.querySelector('div.noprint:last-of-type');
Expand All @@ -728,7 +725,7 @@ AppellateDelegate.prototype.handleCaseSelectionPage = async function () {
const appellateLink = anchors[0];
rIcon.insertAfter(appellateLink);
} else {
PACER.handleDocketAvailabilityMessages(appellateData);
PACER.handleDocketAvailabilityMessages(appellateDataCount);
}

if (anchors.length == 3) {
Expand All @@ -743,13 +740,14 @@ AppellateDelegate.prototype.handleCaseSelectionPage = async function () {
docket_number_core: districtLinkData.docket_number_core,
},
});
if (districtData.count === 1 && districtData.results) {
let districtDataCount = districtData.results.length;
if (districtDataCount == 1) {
const rIcon = APPELLATE.makeRButtonForCases(
districtData.results[0].absolute_url
);
rIcon.insertAfter(districtLink);
} else {
PACER.handleDocketAvailabilityMessages(districtData);
PACER.handleDocketAvailabilityMessages(districtDataCount);
}
}
} else {
Expand Down Expand Up @@ -947,18 +945,13 @@ AppellateDelegate.prototype.handleDocketDisplayPage = async function () {
pacer_case_id: this.pacer_case_id,
},
});

if (docketData.count === 0) {
console.warn('RECAP: Zero results found for docket lookup.');
} else if (docketData.count > 1) {
console.error(
'RECAP: More than one result found for docket lookup. ' +
`Found ${result.count}`
);
} else {
let docketDataCount = docketData.results.length;
if (docketDataCount === 1) {
addAlertButtonInRecapAction(this.court, this.pacer_case_id);
let cl_id = getClIdFromAbsoluteURL(docketData.results[0].absolute_url);
addSearchDocketInRecapAction(cl_id);
} else {
PACER.handleDocketAvailabilityMessages(docketDataCount);
}

// if you've already uploaded the page, return
Expand Down
52 changes: 20 additions & 32 deletions src/content_delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,28 +224,22 @@ ContentDelegate.prototype.handleDocketQueryUrl = async function () {
},
});

if (docketData.count === 0) {
console.warn('RECAP: Zero results found for docket lookup.');
} else if (docketData.count > 1) {
console.error(
'RECAP: More than one result found for docket lookup. Found ' +
`${result.count}`
);
let docketDataCount = docketData.results.length;
if (docketDataCount === 1) {
PACER.removeBanners();
const dateToInput = document.querySelector('input[name=date_to]');
const form = document.querySelector('form');
const div = document.createElement('div');

div.classList.add('recap-banner');
div.appendChild(recapAlertButton(this.court, this.pacer_case_id, true));
form.appendChild(recapBanner(docketData.results[0]));
form.appendChild(div);

if (docketData.results[0].date_last_filing)
dateToInput.after(recapAddLatestFilingButton(docketData.results[0]));
} else {
if (docketData.results) {
PACER.removeBanners();
const dateToInput = document.querySelector('input[name=date_to]');
const form = document.querySelector('form');
const div = document.createElement('div');

div.classList.add('recap-banner');
div.appendChild(recapAlertButton(this.court, this.pacer_case_id, true));
form.appendChild(recapBanner(docketData.results[0]));
form.appendChild(div);

if (docketData.results[0].date_last_filing)
dateToInput.after(recapAddLatestFilingButton(docketData.results[0]));
}
PACER.handleDocketAvailabilityMessages(docketDataCount);
};
};

Expand Down Expand Up @@ -297,19 +291,14 @@ ContentDelegate.prototype.handleDocketDisplayPage = async function () {
pacer_case_id: this.pacer_case_id,
},
});
if (docketData.count === 0) {
console.warn('RECAP: Zero results found for docket lookup.');
} else if (docketData.count > 1) {
console.error(
'RECAP: More than one result found for docket lookup. Found ' +
`${result.count}`
);
} else {
let docketDataCount = docketData.results.length;
if (docketDataCount === 1) {
addAlertButtonInRecapAction(this.court, this.pacer_case_id);
let cl_id = getClIdFromAbsoluteURL(docketData.results[0].absolute_url);
addSearchDocketInRecapAction(cl_id);
} else {
PACER.handleDocketAvailabilityMessages(docketDataCount);
}

// if you've already uploaded the page, return
if (history.state && history.state.uploaded) return;

Expand Down Expand Up @@ -455,8 +444,7 @@ ContentDelegate.prototype.handleSingleDocumentPageCheck = async function () {
pacer_doc_id__in: this.pacer_doc_id,
},
});

if (!recapLinks.count) return;
if (!recapLinks.results.length) return;
console.info(
'RECAP: Got results from API. Processing results to insert link'
);
Expand Down
8 changes: 4 additions & 4 deletions src/pacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,11 @@ let PACER = {
return cleanNumber ? cleanNumber : 0;
},

handleDocketAvailabilityMessages: (result) =>{
if (result.count === 0) {
handleDocketAvailabilityMessages: (resultCount) =>{
if (resultCount === 0) {
console.warn('RECAP: Zero results found for docket lookup.');
} else if (result.count > 1) {
console.error(`RECAP: More than one result found for docket lookup. Found ${result.count}`);
} else if (resultCount > 1) {
console.error(`RECAP: More than one result found for docket lookup. Found ${resultCount}`);
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/utils/background_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { buildFormData, sources, authHeader, jsonHeader } from './recap.js';
// **Returns:**
// - A string representing the complete CourtListener API URL.
const courtListenerURL = (suffix) =>
'https://www.courtlistener.com/api/rest/v3/' + suffix + '/';
'https://www.courtlistener.com/api/rest/v4/' + suffix + '/';

// Encodes Search Parameters for GET Requests
//
Expand Down

0 comments on commit 9c3de6f

Please sign in to comment.