Exemple #1
0
    def test_retrieve_search_summary_00(self, mocker):
        """Ensure the collector functions are called."""
        c = CollectorClient(self.fake.pystr())
        c.collector = mocker.Mock()

        c.retrieve_search_summary(self.fake.pystr())

        c.collector.retrieve_search_summary.assert_called()
Exemple #2
0
    def test_lookup_place_02(self, mocker):
        """Ensure lookup returns details for a given name/address pair."""
        fake_place_id = self.fake.pystr()
        fake_name = self.fake.pystr()
        fake_address = self.fake.address()
        c = CollectorClient(self.fake.pystr())
        c.search_places = mocker.Mock()
        c.retrieve_search_summary = mocker.Mock(
            return_value=PlaceSearchSummary(place_id=fake_place_id))
        c.get_place_details = mocker.Mock()

        c.lookup_place(name=fake_name, address=fake_address)

        c.search_places.assert_called_with(address=fake_address,
                                           terms=fake_name,
                                           limit=1)
        c.get_place_details.assert_called_with(fake_place_id)
Exemple #3
0
def collect_place_details_from_yelp(name, address):
    """Collect business information from Yelp."""
    # Prepare client.
    client = CollectorClient('yelp',
                             api_key=os.environ['RYR_COLLECTOR_YELP_API_KEY'])
    client.authenticate()

    # Retrieve detailed results.
    client.search_places(address, terms=name, limit=1)
    place_summary = client.retrieve_search_summary(0)

    if not place_summary:
        raise ValueError('Yelp did not return any result.')

    # Extract the place_id.
    details = client.get_place_details(place_summary.place_id)
    return details