Commit 2a95540
authored
Improve
@kmoscoe identified an improvement we can make to how the
`DataCommonsClient` class handles a fully resolved URL.
For context, during the design phase, @dwnoble requested having a way to
provide a fully resolved URL, instead of the URL of Google's Data
Commons (datacommons.org) or the URL of a custom Data Commons instance
(like datacommons.one.org).
That means that the `DataCommonsClient` class is initiated with:
```python
"""
Args:
api_key (Optional[str]): The API key for authentication. Defaults to None. Note that
custom DC instances do not currently require an API key.
dc_instance (Optional[str]): The Data Commons instance to use. Defaults to "datacommons.org".
url (Optional[str]): A custom, fully resolved URL for the Data Commons API. Defaults to None.
"""
```
However, as @kmoscoe pointed out, if a `url` is used, it will return an
error unless `dc_instance` is set to `None`. That's because both
`dc_instance` and `url` cannot be set at the same time... and currently
the default value of `dc_instance` is, for convenience,
`datacommons.org`.
This PR introduces a small check (and it's associated test), to ignore
`dc_instance` (if its default value is used) in cases when a `url` is
provided.
That would allow for something like this to work:
```python
from datacommons_client.client import DataCommonsClient
client = DataCommonsClient(url="http://localhost:8080/core/api/v2/")
```
Instead of raising an error and requiring to also set `dc_instance` to
`None`.url handling (#216)1 parent e7dd8e3 commit 2a95540
2 files changed
+33
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
48 | 53 | | |
49 | 54 | | |
50 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
| |||
95 | 98 | | |
96 | 99 | | |
97 | 100 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
| |||
162 | 167 | | |
163 | 168 | | |
164 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
0 commit comments