Skip to content

Commit 326dd2d

Browse files
author
Paul Tagliamonte
committed
Adding in kwargs for future-proofing
1 parent da0c2fe commit 326dd2d

File tree

1 file changed

+54
-27
lines changed

1 file changed

+54
-27
lines changed

sunlight/services/congress.py

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,24 @@ def legislators(self, **kwargs):
3434
'legislator')
3535

3636

37-
def legislator_search(self, name, threshold=0.9, all_legislators=False):
37+
def legislator_search(self, name, threshold=0.9, all_legislators=False,
38+
**kwargs):
3839
"""
3940
Fuzzy-matching name search against federal legislators.
4041
4142
See documentation at `legislators.search
4243
<http://services.sunlightlabs.com/docs/congressapi/legislators.search/>`_
4344
"""
44-
params = {'name': name, 'threshold': threshold}
45+
params = kwargs.copy()
46+
params.update({'name': name, 'threshold': threshold})
47+
4548
if all_legislators:
4649
params['all_legislators'] = 1
47-
return _unpack(self.get('legislators.search', **params),
48-
'result')
50+
51+
return _unpack(self.get('legislators.search', **params), 'result')
4952

5053

51-
def legislators_for_zip(self, zipcode):
54+
def legislators_for_zip(self, zipcode, **kwargs):
5255
"""
5356
Query for all legislators representing a given ZIP code.
5457
@@ -59,71 +62,95 @@ def legislators_for_zip(self, zipcode):
5962
See documentation at `legislators.allForZip
6063
<http://services.sunlightlabs.com/docs/congressapi/legislators.allForZip/>`_
6164
"""
62-
return _unpack(self.get('legislators.allForZip', zip=zipcode),
63-
'legislator'
64-
)
65+
params = kwargs.copy()
66+
params.update({
67+
"zip": zipcode
68+
})
69+
return _unpack(self.get('legislators.allForZip', **params),
70+
'legislator')
6571

66-
def legislators_for_lat_lon(self, latitude, longitude):
72+
def legislators_for_lat_lon(self, latitude, longitude, **kwargs):
6773
"""
6874
Query for all legislators representing an given location.
6975
7076
See documentation at `legislators.allForLatLong
7177
<http://services.sunlightlabs.com/docs/congressapi/legislators.allForLatLong/>`_
7278
"""
73-
return _unpack(self.get('legislators.allForLatLong', latitude=latitude,
74-
longitude=longitude), 'legislator')
79+
params = kwargs.copy()
80+
params.update({
81+
"latitude": latitude,
82+
"longitude": longitude
83+
})
84+
return _unpack(self.get('legislators.allForLatLong', **params),
85+
'legislator')
7586

76-
def districts_for_zip(self, zipcode):
87+
def districts_for_zip(self, zipcode, **kwargs):
7788
"""
7889
Query for all congressional districts overlapping a zip code.
7990
8091
See documentation at `districts.getDistrictFromLatLong
8192
<http://services.sunlightlabs.com/docs/congressapi/districts.getDistrictFromLatLong/>`_
8293
"""
83-
return _unpack(self.get('districts.getDistrictsFromZip', zip=zipcode),
84-
'district'
85-
)
94+
params = kwargs.copy()
95+
params.update({
96+
"zip": zipcode
97+
})
98+
return _unpack(self.get('districts.getDistrictsFromZip', **params),
99+
'district')
86100

87-
def districts_for_lat_lon(self, latitude, longitude):
101+
def districts_for_lat_lon(self, latitude, longitude, **kwargs):
88102
"""
89103
Query for all congressional districts containing a given location.
90104
91105
See documentation at `districts.getDistrictFromLatLong
92106
<http://services.sunlightlabs.com/docs/congressapi/districts.getDistrictFromLatLong/>`_
93107
"""
94-
return _unpack(self.get('districts.getDistrictFromLatLong',
95-
latitude=latitude, longitude=longitude),
96-
'district'
97-
)
108+
params = kwargs.copy()
109+
params.update({
110+
"latitude": latitude,
111+
"longitude": longitude
112+
})
113+
return _unpack(self.get('districts.getDistrictFromLatLong', **params),
114+
'district')
115+
98116

99-
def committees(self, chamber):
117+
def committees(self, chamber, **kwargs):
100118
"""
101119
Query for all committees for a chamber. (House|Senate|Joint)
102120
103121
See documentation at `committees.getList
104122
<http://services.sunlightlabs.com/docs/congressapi/committees.getList/>`_
105123
"""
106-
return _unpack(self.get('committees.getList', chamber=chamber),
124+
params = kwargs.copy()
125+
params.update({"chamber": chamber})
126+
return _unpack(self.get('committees.getList', **params),
107127
'committee')
108128

109-
def committee_detail(self, id):
129+
def committee_detail(self, committee_id, **kwargs):
110130
"""
111131
Query for all details for a committee, including members.
112132
113133
See documentation at `committees.get
114134
<http://services.sunlightlabs.com/docs/congressapi/committees.get/>`_
115135
"""
116-
return self.get('committees.get', id=id)['committee']
136+
params = kwargs.copy()
137+
params.update({"id": committee_id})
138+
# We can't use _unpack since top level is `committee' not committees
139+
return self.get('committees.get', **params)['committee']
117140

118-
def committees_for_legislator(self, bioguide_id):
141+
def committees_for_legislator(self, bioguide_id, **kwargs):
119142
"""
120143
Query for all details for all of a legislator's committee assignments.
121144
122145
See documentation at `committees.allForLegislator
123146
<http://services.sunlightlabs.com/docs/congressapi/committees.allForLegislator/>`_
124147
"""
125-
return _unpack(self.get('committees.allForLegislator',
126-
bioguide_id=bioguide_id), 'committee')
148+
params = kwargs.copy()
149+
params.update({
150+
"bioguide_id": bioguide_id
151+
})
152+
return _unpack(self.get('committees.allForLegislator', **params),
153+
'committee')
127154

128155
# implementation methods
129156
def _get_url(self, obj, apikey, **kwargs):

0 commit comments

Comments
 (0)