go-yelp is a #golang wrapper for the Yelp REST API. It lets you do all kinds of interesting things like searching for businesses, getting user comments and ratings, and handling common errors. The library is written Go.
For more information, visit the Yelp REST API.
To install go-yelp, just use the go get
command:
go get github.com/JustinBeckwith/go-yelp/yelp
When you're ready to start using the API, import the reference:
import "github.com/JustinBeckwith/go-yelp/yelp"
All searches are performed through a client. To create a new client, you need provide a set of access keys necessary to use the V2 Yelp API. You can sign up for a Yelp developer account, and access your keys here:
Keep these keys safe! There are a variety of ways to store them. I chose to store them in a config.json file which is not checked into the repository. To run the tests, you can create your own config.json
file:
{
"ConsumerKey": "MY_CONSUMER_KEY",
"ConsumerSecret": "MY_CONSUMER_SECRET",
"AccessToken": "MY_ACCESS_TOKEN",
"AccessTokenSecret": "MY_ACCESS_TOKEN_SECRET"
}
The simple search API enables searching for businesses with a term and a location (ex: coffee, Seattle). After you have your keys, create a client, and make a simple query:
import "github.com/JustinBeckwith/go-yelp/yelp"
client := yelp.New(options, nil)
result, err := client.DoSimpleSearch("coffee", "seattle")
For more complex searches, the DoSearch
method allows for searching based on a combination of general search criteria, and advanced location options:
// Build an advanced set of search criteria that include
// general options, and location specific options.
options := SearchOptions{
GeneralOptions: &GeneralOptions{
Term: "food",
},
LocationOptions: &LocationOptions{
"bellevue",
&CoordinateOptions{
Latitude: null.FloatFrom(37.788022),
Longitude: null.FloatFrom(-122.399797),
},
},
}
// Perform the search using the search options
result, err := client.DoSearch(options)
To directly search for a business by name, use the client.GetBusiness(...)
method on the client:
client := yelp.New(options, nil)
result, err := client.GetBusiness("yelp-san-francisco")
This library is distributed under the MIT License found in the LICENSE file.
Feel free to submit an issue on the repository, or find me at @JustinBeckwith