Skip to content

Commit fb29d43

Browse files
authored
Feature/required args (#10)
* create api decorator to check valid args * format files * add args validation for releases * add api arg validator for categories * update required args for categories namespace * add required args to tags namespace * add validate args to sources apis * add arg validation to series namespace * add required args for series apis * finish base implementation of all APIs, closes issue #4 * bump fred-py-api to 0.0.5 and update readme to point to wiki
1 parent bee1303 commit fb29d43

File tree

9 files changed

+353
-120
lines changed

9 files changed

+353
-120
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Fred Python API
22
A fully-featured FRED Python Wrapper.
33

4+
## Documentation:
5+
- [fred-py-api Docs](https://github.com/zachspar/fred-py-api/wiki)
6+
47
### FRED References:
58
- [API Documentation](https://fred.stlouisfed.org/docs/api/fred/)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "fred_py_api"
7-
version = "0.0.4"
7+
version = "0.0.5"
88
authors = [
99
{ name="Zachary Spar", email="[email protected]" },
1010
]

src/fredapi/api/categories.py

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Fred API for Categories Namespace.
44
"""
55
from .fred_client import FredClient
6+
from ..util.decorators import validate_api_args
67

78

89
class FredAPICategories(FredClient):
@@ -18,38 +19,85 @@ class FredAPICategories(FredClient):
1819
fred/category/related_tags - Get the related tags for a category.
1920
"""
2021

22+
@validate_api_args("api_key", "file_type", "category_id")
2123
def get_category(self, category_id: int = None, **kwargs) -> dict:
2224
"""Get category by ID."""
23-
return self._get(f"category", {
24-
"category_id": category_id,
25-
**kwargs,
26-
})
25+
return self._get(f"category", {"category_id": category_id, **kwargs,})
2726

28-
def get_category_series(self, category_id: int = None, **kwargs) -> dict:
27+
@validate_api_args(
28+
"api_key",
29+
"file_type",
30+
"category_id",
31+
"realtime_start",
32+
"realtime_end",
33+
"limit",
34+
"offset",
35+
"order_by",
36+
"sort_order",
37+
"filter_variable",
38+
"filter_value",
39+
"tag_names",
40+
"exclude_tag_names",
41+
)
42+
def get_category_series(self, category_id: int, **kwargs) -> dict:
2943
"""Get category series by ID."""
30-
return self._get(f"category/series", {
31-
"category_id": category_id,
32-
**kwargs,
33-
})
44+
return self._get(f"category/series", {"category_id": category_id, **kwargs,})
3445

46+
@validate_api_args("api_key", "file_type", "category_id", "realtime_start", "realtime_end")
3547
def get_category_children(self, category_id: int = None, **kwargs) -> dict:
3648
"""Get category children by ID."""
37-
return self._get(f"category/children", {
38-
"category_id": category_id,
39-
**kwargs,
40-
})
49+
return self._get(f"category/children", {"category_id": category_id, **kwargs,})
4150

42-
def get_category_related(self, category_id: int = None, **kwargs) -> dict:
51+
@validate_api_args("api_key", "file_type", "category_id", "realtime_start", "realtime_end")
52+
def get_category_related(self, category_id: int, **kwargs) -> dict:
4353
"""Get category related by ID."""
44-
return self._get(f"category/related", {
45-
"category_id": category_id,
46-
**kwargs,
47-
})
54+
return self._get(f"category/related", {"category_id": category_id, **kwargs,})
4855

49-
def get_category_tags(self, category_id: int = None, **kwargs) -> dict:
56+
@validate_api_args(
57+
"api_key",
58+
"file_type",
59+
"category_id",
60+
"realtime_start",
61+
"realtime_end",
62+
"limit",
63+
"offset",
64+
"order_by",
65+
"sort_order",
66+
"filter_variable",
67+
"filter_value",
68+
"tag_names",
69+
"tag_group_id",
70+
"search_text",
71+
"limit",
72+
"offset",
73+
"order_by",
74+
"sort_order",
75+
)
76+
def get_category_tags(self, category_id: int, **kwargs) -> dict:
5077
"""Get category tags by ID."""
51-
raise NotImplementedError("get_category_tags endpoint is not yet implemented.")
78+
return self._get(f"category/tags", {"category_id": category_id, **kwargs,})
5279

53-
def get_category_related_tags(self, category_id: int = None, **kwargs) -> dict:
80+
@validate_api_args(
81+
"api_key",
82+
"file_type",
83+
"category_id",
84+
"realtime_start",
85+
"realtime_end",
86+
"limit",
87+
"offset",
88+
"order_by",
89+
"sort_order",
90+
"filter_variable",
91+
"filter_value",
92+
"tag_names",
93+
"exclude_tag_names",
94+
"tag_group_id",
95+
"search_text",
96+
"limit",
97+
"offset",
98+
"order_by",
99+
"sort_order",
100+
)
101+
def get_category_related_tags(self, category_id: int, tag_names: str, **kwargs) -> dict:
54102
"""Get category related tags by ID."""
55-
raise NotImplementedError("get_category_related_tags endpoint is not yet implemented.")
103+
return self._get(f"category/related_tags", {"category_id": category_id, "tag_names": tag_names, **kwargs,})

src/fredapi/api/releases.py

Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Fred API for Releases Namespace.
44
"""
55
from .fred_client import FredClient
6+
from ..util.decorators import validate_api_args
67

78

89
class FredAPIReleases(FredClient):
@@ -21,58 +22,112 @@ class FredAPIReleases(FredClient):
2122
fred/release/tables - Get the release tables for a given release.
2223
"""
2324

25+
@validate_api_args(
26+
"api_key", "file_type", "realtime_start", "realtime_end", "limit", "offset", "order_by", "sort_order"
27+
)
2428
def get_releases(self, **kwargs) -> dict:
2529
"""Get releases."""
26-
return self._get(f"releases", {
27-
**kwargs,
28-
})
30+
return self._get(f"releases", {**kwargs,})
2931

32+
@validate_api_args(
33+
"api_key",
34+
"file_type",
35+
"realtime_start",
36+
"realtime_end",
37+
"limit",
38+
"offset",
39+
"order_by",
40+
"sort_order",
41+
"include_release_dates_with_no_data",
42+
)
3043
def get_releases_dates(self, **kwargs) -> dict:
3144
"""Get releases dates."""
32-
return self._get(f"releases/dates", {
33-
**kwargs,
34-
})
45+
return self._get(f"releases/dates", {**kwargs,})
3546

36-
def get_release(self, release_id: int = None, **kwargs) -> dict:
47+
@validate_api_args("api_key", "release_id", "file_type", "realtime_start", "realtime_end")
48+
def get_release(self, release_id: int, **kwargs) -> dict:
3749
"""Get release by ID."""
38-
return self._get(f"release", {
39-
"release_id": release_id,
40-
**kwargs,
41-
})
50+
return self._get(f"release", {"release_id": release_id, **kwargs,})
4251

43-
def get_release_dates(self, release_id: int = None, **kwargs) -> dict:
52+
@validate_api_args(
53+
"api_key",
54+
"release_id",
55+
"file_type",
56+
"realtime_start",
57+
"realtime_end",
58+
"limit",
59+
"offset",
60+
"sort_order",
61+
"include_release_dates_with_no_data",
62+
)
63+
def get_release_dates(self, release_id: int, **kwargs) -> dict:
4464
"""Get release dates by ID."""
45-
return self._get(f"release/dates", {
46-
"release_id": release_id,
47-
**kwargs,
48-
})
65+
return self._get(f"release/dates", {"release_id": release_id, **kwargs,})
4966

50-
def get_release_series(self, release_id: int = None, **kwargs) -> dict:
67+
@validate_api_args(
68+
"api_key",
69+
"file_type",
70+
"release_id",
71+
"realtime_start",
72+
"realtime_end",
73+
"limit",
74+
"offset",
75+
"order_by",
76+
"sort_order",
77+
"filter_variable",
78+
"filter_value",
79+
"tag_names",
80+
"exclude_tag_names",
81+
)
82+
def get_release_series(self, release_id: int, **kwargs) -> dict:
5183
"""Get release series by ID."""
52-
return self._get(f"release/series", {
53-
"release_id": release_id,
54-
**kwargs,
55-
})
84+
return self._get(f"release/series", {"release_id": release_id, **kwargs,})
5685

57-
def get_release_sources(self, release_id: int = None, **kwargs) -> dict:
86+
@validate_api_args("api_key", "file_type", "release_id", "realtime_start", "realtime_end")
87+
def get_release_sources(self, release_id: int, **kwargs) -> dict:
5888
"""Get release sources by ID."""
59-
return self._get(f"release/sources", {
60-
"release_id": release_id,
61-
**kwargs,
62-
})
89+
return self._get(f"release/sources", {"release_id": release_id, **kwargs,})
6390

64-
def get_release_tags(self, release_id: int = None, **kwargs) -> dict:
91+
@validate_api_args(
92+
"api_key",
93+
"file_type",
94+
"release_id",
95+
"realtime_start",
96+
"realtime_end",
97+
"tag_names",
98+
"tag_group_id",
99+
"search_text",
100+
"limit",
101+
"offset",
102+
"order_by",
103+
"sort_order",
104+
)
105+
def get_release_tags(self, release_id: int, **kwargs) -> dict:
65106
"""Get release tags by ID."""
66-
raise NotImplementedError("get_release_tags endpoint is not yet implemented.")
107+
return self._get(f"release/tags", {"release_id": release_id, **kwargs,})
67108

68-
def get_release_related_tags(self, release_id: int = None, **kwargs) -> dict:
109+
@validate_api_args(
110+
"api_key",
111+
"file_type",
112+
"release_id",
113+
"realtime_start",
114+
"realtime_end",
115+
"tag_names",
116+
"exclude_tag_names",
117+
"tag_group_id",
118+
"search_text",
119+
"limit",
120+
"offset",
121+
"order_by",
122+
"sort_order",
123+
)
124+
def get_release_related_tags(self, release_id: int, tag_names: str, **kwargs) -> dict:
69125
"""Get release related tags by ID."""
70-
raise NotImplementedError("get_release_related_tags endpoint is not yet implemented.")
126+
return self._get(f"release/related_tags", {"release_id": release_id, "tag_names": tag_names, **kwargs,})
71127

72-
def get_release_tables(self, release_id: int = None, element_id: int = None, **kwargs) -> dict:
128+
@validate_api_args(
129+
"api_key", "file_type", "release_id", "element_id", "include_observation_values", "observation_date"
130+
)
131+
def get_release_tables(self, release_id: int, element_id: int = None, **kwargs) -> dict:
73132
"""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-
})
133+
return self._get(f"release/tables", {"release_id": release_id, "element_id": element_id, **kwargs,})

0 commit comments

Comments
 (0)