def _iterate_dict(self): """Iterate through the dict data found.""" selection = MapSelect(definitions=self.final_fields, json_data=self.json_data) result = selection.iterit() result_1 = self._call_api(result) return result_1
def _iterate_list(self): """Iterate through the list data found.""" selected_data = [] for objct in self.json_data: selection = MapSelect(definitions=self.final_fields, json_data=[objct]) selected_objct = selection.iterit() if selected_objct != {}: selected_data.append(selected_objct) return selected_data
def _iterate_dict(self): """Iterate through the dict data found.""" selection_value_lst = [] selection = MapSelect(definitions=self.final_fields, json_data=self.json_data) selection_value = selection.iterit() for key, value in selection_value.items(): if isinstance(value, list): selection_value_lst = selection_value_lst + value else: selection_value_lst.append(value) return selection_value_lst
def _iterate_list(self): """Iterate through the list data found.""" selected_data = [] for objct in self.json_data: selection = MapSelect(definitions=self.final_fields, json_data=[objct]) selected_objct = selection.iterit() if selected_objct != {}: result = self._call_api(selected_objct) ### NEEDS TESTING AF selected_data = list_protection(result, selected_data) return selected_data
def iterate(self, req_fields): """Get the selected fields from json data.""" # Atribute provided selection var to instance var. self.req_fields = req_fields # Validate the fields provided. if not self._validate_req_fields(): return self.selected_data # Select the data. self.selected_data = self._iterate_json() new_context_map = MapSelect(json_data=self.selected_data) self.json_map = new_context_map.mapit() self.final_fields_order = self._get_available_fields('?', mode='') return self.selected_data
def _iterate_list(self): """Iterate through the list data found.""" selected_data = [] selection_value_lst = [] for objct in self.json_data: selection = MapSelect(definitions=self.final_fields, json_data=[objct]) selected_objct = selection.iterit() if selected_objct != {}: selection_value_lst = [] if isinstance(selected_objct, list): selection_value_lst = selection_value_lst + selected_objct if isinstance(selected_objct, dict): for key, value in selected_objct.items(): if isinstance(value, list): selection_value_lst = selection_value_lst + value else: selection_value_lst.append(value) selected_data = selected_data + selection_value_lst return selected_data
def model_map(self): """Generate map from json model to allow verification.""" # Get a map from the json provided. table_order = [] if self.fields_model == {} or self.fields_model == []: json_iter = MapSelect(definitions=[], json_data=self.json_data) else: two_hundred = self.fields_model['doc']['responses']['200'] schema = two_hundred['schema'] if 'table_order' in two_hundred.keys(): table_order = two_hundred['table_order'] if schema == {}: json_iter = MapSelect(definitions=[], json_data=self.json_data) else: json_iter = MapResponseDoc(json_data=self.fields_model) self.json_map = json_iter.mapit() self.json_map.table_order = table_order return self.json_map
def _iterate_dict(self): """Iterate through the dict data found.""" selection = MapSelect(definitions=self.final_fields, json_data=self.json_data) return selection.iterit()