Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WB_WDI source improvement #208

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions sdmx/source/wb_wdi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import Source as BaseSource
from sdmx.rest import Resource
from sdmx.source import Source as BaseSource


class Source(BaseSource):
Expand All @@ -8,12 +9,33 @@ def modify_request_args(self, kwargs):
"""World Bank's agency ID."""
super().modify_request_args(kwargs)

if kwargs["resource_type"] == "categoryscheme":
if kwargs.get("resource_type") == Resource.categoryscheme:
# Service does not respond to requests for "WB" category schemes
kwargs["provider"] = "all"
elif kwargs["resource_type"] != "data":
elif kwargs.get("resource_type") == Resource.data:
# Provider's own ID differs from its ID in this package
kwargs.setdefault("provider", "WB")
elif kwargs.get("resource_type") == Resource.dataflow:
# Here we have no agency_id (/all/latest is allowed).
# Unless set, it is added automatically, use url to avoid that.
kwargs.pop("resource_type")
if not all(value is None for value in kwargs.values()):
raise ValueError(
"WDI dataflow is a unique endpoint and doesn't support arguments"
)
kwargs.setdefault(
"url", "https://api.worldbank.org/v2/sdmx/rest/dataflow"
)
elif kwargs.get("resource_type") in {Resource.datastructure, Resource.codelist}:
# Here /all/latest is not allowed.
# It is added automatically, use url to circumvent that.
name = kwargs.get("resource_type").name
kwargs.pop("resource_type")
if not all(value is None for value in kwargs.values()):
raise ValueError(
f"WDI {name} is a unique endpoint and doesn't support arguments"
)
kwargs.setdefault("url", f"https://api.worldbank.org/v2/sdmx/rest/{name}/wb")

try:
if isinstance(kwargs["key"], str):
Expand Down
6 changes: 3 additions & 3 deletions sdmx/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@
"allowedconstraint": false,
"categorisation": false,
"categoryscheme": false,
"codelist": false,
"codelist": true,
"conceptscheme": false,
"contentconstraint": false,
"dataconsumerscheme": false,
"dataflow": false,
"dataflow": true,
"dataproviderscheme": false,
"datastructure": false,
"datastructure": true,
"hierarchicalcodelist": false,
"metadataflow": false,
"metadatastructure": false,
Expand Down
Loading