Class: Yelp::Fusion::Endpoint::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/yelp/fusion/endpoint/search.rb

Overview

Class to search for businesses

Constant Summary collapse

PATH =
'/v3/businesses/search'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Search

Returns a new instance of Search.



32
33
34
# File 'lib/yelp/fusion/endpoint/search.rb', line 32

def initialize(client)
  @client = client
end

Instance Method Details

#search(location, params = {}) ⇒ Response::Search

Take a search_request and return the formatted/structured response from the API

Examples:

Search for business with params

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

response = client.search('San Francisco', params)
response.businesses # [<Business 1>, <Business 2>, <Business 3>]
response.businesses[0].name # 'Yelp'

Parameters:

Returns:



55
56
57
58
59
# File 'lib/yelp/fusion/endpoint/search.rb', line 55

def search(location, params = {})
  params[:location] = location

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

#search_by_coordinates(coordinates, params = {}) ⇒ Response::Search

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

Examples:

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'

Parameters:

Returns:

Raises:



84
85
86
87
88
89
90
# 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