Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

Commit

Permalink
Added data kwarg and few others to the search for #109
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Nov 22, 2015
1 parent 738a6ad commit 8cb0c50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions documentcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,25 @@ def is_url(self, string):
except:
return False

def _get_search_page(self, query, page, per_page):
def _get_search_page(
self,
query,
page,
per_page=1000,
mentions=3,
data=False,
):
"""
Retrieve one page of search results from the DocumentCloud API.
"""
if mentions > 10:
raise ValueError("You cannot search for more than 10 mentions")
params = {
'q': query,
'page': page,
'per_page': per_page,
'mentions': 3,
'mentions': mentions,
'data': data,
}
data = self.fetch('search.json', params)
return data.get("documents")
Expand Down
16 changes: 16 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ def test_search(self):
)
self.assertEqual(len(one_page), 1)

data = one_page = self.public_client.documents.search(
self.test_search,
page=1,
per_page=1,
data=True,
)
data[0].data

with self.assertRaises(ValueError):
self.public_client.documents.search(
self.test_search,
page=1,
per_page=1,
mentions=11,
)


class DocumentTest(BaseTest):
"""
Expand Down

0 comments on commit 8cb0c50

Please sign in to comment.