File tree Expand file tree Collapse file tree 3 files changed +33
-18
lines changed
Expand file tree Collapse file tree 3 files changed +33
-18
lines changed Original file line number Diff line number Diff line change 33from ..services .location .jhu import JhuLocationService
44from ..services .location .nyt import NYTLocationService
55
6- # Mapping of services to data-sources.
7- DATA_SOURCES = {
8- "jhu" : JhuLocationService (),
9- "csbs" : CSBSLocationService (),
10- "nyt" : NYTLocationService (),
11- }
6+ class DataSources :
7+ # Mapping of services to data-sources.
8+ __DATA_SOURCES_MAP = {
9+ "jhu" : JhuLocationService (),
10+ "csbs" : CSBSLocationService (),
11+ "nyt" : NYTLocationService (),
12+ }
1213
14+ def __init__ (self ):
15+ pass
1316
14- def data_source ( source ):
15- """
16- Retrieves the provided data-source service.
17+ def get_data_source ( self , source ):
18+ """
19+ Retrieves the provided data-source service.
1720
18- :returns: The service.
19- :rtype: LocationService
20- """
21- return DATA_SOURCES .get (source .lower ())
21+ :returns: The service.
22+ :rtype: LocationService
23+ """
24+ return self .__DATA_SOURCES_MAP .get (source .lower ())
25+
26+ def get_data_sources (self ):
27+ """
28+ Retrieves a dict of all data sources.
29+
30+ :returns: The dictionary of data sources.
31+ :rtype: dict
32+ """
33+ return self .__DATA_SOURCES_MAP
Original file line number Diff line number Diff line change 1414from sentry_sdk .integrations .asgi import SentryAsgiMiddleware
1515
1616from .config import get_settings
17- from .data import data_source
17+ from .data import DataSources
1818from .routers import V1 , V2
1919from .utils .httputils import setup_client_session , teardown_client_session
2020
4141 on_shutdown = [teardown_client_session ],
4242)
4343
44+ DATA_SOURCES = DataSources ()
45+
4446# #####################
4547# Middleware
4648#######################
@@ -73,8 +75,8 @@ async def add_datasource(request: Request, call_next):
7375 """
7476 Attach the data source to the request.state.
7577 """
76- # Retrieve the datas ource from query param.
77- source = data_source (request .query_params .get ("source" , default = "jhu" ))
78+ # Retrieve the data source from query param.
79+ source = DATA_SOURCES . get_data_source (request .query_params .get ("source" , default = "jhu" ))
7880
7981 # Abort with 404 if source cannot be found.
8082 if not source :
Original file line number Diff line number Diff line change 33
44from fastapi import APIRouter , HTTPException , Request
55
6- from ..data import DATA_SOURCES
6+ from ..data import DataSources
77from ..models import LatestResponse , LocationResponse , LocationsResponse
88
99V2 = APIRouter ()
10+ DATA_SOURCES = DataSources ()
1011
1112
1213class Sources (str , enum .Enum ):
@@ -107,4 +108,4 @@ async def sources():
107108 """
108109 Retrieves a list of data-sources that are availble to use.
109110 """
110- return {"sources" : list (DATA_SOURCES .keys ())}
111+ return {"sources" : list (DATA_SOURCES .get_data_sources (). keys ())}
You can’t perform that action at this time.
0 commit comments