|
6 | 6 | import requests |
7 | 7 |
|
8 | 8 | from reposit.data.exceptions import InvalidControllerException |
9 | | -from reposit.data.utils import is_valid_url |
| 9 | +from reposit.data.utils import is_valid_url, deepest_key, match_to_schema |
10 | 10 | from reposit.settings import BASE_URL |
11 | | -from reposit.utilities import dict_iter |
12 | 11 |
|
13 | 12 | logger = logging.getLogger(__name__) |
14 | 13 |
|
@@ -103,32 +102,3 @@ def _simple_format_for_fields(self, api_response): |
103 | 102 | target_key = deepest_key(self.schema) |
104 | 103 | target_data = match_to_schema(data, target_key) |
105 | 104 | return target_data |
106 | | - |
107 | | - |
108 | | -def deepest_key(_dict): |
109 | | - """Return the deepest key in a dict""" |
110 | | - for key, value in dict_iter(_dict): |
111 | | - if isinstance(value, dict) and bool(value): |
112 | | - return deepest_key(_dict[key]) |
113 | | - return key |
114 | | - |
115 | | - |
116 | | -def match_to_schema(_dict, requested_key): |
117 | | - """ |
118 | | - Match the schema supplied with the response to return the |
119 | | - data we requested. |
120 | | - :param _dict: |
121 | | - :param requested_key: |
122 | | - :return: |
123 | | - """ |
124 | | - if _dict.get(requested_key) is not None: |
125 | | - return _dict[requested_key] |
126 | | - |
127 | | - for valid_key in _dict: |
128 | | - if valid_key == requested_key: |
129 | | - if not isinstance(_dict.get(valid_key), dict): |
130 | | - return _dict[valid_key] |
131 | | - else: |
132 | | - continue |
133 | | - elif valid_key != requested_key and isinstance(_dict.get(valid_key), dict): |
134 | | - return match_to_schema(_dict[valid_key], requested_key) |
0 commit comments