From c2844710c9ed2bf833c9fceb7f0f524fff1f2d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20B=C3=BChrig?= Date: Tue, 10 Apr 2018 23:42:29 +0200 Subject: [PATCH] Some bugfixings. Corrected search-request-url. --- yelp/coordinate_options.go | 6 ++--- yelp/general_options.go | 12 +++++----- yelp/null.go | 45 ++++++++++++++++++++++++++++++++++++++ yelp/yelp.go | 8 +++---- 4 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 yelp/null.go diff --git a/yelp/coordinate_options.go b/yelp/coordinate_options.go index b5f314a..06b853a 100644 --- a/yelp/coordinate_options.go +++ b/yelp/coordinate_options.go @@ -3,16 +3,14 @@ package yelp import ( "errors" "fmt" - - "github.com/guregu/null" ) // CoordinateOptions are used with complex searches for locations. // The geographic coordinate format is defined as: // ll=latitude,longitude,accuracy,altitude,altitude_accuracy type CoordinateOptions struct { - Latitude null.Float // Latitude of geo-point to search near (required) - Longitude null.Float // Longitude of geo-point to search near (required) + Latitude Float // Latitude of geo-point to search near (required) + Longitude Float // Longitude of geo-point to search near (required) // Accuracy null.Float // Accuracy of latitude, longitude (optional) // Altitude null.Float // Altitude (optional) // AltitudeAccuracy null.Float // Accuracy of altitude (optional) diff --git a/yelp/general_options.go b/yelp/general_options.go index 6a7cad7..d05125f 100644 --- a/yelp/general_options.go +++ b/yelp/general_options.go @@ -2,18 +2,16 @@ package yelp import ( "fmt" - - "github.com/guregu/null" ) // GeneralOptions includes a set of standard query options for using the search API. // They are used along with a location based option to complete a search. type GeneralOptions struct { - Term string // Search term (e.g. "food", "restaurants"). If term isn’t included we search everything. - Limit null.Int // Number of business results to return - Offset null.Int // Offset the list of returned business results by this amount - SortBy string // Sort mode: 0=Best matched (default), 1=Distance, 2=Highest Rated. If the mode is 1 or 2 a search may retrieve an additional 20 businesses past the initial limit of the first 20 results. This is done by specifying an offset and limit of 20. Sort by distance is only supported for a location or geographic search. The rating sort is not strictly sorted by the rating value, but by an adjusted rating value that takes into account the number of ratings, similar to a bayesian average. This is so a business with 1 rating of 5 stars doesn’t immediately jump to the top. - CategoryFilter string // Category to filter search results with. See the list of supported categories. The category filter can be a list of comma delimited categories. For example, 'bars,french' will filter by Bars and French. The category identifier should be used (for example 'discgolf', not 'Disc Golf'). + Term string // Search term (e.g. "food", "restaurants"). If term isn’t included we search everything. + Limit Int // Number of business results to return + Offset Int // Offset the list of returned business results by this amount + SortBy string // Sort mode: 0=Best matched (default), 1=Distance, 2=Highest Rated. If the mode is 1 or 2 a search may retrieve an additional 20 businesses past the initial limit of the first 20 results. This is done by specifying an offset and limit of 20. Sort by distance is only supported for a location or geographic search. The rating sort is not strictly sorted by the rating value, but by an adjusted rating value that takes into account the number of ratings, similar to a bayesian average. This is so a business with 1 rating of 5 stars doesn’t immediately jump to the top. + CategoryFilter string // Category to filter search results with. See the list of supported categories. The category filter can be a list of comma delimited categories. For example, 'bars,french' will filter by Bars and French. The category identifier should be used (for example 'discgolf', not 'Disc Golf'). // RadiusFilter null.Float // Search radius in meters. If the value is too large, a AREA_TOO_LARGE error may be returned. The max value is 40000 meters (25 miles). // DealsFilter null.Bool // Whether to exclusively search for businesses with deals Locale string diff --git a/yelp/null.go b/yelp/null.go new file mode 100644 index 0000000..220905b --- /dev/null +++ b/yelp/null.go @@ -0,0 +1,45 @@ +package yelp + +import "github.com/guregu/null" + +//Float delegate for guregu/null +type Float struct { + null.Float +} + +//NewFloat Construction +func NewFloat(f float64, valid bool) Float { return Float{null.NewFloat(f, valid)} } + +//FloatFrom Construction +func FloatFrom(f float64) Float { return Float{null.FloatFrom(f)} } + +//FloatFromPtr Construction +func FloatFromPtr(f *float64) Float { return Float{null.FloatFromPtr(f)} } + +//Int delegate for guregu/null +type Int struct { + null.Int +} + +//NewInt Construction +func NewInt(f int64, valid bool) Int { return Int{null.NewInt(f, valid)} } + +//IntFrom Construction +func IntFrom(f int64) Int { return Int{null.IntFrom(f)} } + +//IntFromPtr Construction +func IntFromPtr(f *int64) Int { return Int{null.IntFromPtr(f)} } + +//Bool delegate for guregu/null +type Bool struct { + null.Bool +} + +//NewBool Construction +func NewBool(f bool, valid bool) Bool { return Bool{null.NewBool(f, valid)} } + +//BoolFrom Construction +func BoolFrom(f bool) Bool { return Bool{null.BoolFrom(f)} } + +//BoolFromPtr Construction +func BoolFromPtr(f *bool) Bool { return Bool{null.BoolFromPtr(f)} } diff --git a/yelp/yelp.go b/yelp/yelp.go index 2bf1aa1..d459436 100644 --- a/yelp/yelp.go +++ b/yelp/yelp.go @@ -119,11 +119,11 @@ func (client *Client) makeRequest(area string, id string, params map[string]stri if params["offset"] != "" { q.Add("offset", params["offset"]) } - if params["sortby"] != "" { - q.Add("sort_by", params["sortby"]) + if params["sort_by"] != "" { + q.Add("sort_by", params["sort_by"]) } - if params["categoryfilter"] != "" { - q.Add("category_filter", params["categoryfilter"]) + if params["category_filter"] != "" { + q.Add("categories", params["category_filter"]) } if params["locale"] != "" { q.Add("locale", params["locale"])