Skip to content

Commit cf17554

Browse files
committed
Update capitolwords endpoint with version number; Fix _get_url to conform to new Service.get requirements. See also #13.
1 parent b827546 commit cf17554

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

sunlight/services/capitolwords.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sunlight.service
88
import json
99

10-
service_url = "http://capitolwords.org/api"
10+
service_url = "http://capitolwords.org/api/1"
1111

1212

1313
class CapitolWords(sunlight.service.Service):
@@ -35,7 +35,7 @@ def dates(self, phrase, **kwargs):
3535
endpoint <http://capitolwords.org/api/#dates.json>`_.
3636
"""
3737
kwargs['phrase'] = phrase
38-
return self.get("dates", **kwargs)
38+
return self.get(["dates"], **kwargs)
3939

4040
def phrases(self, entity_type, entity_value, **kwargs):
4141
"""
@@ -49,7 +49,7 @@ def phrases(self, entity_type, entity_value, **kwargs):
4949
kwargs['entity_type'] = entity_type
5050
kwargs['entity_value'] = entity_value
5151

52-
return self.get("phrases", **kwargs)
52+
return self.get(["phrases"], **kwargs)
5353

5454
def phrases_by_entity(self, entity_type, **kwargs):
5555
"""
@@ -60,8 +60,7 @@ def phrases_by_entity(self, entity_type, **kwargs):
6060
For a list of arguments see `Capitol Words' phrases/entity.json
6161
endpoint <http://capitolwords.org/api/#phrases/entity.json>`_.
6262
"""
63-
lss = "%s/%s" % ("phrases", entity_type)
64-
return self.get(lss, **kwargs)
63+
return self.get(["phrases", entity_type], **kwargs)
6564

6665
def text(self, phrase=None, title=None, **kwargs):
6766
"""
@@ -88,14 +87,17 @@ def text(self, phrase=None, title=None, **kwargs):
8887
if title:
8988
kwargs['title'] = title
9089

91-
return self.get("text", **kwargs)
90+
return self.get(["text"], **kwargs)
9291

9392
# API impl methods below
9493

95-
def _get_url(self, obj, apikey, **kwargs):
94+
def _get_url(self, pathparts, apikey, **kwargs):
95+
# join pieces by slashes and add a trailing slash
96+
endpoint_path = "/".join(pathparts)
97+
9698
ret = "%s/%s.json?apikey=%s&%s" % (
9799
service_url,
98-
obj,
100+
endpoint_path,
99101
apikey,
100102
sunlight.service.safe_encode(kwargs)
101103
)

0 commit comments

Comments
 (0)