class Yelp::Fusion::Endpoint::Search

Class to search for businesses

Constants

PATH

Public Class Methods

new(client) click to toggle source
# File lib/yelp/fusion/endpoint/search.rb, line 32
def initialize(client)
  @client = client
end

Public Instance Methods

search_by_coordinates(coordinates, params = {}) click to toggle source

Search by coordinates: give it a latitude and longitude along with option accuracy, altitude, and altitude_accuracy to search an area. More info at: www.yelp.com/developers/documentation/v3/business_search

@param coordinates [Hash] a hash of latitude and longitude. @param params [Hash] a hash that corresponds to params on the API:

https://www.yelp.com/developers/documentation/v3/business_search

@return [Response::Search] a parsed object of the response.

For a complete list of possible response values visit:
https://www.yelp.com/developers/documentation/v3/business_search

@example Search for business with params

coordinates = { latitude: 37.786732,
                longitude: -122.399978 }

params = { term: 'food',
           limit: 3,
           category: 'discgolf' }

response = client.search(coordinates, params)
response.businesses # [<Business 1>, <Business 2>, <Business 3>]
response.businesses[0].name # 'Yelp'
# File lib/yelp/fusion/endpoint/search.rb, line 84
def search_by_coordinates(coordinates, params = {})
  raise Error::MissingLatLng if coordinates[:latitude].nil? ||
                                coordinates[:longitude].nil?

  coordinates.merge!(params)
  Responses::Search.new(JSON.parse(search_request(coordinates).body))
end

Private Instance Methods

search_request(params) click to toggle source

Make a request against the search endpoint from the API and return the raw response. After getting the response back it's checked to see if there are any API errors and raises the relevant one if there is.

@param params [Hash] a hash of parameters for the search request @return [Faraday::Response] the raw response back from the connection

# File lib/yelp/fusion/endpoint/search.rb, line 100
def search_request(params)
  result = @client.connection.get(PATH, params)
  Yelp::Fusion::Error.check_for_error(result)
  result
end