From 67d5e2cc2e847596d859d198de441ed416668fae Mon Sep 17 00:00:00 2001 From: Paige Gulley Date: Thu, 31 Oct 2024 17:35:19 -0400 Subject: [PATCH 1/2] added source/collection retrieval methods --- mediacloud/api.py | 7 +++++++ mediacloud/test/api_directory_test.py | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/mediacloud/api.py b/mediacloud/api.py index 3613cd7..8487d85 100644 --- a/mediacloud/api.py +++ b/mediacloud/api.py @@ -63,6 +63,10 @@ class DirectoryApi(BaseApi): PLATFORM_TWITTER = "twitter" PLATFORM_REDDIT = "reddit" + def collection(self, id_: int): + + return self._query(f'sources/collections/{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) @@ -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, id_:int): + return self._query(f'sources/sources/{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: diff --git a/mediacloud/test/api_directory_test.py b/mediacloud/test/api_directory_test.py index 8ac8f2b..0c4333b 100644 --- a/mediacloud/test/api_directory_test.py +++ b/mediacloud/test/api_directory_test.py @@ -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" \ No newline at end of file From 50e297b625364bf4eea1bb33bac3575ed2d50fdd Mon Sep 17 00:00:00 2001 From: Paige Gulley Date: Fri, 1 Nov 2024 12:10:39 -0400 Subject: [PATCH 2/2] correct typing in tests, variable names --- mediacloud/api.py | 8 ++++---- mediacloud/test/api_directory_test.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mediacloud/api.py b/mediacloud/api.py index 8487d85..8928fd8 100644 --- a/mediacloud/api.py +++ b/mediacloud/api.py @@ -63,9 +63,9 @@ class DirectoryApi(BaseApi): PLATFORM_TWITTER = "twitter" PLATFORM_REDDIT = "reddit" - def collection(self, id_: int): + def collection(self, collection_id: int): - return self._query(f'sources/collections/{id_}/', None) + 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: @@ -76,8 +76,8 @@ def collection_list(self, platform: Optional[str] = None, name: Optional[str] = params['platform'] = platform return self._query('sources/collections/', params) - def source(self, id_:int): - return self._query(f'sources/sources/{id_}/', None) + 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, diff --git a/mediacloud/test/api_directory_test.py b/mediacloud/test/api_directory_test.py index 0c4333b..df88f1b 100644 --- a/mediacloud/test/api_directory_test.py +++ b/mediacloud/test/api_directory_test.py @@ -108,11 +108,11 @@ def test_feed_list_modified_before(self): assert len(feeds) > 0 def test_get_collection(self): - us_national_id = "34412234" + 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" + nyt_id = 1 response = self._directory.source(nyt_id) assert response["name"] == "nytimes.com" \ No newline at end of file