Skip to content

Commit a16d790

Browse files
author
Paul Tagliamonte
committed
Starting to build out the new API
1 parent a65e36c commit a16d790

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

examples/congress/ma_legs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
from sunlight import congress
5+
6+
7+
for leg in congress.legislators(party="D"):
8+
print(leg)

sunlight/services/congress.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
import json
1313

1414

15+
API_ROOT = "http://congress.api.sunlightfoundation.com"
16+
17+
1518
class Congress(sunlight.service.Service):
1619
"""
17-
Bindings into the `Sunlight Congress API
18-
<http://services.sunlightlabs.com/docs/Sunlight_Congress_API/>`_, an API
19-
primarily for details on current federal legislators.
2020
"""
2121

22+
def legislators(self, **kwargs):
23+
return self.get('legislators', **kwargs)
24+
2225
# implementation methods
23-
def _get_url(self, obj, apikey, **kwargs):
26+
def _get_url(self, endpoint, apikey, **kwargs):
2427
return "%s/%s?apikey=%s&%s" % (
25-
service_url,
26-
obj,
27-
apikey,
28+
API_ROOT, endpoint, apikey,
2829
sunlight.service.safe_encode(kwargs)
2930
)
31+
32+
def _decode_response(self, response):
33+
return json.loads(response)['results']

sunlight/services/congress_deprecated.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
.. module:: sunlight.services.congress
66
:synopsis: Sunlight Congress API Implementation
77
8-
Sunlight Congress API Implementation inside ``python-sunlight``.
8+
.. warning::
9+
Please avoid using this for new applications, this API has been
10+
phased out, and will be taken down at the end of the current
11+
congress.
12+
13+
Deprecated Sunlight Congress API Implementation inside ``python-sunlight``.
914
"""
1015

1116
import sunlight.service

0 commit comments

Comments
 (0)