@4lch4/lib-congress
Version:
A library for interacting with the api.congress.gov API.
421 lines (396 loc) • 15.1 kB
text/typescript
//#region Imports
import {
AmendmentActions,
AmendmentType,
BillActions,
BillType,
Chambers,
CommitteeActions,
CommitteeReportType,
CommunicationType,
IAmendment,
IAmendmentPathParameters,
IAmendmentsQueryParameters,
IAmendmentsResponse,
IAppConfig,
IBaseOptions,
IBaseQueryParameters,
IBaseResponseData,
IBill,
IBillsPathParameters,
IBillsQueryParameters,
IBillsResponse,
ICommittee,
ICommitteePathParameters,
ICommitteeReport,
ICommitteeReportPathParameters,
ICommitteeReportQueryParameters,
ICommitteeReportResponse,
ICommitteeResponse,
ICongress,
ICongressionalRecord,
ICongressionalRecordDigest,
ICongressionalRecordIssue,
ICongressionalRecordLinks,
ICongressionalRecordPDF,
ICongressionalRecordQueryParameters,
ICongressionalRecordResponse,
ICongressPathParameters,
ICongressResponse,
ICongressSession,
IHouseCommunication,
IHouseCommunicationPathParameters,
IHouseCommunicationResponse,
IHouseCommunicationType,
ILatestAction,
IMember,
IMemberDepiction,
IMemberPathParameters,
IMemberResponse,
IMemberServed,
IMemberServedTimespan,
INomination,
INominationPathParameters,
INominationResponse,
INominationType,
IPagination,
IRequestConfig,
IResponse,
IResponseRequest,
ISubCommittee,
ISummariesPathParameters,
ISummariesQueryParameters,
ISummariesResponse,
ISummary,
ITreaty,
ITreatyParts,
ITreatyPathParameters,
ITreatyResponse,
MemberActions,
NominationActions,
ResponseFormat,
SortType,
TreatyActions
} from './interfaces/index.js'
import { BaseRoute } from './lib/index.js'
//#endregion Imports
//#region Exports
export * as Enum from './interfaces/enums/index.js'
export * as Interfaces from './interfaces/index.js'
export * as Lib from './lib/index.js'
export {
AmendmentActions,
BillActions,
IAppConfig,
IPagination,
SortType,
IRequestConfig,
IResponseRequest,
IBaseResponseData,
MemberActions,
CommitteeActions,
IAmendment,
IAmendmentPathParameters,
IBaseOptions,
IBaseQueryParameters,
IBill,
IBillsPathParameters,
ICommittee,
ICommitteeReport,
ICongressSession,
IHouseCommunication,
IHouseCommunicationType,
ILatestAction,
IMember,
IMemberDepiction,
IMemberServed,
IMemberServedTimespan,
INomination,
INominationType,
ISubCommittee,
ICommitteeReportQueryParameters,
ICommitteeReportPathParameters,
IAmendmentsQueryParameters,
ITreaty,
ITreatyParts,
IBillsQueryParameters,
ICommitteePathParameters,
ICongress,
ICongressPathParameters,
IMemberPathParameters,
IResponse,
ISummariesPathParameters,
ISummariesQueryParameters,
ISummary,
AmendmentType,
BillType,
Chambers,
CommitteeReportType,
CommunicationType,
ITreatyPathParameters,
INominationPathParameters,
IHouseCommunicationPathParameters,
ICongressionalRecordQueryParameters,
ICongressionalRecord,
ICongressionalRecordDigest,
ICongressionalRecordIssue,
ICongressionalRecordLinks,
ICongressionalRecordPDF,
NominationActions,
TreatyActions,
ResponseFormat
}
//#endregion Exports
export class CongressAPI extends BaseRoute {
/**
* Determines which `/amendments` endpoint to send the request to based on the
* provided `opts` object, crafts the necessary request options, and sends the
* request to the API. The response is returned via Promise and the structure
* of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
* @param action An optional parameter that determines which alternate endpoint to pull data from.
*
* @returns Amendment data based on the provided parameters.
*/
public async getAmendments(
opts?: IBaseOptions<IAmendmentPathParameters, IBaseQueryParameters>,
action?: AmendmentActions
): Promise<IResponse<IAmendmentsResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/amendment`.
const endpoint = this.getRequestEndpoint('/amendment', [
opts?.pathParams?.congress,
opts?.pathParams?.amendmentType,
opts?.pathParams?.amendmentNumber,
action
])
return this.sendRequest<IAmendmentsResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which endpoint to send the request to based on the provided
* `opts` object, crafts the necessary request options, and sends the request
* to the API. The response is returned via Promise and the structure of the
* response is determined by the `responseFormat` and `trimmedResponses`
* properties of the application config.
*
* @param opts The options for the request.
* @param action An optional parameter that determines which alternate endpoint to pull data from.
*
* @returns Bill data based on the provided parameters.
*/
public async getBills(
opts?: IBaseOptions<IBillsPathParameters, IBillsQueryParameters>,
action?: BillActions
): Promise<IResponse<IBillsResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/bill`.
const endpoint = this.getRequestEndpoint('/bill', [
opts?.pathParams?.congress,
opts?.pathParams?.billType,
opts?.pathParams?.billNumber,
action
])
return this.sendRequest<IBillsResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/summaries` endpoint to send the request to based on the
* provided `opts` object, crafts the necessary request options, and sends the
* request to the API. The response is returned via Promise and the structure
* of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
*
* @returns Summary data based on the provided parameters.
*/
public async getSummaries(
opts?: IBaseOptions<ISummariesPathParameters, ISummariesQueryParameters>
): Promise<IResponse<ISummariesResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/summaries`.
const endpoint = this.getRequestEndpoint('/summaries', [
opts?.pathParams?.congress,
opts?.pathParams?.billType
])
return this.sendRequest<ISummariesResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/congress` endpoint to send the request to based on the
* provided `opts` object, crafts the necessary request options, and sends the
* request to the API. The response is returned via Promise and the structure
* of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
*
* @returns Congress data based on the provided parameters.
*/
public async getCongress(
opts?: IBaseOptions<ICongressPathParameters, IBaseQueryParameters>
): Promise<IResponse<ICongressResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/congress`.
const endpoint = this.getRequestEndpoint('/congress', [opts?.pathParams?.congress])
return this.sendRequest<ICongressResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/members` endpoint to send the request to based on the
* provided `opts` object, crafts the necessary request options, and sends the
* request to the API. The response is returned via Promise and the structure
* of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
*
* @returns Member data based on the provided parameters.
*/
public async getMembers(
opts?: IBaseOptions<IMemberPathParameters, IBaseQueryParameters>,
action?: MemberActions
): Promise<IResponse<IMemberResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/member`.
const endpoint = this.getRequestEndpoint('/member', [opts?.pathParams?.bioguideId, action])
return this.sendRequest<IMemberResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/committee` endpoint to send the request to based on the
* provided `opts` object, crafts the necessary request options, and sends the
* request to the API. The response is returned via Promise and the structure
* of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
*
* @returns Committee data based on the provided parameters.
*/
public async getCommittees(
opts?: IBaseOptions<ICommitteePathParameters, IBaseQueryParameters>,
action?: CommitteeActions
): Promise<IResponse<ICommitteeResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/member`.
const endpoint = this.getRequestEndpoint('/committee', [
opts?.pathParams?.chamber,
opts?.pathParams?.congress,
opts?.pathParams?.committeeCode,
action
])
return this.sendRequest<ICommitteeResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/committeeReport` endpoint to send the request to based on the
* provided `opts` object, crafts the necessary request options, and sends the
* request to the API. The response is returned via Promise and the structure
* of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
*
* @returns Committee Report data based on the provided parameters.
*/
public async getCommitteeReports(
opts?: IBaseOptions<ICommitteeReportPathParameters, ICommitteeReportQueryParameters>
): Promise<IResponse<ICommitteeReportResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/member`.
const endpoint = this.getRequestEndpoint('/committeeReport', [
opts?.pathParams?.congress,
opts?.pathParams?.reportType,
opts?.pathParams?.reportNumber
])
return this.sendRequest<ICommitteeReportResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/congressional-record` endpoint to send the request to
* based on the provided `opts` object, crafts the necessary request options,
* and sends the request to the API. The response is returned via Promise and
* the structure of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
*
* @returns Congressional Record data based on the provided parameters.
*/
public async getCongressionalRecord(
opts?: IBaseOptions<undefined, ICongressionalRecordQueryParameters>
): Promise<IResponse<ICongressionalRecordResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/member`.
const endpoint = this.getRequestEndpoint('/congressional-record')
return this.sendRequest<ICongressionalRecordResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/house-communication` endpoint to send the request to
* based on the provided `opts` object, crafts the necessary request options,
* and sends the request to the API. The response is returned via Promise and
* the structure of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
*
* @returns House Communications data based on the provided parameters.
*/
public async getHouseCommunications(
opts?: IBaseOptions<IHouseCommunicationPathParameters, IBaseQueryParameters>
): Promise<IResponse<IHouseCommunicationResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/member`.
const endpoint = this.getRequestEndpoint('/house-communication', [
opts?.pathParams?.congress,
opts?.pathParams?.communicationType,
opts?.pathParams?.communicationNumber
])
return this.sendRequest<IHouseCommunicationResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/nomination` endpoint to send the request to based on the
* provided `opts` object, crafts the necessary request options, and sends the
* request to the API. The response is returned via Promise and the structure
* of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
* @returns Nomination data based on the provided parameters.
*/
public async getNominations(
opts?: IBaseOptions<INominationPathParameters, IBaseQueryParameters>,
action?: NominationActions
): Promise<IResponse<INominationResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/member`.
const endpoint = this.getRequestEndpoint('/nomination', [
opts?.pathParams?.congress,
opts?.pathParams?.nominationNumber,
opts?.pathParams?.ordinal,
action
])
return this.sendRequest<INominationResponse>('GET', endpoint, opts?.queryParams)
}
/**
* Determines which `/treaty` endpoint to send the request to based on the
* provided `opts` object, crafts the necessary request options, and sends the
* request to the API. The response is returned via Promise and the structure
* of the response is determined by the `responseFormat` and
* `trimmedResponses` properties of the application config.
*
* @param opts The options for the request.
* @returns Treaty data based on the provided parameters.
*/
public async getTreaties(
opts?: IBaseOptions<ITreatyPathParameters, IBaseQueryParameters>,
action?: TreatyActions
): Promise<IResponse<ITreatyResponse>> {
// Build the endpoint to send the request by providing the various options.
// If all the values are undefined, then the endpoint will be `/member`.
const endpoint = this.getRequestEndpoint('/treaty', [
opts?.pathParams?.congress,
opts?.pathParams?.treatyNumber,
opts?.pathParams?.treatySuffix,
action
])
return this.sendRequest<ITreatyResponse>('GET', endpoint, opts?.queryParams)
}
}