Skip to content

Commit

Permalink
Merge pull request #95 from pgulley/id_queries
Browse files Browse the repository at this point in the history
added source/collection retrieval methods
  • Loading branch information
pgulley authored Nov 1, 2024
2 parents e5234bf + 50e297b commit 1b95ff3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mediacloud/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class DirectoryApi(BaseApi):
PLATFORM_TWITTER = "twitter"
PLATFORM_REDDIT = "reddit"

def collection(self, collection_id: int):

return self._query(f'sources/collections/{collection_id}/', None)

def collection_list(self, platform: Optional[str] = None, name: Optional[str] = None,
limit: Optional[int] = 0, offset: Optional[int] = 0) -> Dict:
params: Dict[Any, Any] = dict(limit=limit, offset=offset)
Expand All @@ -72,6 +76,9 @@ def collection_list(self, platform: Optional[str] = None, name: Optional[str] =
params['platform'] = platform
return self._query('sources/collections/', params)

def source(self, source_id:int):
return self._query(f'sources/sources/{source_id}/', None)

def source_list(self, platform: Optional[str] = None, name: Optional[str] = None,
collection_id: Optional[int] = None,
limit: Optional[int] = 0, offset: Optional[int] = 0) -> Dict:
Expand Down
10 changes: 10 additions & 0 deletions mediacloud/test/api_directory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,13 @@ def test_feed_list_modified_before(self):
break
offset += limit
assert len(feeds) > 0

def test_get_collection(self):
us_national_id = 34412234
response = self._directory.collection(us_national_id)
assert response["name"] == "United States - National"

def test_get_source(self):
nyt_id = 1
response = self._directory.source(nyt_id)
assert response["name"] == "nytimes.com"

0 comments on commit 1b95ff3

Please sign in to comment.