示例#1
0
    def send(self, lookup):
        """
        Sends a Lookup object to the US Extract Code API and stores the result in the Lookup's result field.
        It also returns the result directly.
        """
        if lookup is None or lookup.text is None or not isinstance(lookup.text, str) or len(lookup.text.strip()) == 0:
            raise SmartyException('Client.send() requires a Lookup with the "text" field set')

        request = self.build_request(lookup)
        response = self.sender.send(request)
        result = Result(self.serializer.deserialize(response.payload))

        lookup.result = result
        return result
示例#2
0
    def send(self, lookup):
        """
        Sends a Lookup object to the US Autocomplete API and stores the result in the Lookup's result field.
        """
        if not lookup or not lookup.prefix:
            raise SmartyException(
                'Send() must be passed a Lookup with the prefix field set.')

        request = self.build_request(lookup)

        response = self.sender.send(request)

        result = self.serializer.deserialize(response.payload)
        suggestions = self.convert_suggestions(result.get('suggestions', []))
        lookup.result = suggestions

        return suggestions
示例#3
0
    def send(self, lookup):
        """
        Sends a Lookup object to the International Autocomplete API and stores the result in the Lookup's result field.
        """
        if not lookup or not lookup.search:
            raise SmartyException('Send() must be passed a Lookup with the search field set.')

        request = self.build_request(lookup)

        response = self.sender.send(request)

        if response.error:
            raise response.error

        result = self.serializer.deserialize(response.payload)
        candidates = self.convert_candidates(result.get('candidates') or [])
        lookup.result = candidates

        return candidates