Repository navigation
Expand file tree
/
Copy pathcongressAPI.js
More file actions
48 lines (38 loc) · 1.59 KB
/
Copy pathcongressAPI.js
File metadata and controls
48 lines (38 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import fetch from "node-fetch"
import { readFileSync } from "fs"
const config = JSON.parse(readFileSync("./config.json"))
const apiKey = config.apiKey
const baseUrl = "https://api.propublica.org/congress/v1"
const getStateSenators = state => {
return fetch(`${baseUrl}/members/senate/${state}/current.json`, {headers:{"X-API-Key":apiKey}})
.then(res => res.json())
}
const getStateReps = state => {
return fetch(`${baseUrl}/members/house/${state}/current.json`, {headers:{"X-API-Key":apiKey}})
.then(res => res.json())
}
const getCongressMember = id => {
return fetch(`${baseUrl}/members/${id}.json`, {headers:{"X-API-Key":apiKey}})
.then(res => res.json())
}
const getCongressMembers = chamber => {
return fetch(`${baseUrl}/116/${chamber}/members.json`, {headers:{"X-API-Key":apiKey}})
.then(res => res.json())
}
const getLatestMembers = () => {
return fetch(`${baseUrl}/members/new.json`, {headers:{"X-API-Key":apiKey}})
.then(res => res.json())
}
const getLatestBills = () => {
return fetch(`${baseUrl}/116/both/bills/introduced.json`, {headers:{"X-API-Key":apiKey}})
.then(res => res.json())
}
const getAllMembers = chamber => {
return fetch(`${baseUrl}/116/${chamber}/members.json`, {headers:{"X-API-Key":apiKey}})
.then(res => res.json())
}
const getBill = (id) => {
return fetch(`${baseUrl}/116/bills/${id}.json`, {headers:{"X-API-Key":apiKey}})
.then(res => res.json())
}
export default { getStateSenators, getStateReps, getCongressMember, getCongressMembers, getLatestMembers, getLatestBills, getAllMembers, getBill }