Merge pull request #1 from mattbanister/master · diffbot/diffbot-python@b812fde · GitHub
Skip to content

Commit b812fde

Browse files
committed
Merge pull request #1 from mattbanister/master
Updates to README, fixes to filtering, optional arguments and expanded examples
2 parents aa51c30 + 7567ba4 commit b812fde

3 files changed

Lines changed: 130 additions & 27 deletions

File tree

README.md

Lines changed: 63 additions & 13 deletions

client.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,17 @@ class DiffbotClient(object):
55
def __init__(self):
66
self.base_url = "http://api.diffbot.com/"
77

8-
def request(self, url, token, api, fields=[], version=2):
8+
def request(self, url, token, api, fields=[], version=2, **kwargs):
99
"""
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
15+
if kwargs:
16+
params.update(kwargs)
1317
response = requests.get(self.compose_url(api, version), params=params)
1418
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)
2619
return obj
2720

2821
def compose_url(self, api, version_number):

example.py

Lines changed: 62 additions & 2 deletions

0 commit comments

Comments
 (0)