Skip to content

Commit 44f4cd4

Browse files
committed
Fixed problem with filtering fields after API call. Fields are now sent in query string
1 parent aa51c30 commit 44f4cd4

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

client.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,10 @@ def request(self, url, token, api, fields=[], version=2):
1010
Returns a python object containing the requested resource from the diffbot api
1111
"""
1212
params = {"url": url, "token": token}
13+
if fields:
14+
params['fields'] = fields
1315
response = requests.get(self.compose_url(api, version), params=params)
1416
obj = response.json()
15-
obj = self.select_fields_from_response(obj, fields)
16-
return obj
17-
18-
@staticmethod
19-
def select_fields_from_response(obj, fields):
20-
"""
21-
Returns the response object with the specified fields or all fields if
22-
the fields list is empty
23-
"""
24-
if fields:
25-
obj = dict((x, obj[x]) for x in fields)
2617
return obj
2718

2819
def compose_url(self, api, version_number):

example.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313
print "\nPrinting response:\n"
1414
pp = pprint.PrettyPrinter(indent=4)
1515
print pp.pprint(response)
16+
17+
print "Calling article API endpoint with fields specified on the url: http://shichuan.github.io/javascript-patterns/...\n"
18+
response = diffbot.request(url, token, api, fields=['title', 'type'], version=2)
19+
print "\nPrinting response:\n"
20+
pp = pprint.PrettyPrinter(indent=4)
21+
print pp.pprint(response)

0 commit comments

Comments
 (0)