def send_batch(self, batch): """ Sends a Batch object containing no more than 100 Lookup objects to the US Street API and stores the results in the result field of the Lookup object. """ smartyrequest = Request() if len(batch) == 0: return converted_lookups = remap_keys(batch.all_lookups) if len(batch) == 1: smartyrequest.parameters = converted_lookups[0] else: smartyrequest.payload = self.serializer.serialize( converted_lookups) response = self.sender.send(smartyrequest) if response.error: raise response.error candidates = self.serializer.deserialize(response.payload) or [] assign_candidates_to_lookups(batch, candidates)
def build_request(lookup): request = Request() request.content_type = 'text/plain' request.payload = lookup.text Client.add_parameter(request, 'html', str(lookup.html).lower()) Client.add_parameter(request, 'aggressive', str(lookup.aggressive).lower()) Client.add_parameter(request, 'addr_line_breaks', str(lookup.addresses_have_line_breaks).lower()) Client.add_parameter(request, 'addr_per_line', lookup.addresses_per_line) return request
def send_batch(self, batch): """ Sends a Batch object containing no more than 100 Lookup objects to the US ZIP Code API and stores the results in the result field of the Lookup object. """ smartyrequest = Request() if len(batch) == 0: return converted_lookups = remap_keys(batch.all_lookups) smartyrequest.payload = self.serializer.serialize(converted_lookups) response = self.sender.send(smartyrequest) if response.error: raise response.error results = self.serializer.deserialize(response.payload) if results is None: results = [] assign_results_to_lookups(batch, results)