The YelpJavaClient provides a simple Java interface for interacting with Yelp's API.
<dependency>
<groupId>tech.redroma.yelp</groupId>
<artifactId>yelp-api</artifactId>
<version>1.1</version>
</dependency>
Create a client using the App ID and App Secret that you obtained from the Yelp Developer console.
String clientId = "...";
String clientSecret = "...";
YelpAPI yelp = YelpAPI.newInstance(clientId, clientSecret);
Searching businesses is as easy as making a request object and using the searchForBusinesses()
method.
//Create a request object
YelpSearchRequest request = YelpSearchRequest.newBuilder()
.withSearchTerm("Deli")
.withCoordinate(Coordinate.of(34.018363, -118.492343))
.withLimit(10)
.withSortBy(YelpSearchRequest.SortType.DISTANCE)
.build();
//Make the request
List<YelpBusiness> results = yelp.searchForBusinesses(request);
LOG.info("Found {} results for request {}", results.size(), request);
Sometimes you want more detailed information about a business, such as the business hours, additional photos, and price information.
Simply call the getBusinessDetails()
method.
//Using any business
YelpBusiness business = Lists.oneOf(results);
//Make the request to get business details.
YelpBusinessDetails businessDetails = yelp.getBusinessDetails(business);
LOG.info("Received detailed info for business named {}: [{}]", business.name, businessDetails);
if (businessDetails.isOpenNow())
{
LOG.info("{} is open now.", businessDetails.name)
}
YelpBusiness business = Lists.oneof(business);
List<YelpReview> reviews = yelp.getReviewsForBusiness(business);
LOG.info("Business named")
We do not yet support the following API calls:
We used Alchemy Design Principles when designing this library.
We wanted our code to feel like it was barely there. This meant keeping things minimal and light.
Yelp already designed a great intuitive API. We didn't want to add a pool of unnecessary soda.
Nearly everything is unit tested, and it is already being used in production by BlackNectar, and others.
We wanted you to have fun, and to feel powerful.
We ditched the no-fun java get() set()
pojo style in favor of open public
variables. We trust you.
This Software is licensed under the Apache 2.0 License