Skip to content

Commit 202ed5f

Browse files
authored
Feature/full api stubs (#6)
* add boilerplate for all APIs, cleanup package layout * remove config.API_KEY ref
1 parent e4cd76c commit 202ed5f

File tree

8 files changed

+154
-75
lines changed

8 files changed

+154
-75
lines changed

src/fredapi/api/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22
"""
33
Fred API core.
44
"""
5-
from .category import FredAPICategory
6-
from .release import FredAPIRelease
5+
from .categories import FredAPICategories
6+
from .exceptions import BaseFredAPIError, FredAPIRequestError
7+
from .releases import FredAPIReleases
78
from .series import FredAPISeries
8-
from .fred_py_api import FredAPI
9+
from .sources import FredAPISources
10+
from .tags import FredAPITags
11+
12+
13+
class FredAPI(FredAPISeries, FredAPIReleases, FredAPICategories, FredAPISources, FredAPITags):
14+
"""
15+
Fred API.
16+
https://fred.stlouisfed.org/docs/api/fred/
17+
"""
18+
19+
pass

src/fredapi/api/categories.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Fred API for Categories Namespace.
4+
"""
5+
from .fred_client import FredClient
6+
7+
8+
class FredAPICategories(FredClient):
9+
"""
10+
Fred API Categories Namespace.
11+
12+
Endpoints:
13+
fred/category - Get a category.
14+
fred/category/children - Get the child categories for a specified parent category.
15+
fred/category/related - Get the related categories for a category.
16+
fred/category/series - Get the series in a category.
17+
fred/category/tags - Get the tags for a category.
18+
fred/category/related_tags - Get the related tags for a category.
19+
"""
20+
21+
def get_category(self, category_id: int = None, **kwargs) -> dict:
22+
"""Get category by ID."""
23+
return self._get(f"category", {
24+
"category_id": category_id,
25+
**kwargs,
26+
})
27+
28+
def get_category_series(self, category_id: int = None, **kwargs) -> dict:
29+
"""Get category series by ID."""
30+
return self._get(f"category/series", {
31+
"category_id": category_id,
32+
**kwargs,
33+
})
34+
35+
def get_category_children(self, category_id: int = None, **kwargs) -> dict:
36+
"""Get category children by ID."""
37+
return self._get(f"category/children", {
38+
"category_id": category_id,
39+
**kwargs,
40+
})
41+
42+
def get_category_related(self, category_id: int = None, **kwargs) -> dict:
43+
"""Get category related by ID."""
44+
return self._get(f"category/related", {
45+
"category_id": category_id,
46+
**kwargs,
47+
})
48+
49+
def get_category_tags(self, category_id: int = None, **kwargs) -> dict:
50+
"""Get category tags by ID."""
51+
raise NotImplementedError("get_category_tags endpoint is not yet implemented.")
52+
53+
def get_category_related_tags(self, category_id: int = None, **kwargs) -> dict:
54+
"""Get category related tags by ID."""
55+
raise NotImplementedError("get_category_related_tags endpoint is not yet implemented.")

src/fredapi/api/category.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/fredapi/api/fred_py_api.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/fredapi/api/release.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/fredapi/api/releases.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Fred API for Releases Namespace.
4+
"""
5+
from .fred_client import FredClient
6+
7+
8+
class FredAPIReleases(FredClient):
9+
"""
10+
Fred API Releases Namespace.
11+
12+
Endpoints:
13+
fred/releases - Get all releases of economic data.
14+
fred/releases/dates - Get release dates for all releases of economic data.
15+
fred/release - Get a release of economic data.
16+
fred/release/dates - Get release dates for a release of economic data.
17+
fred/release/series - Get the series on a release of economic data.
18+
fred/release/sources - Get the sources for a release of economic data.
19+
fred/release/tags - Get the tags for a release.
20+
fred/release/related_tags - Get the related tags for a release.
21+
fred/release/tables - Get the release tables for a given release.
22+
"""
23+
24+
def get_releases(self, **kwargs) -> dict:
25+
"""Get releases."""
26+
return self._get(f"releases", {
27+
**kwargs,
28+
})
29+
30+
def get_releases_dates(self, **kwargs) -> dict:
31+
"""Get releases dates."""
32+
return self._get(f"releases/dates", {
33+
**kwargs,
34+
})
35+
36+
def get_release(self, release_id: int = None, **kwargs) -> dict:
37+
"""Get release by ID."""
38+
return self._get(f"release", {
39+
"release_id": release_id,
40+
**kwargs,
41+
})
42+
43+
def get_release_dates(self, release_id: int = None, **kwargs) -> dict:
44+
"""Get release dates by ID."""
45+
return self._get(f"release/dates", {
46+
"release_id": release_id,
47+
**kwargs,
48+
})
49+
50+
def get_release_series(self, release_id: int = None, **kwargs) -> dict:
51+
"""Get release series by ID."""
52+
return self._get(f"release/series", {
53+
"release_id": release_id,
54+
**kwargs,
55+
})
56+
57+
def get_release_sources(self, release_id: int = None, **kwargs) -> dict:
58+
"""Get release sources by ID."""
59+
return self._get(f"release/sources", {
60+
"release_id": release_id,
61+
**kwargs,
62+
})
63+
64+
def get_release_tags(self, release_id: int = None, **kwargs) -> dict:
65+
"""Get release tags by ID."""
66+
raise NotImplementedError("get_release_tags endpoint is not yet implemented.")
67+
68+
def get_release_related_tags(self, release_id: int = None, **kwargs) -> dict:
69+
"""Get release related tags by ID."""
70+
raise NotImplementedError("get_release_related_tags endpoint is not yet implemented.")
71+
72+
def get_release_tables(self, release_id: int = None, element_id: int = None, **kwargs) -> dict:
73+
"""Get release tables by ID."""
74+
return self._get(f"release/tables", {
75+
"release_id": release_id,
76+
"element_id": element_id,
77+
**kwargs,
78+
})

src/fredapi/api/sources.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python3
22
"""
3-
Fred API Series Namespace.
3+
Fred API Sources Namespace.
44
"""
55
from .fred_client import FredClient
66

77

8-
class FredAPISeries(FredClient):
8+
class FredAPISources(FredClient):
99
"""
10-
Fred API Series Namespace.
10+
Fred API Sources Namespace.
1111
1212
Endpoints:
1313
fred/sources - Get all sources of economic data.
@@ -21,14 +21,14 @@ def get_sources(self, **kwargs) -> dict:
2121
**kwargs,
2222
})
2323

24-
def get_source(self, source_id: str = None, **kwargs) -> dict:
24+
def get_source(self, source_id: int = None, **kwargs) -> dict:
2525
"""Get source by ID."""
2626
return self._get(f"source", {
2727
"source_id": source_id,
2828
**kwargs,
2929
})
3030

31-
def get_source_releases(self, source_id: str = None, **kwargs) -> dict:
31+
def get_source_releases(self, source_id: int = None, **kwargs) -> dict:
3232
"""Get source releases by ID."""
3333
return self._get(f"source/releases", {
3434
"source_id": source_id,

tests/test_category.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
"""
3-
Test the Fred API Category Namespace.
3+
Test the Fred API Categories Namespace.
44
"""
55
import unittest
66

@@ -12,7 +12,7 @@ class TestFredAPICategory(unittest.TestCase):
1212

1313
def setUp(self):
1414
"""Setup the test."""
15-
self.fred_api_category = FredAPICategory(config.API_KEY)
15+
self.fred_api_category = FredAPICategory()
1616

1717
def test_init_assertion_error(self):
1818
"""Test the init assertion error."""

0 commit comments

Comments
 (0)