yelp-fusion 0.1.pre.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +210 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +180 -0
- data/Rakefile +9 -0
- data/Test::vcr_casettes/business.yml +75 -0
- data/Test::vcr_casettes/match.yml +61 -0
- data/Test::vcr_casettes/phone.yml +65 -0
- data/Test::vcr_casettes/review.yml +72 -0
- data/Test::vcr_casettes/search.yml +263 -0
- data/Test::vcr_casettes/search_by_coordinates.yml +57 -0
- data/Test::vcr_casettes/transaction.yml +254 -0
- data/Test::vcr_casettes/transaction_by_coordinates.yml +56 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/yelp/fusion.rb +36 -0
- data/lib/yelp/fusion/client.rb +86 -0
- data/lib/yelp/fusion/configuration.rb +37 -0
- data/lib/yelp/fusion/endpoint/business.rb +70 -0
- data/lib/yelp/fusion/endpoint/match.rb +64 -0
- data/lib/yelp/fusion/endpoint/phone.rb +71 -0
- data/lib/yelp/fusion/endpoint/review.rb +72 -0
- data/lib/yelp/fusion/endpoint/search.rb +104 -0
- data/lib/yelp/fusion/endpoint/transaction.rb +97 -0
- data/lib/yelp/fusion/error.rb +105 -0
- data/lib/yelp/fusion/responses/base.rb +43 -0
- data/lib/yelp/fusion/responses/business.rb +36 -0
- data/lib/yelp/fusion/responses/match.rb +36 -0
- data/lib/yelp/fusion/responses/models/business.rb +48 -0
- data/lib/yelp/fusion/responses/models/categories.rb +34 -0
- data/lib/yelp/fusion/responses/models/center.rb +34 -0
- data/lib/yelp/fusion/responses/models/hours.rb +38 -0
- data/lib/yelp/fusion/responses/models/location.rb +36 -0
- data/lib/yelp/fusion/responses/models/openHours.rb +34 -0
- data/lib/yelp/fusion/responses/models/region.rb +38 -0
- data/lib/yelp/fusion/responses/models/reviews.rb +38 -0
- data/lib/yelp/fusion/responses/models/user.rb +36 -0
- data/lib/yelp/fusion/responses/phone.rb +36 -0
- data/lib/yelp/fusion/responses/review.rb +36 -0
- data/lib/yelp/fusion/responses/search.rb +38 -0
- data/lib/yelp/fusion/responses/transaction.rb +36 -0
- data/lib/yelp/fusion/version.rb +25 -0
- data/yelp-fusion.gemspec +44 -0
- metadata +192 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (c) Jobcase, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module Yelp
|
22
|
+
module Fusion
|
23
|
+
class Configuration
|
24
|
+
attr_accessor :api_key
|
25
|
+
|
26
|
+
# Creates the configuration
|
27
|
+
# @param [config_api] String
|
28
|
+
# containing configuration parameter and its value
|
29
|
+
# @return [Configuration] a new configuration with the value from the
|
30
|
+
# config_api String
|
31
|
+
def initialize(config_api = nil)
|
32
|
+
return unless !config_api.nil? && config_api.is_a?(String)
|
33
|
+
self.api_key = config_api
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Copyright (c) Jobcase, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'erb'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
require 'yelp/fusion/responses/business'
|
25
|
+
|
26
|
+
module Yelp
|
27
|
+
module Fusion
|
28
|
+
module Endpoint
|
29
|
+
class Business
|
30
|
+
PATH = '/v3/businesses/'.freeze
|
31
|
+
|
32
|
+
def initialize(client)
|
33
|
+
@client = client
|
34
|
+
end
|
35
|
+
|
36
|
+
# Make a request to the business endpoint on the API
|
37
|
+
#
|
38
|
+
# @param id [String] the business id
|
39
|
+
# @param locale [Hash] a hash of supported locale-related parameters
|
40
|
+
# @return [Response::Business] the parsed response object from the API
|
41
|
+
#
|
42
|
+
# @example Get business
|
43
|
+
# business = client.business('yelp-san-francisco')
|
44
|
+
# business.name # => 'Yelp'
|
45
|
+
# buinesss.url # => 'http://www.yelp.com/biz/yelp-san-francisco'
|
46
|
+
def business(id, locale = {})
|
47
|
+
Responses::Business.new(JSON.parse(business_request(id, locale).body))
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# Make a request to the business endpoint of the API
|
53
|
+
# The endpoint requires a format of /v3/business/{business-id}
|
54
|
+
# so the primary request parameter is concatenated. After getting
|
55
|
+
# the response back it's checked to see if there are any API errors
|
56
|
+
# and raises the relevant one if there is
|
57
|
+
#
|
58
|
+
# @param id [String, Integer] the business id
|
59
|
+
# @param locale [Hash] a hash of supported locale-related parameters
|
60
|
+
# @return [Faraday::Response] the raw response back from the connection
|
61
|
+
def business_request(id, locale = {})
|
62
|
+
result = @client.connection.get (PATH +
|
63
|
+
ERB::Util.url_encode(id)), locale
|
64
|
+
Error.check_for_error(result)
|
65
|
+
result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Copyright (c) Jobcase, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'erb'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
require 'yelp/fusion/responses/business'
|
25
|
+
|
26
|
+
module Yelp
|
27
|
+
module Fusion
|
28
|
+
module Endpoint
|
29
|
+
class Match
|
30
|
+
PATH = '/v3/businesses/matches'.freeze
|
31
|
+
|
32
|
+
def initialize(client)
|
33
|
+
@client = client
|
34
|
+
end
|
35
|
+
|
36
|
+
# Make a request to the business endpoint on the API
|
37
|
+
#
|
38
|
+
# @param params [Hash] a hash of the required location parameters
|
39
|
+
# @return [Response::Match] a parsed object of the response.
|
40
|
+
# For a complete sample response visit:
|
41
|
+
# https://www.yelp.com/developers/documentation/v3/business_match
|
42
|
+
#
|
43
|
+
# @example Search for business with params
|
44
|
+
# params = { name: 'swissbakers', address1:
|
45
|
+
# '168 Western Ave', city: 'allston', state:
|
46
|
+
# 'MA', country: 'US' }
|
47
|
+
# response = client.mathc(params)
|
48
|
+
# response.businesses # [<Business 1>, <Business 2>, <Business 3>]
|
49
|
+
# response.businesses[0].name # 'Yelp'
|
50
|
+
def match(params = {})
|
51
|
+
Responses::Match.new(JSON.parse(match_request(params).body))
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def match_request(params = {})
|
57
|
+
result = @client.connection.get PATH, params
|
58
|
+
Error.check_for_error(result)
|
59
|
+
result
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Copyright (c) Jobcase, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'erb'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
require 'yelp/fusion/responses/phone'
|
25
|
+
|
26
|
+
module Yelp
|
27
|
+
module Fusion
|
28
|
+
module Endpoint
|
29
|
+
class Phone
|
30
|
+
PATH = '/v3/businesses/search/phone'.freeze
|
31
|
+
|
32
|
+
def initialize(client)
|
33
|
+
@client = client
|
34
|
+
end
|
35
|
+
|
36
|
+
# Make a request to the business endpoint on the API
|
37
|
+
#
|
38
|
+
# @param phone [String] the phone number
|
39
|
+
# @return [Response::Phone] a parsed object of the response.
|
40
|
+
# For a complete sample response visit:
|
41
|
+
# https://www.yelp.com/developers/documentation/v3/business_search_phone
|
42
|
+
#
|
43
|
+
# @example Search for business with params and locale
|
44
|
+
#
|
45
|
+
# response = client.phone_search('+14159083801')
|
46
|
+
# response.businesses # [<Business 1>, <Business 2>, <Business 3>]
|
47
|
+
# response.businesses[0].name # 'Yelp'
|
48
|
+
def phone_search(phone)
|
49
|
+
phone_hash = { phone: phone }
|
50
|
+
Responses::Phone.new(JSON.parse(phone_request(phone_hash).body))
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# Make a request to the business endpoint of the API
|
56
|
+
# The endpoint requires a format of /v3/business_search_phone
|
57
|
+
# so the primary request parameter is concatenated. After getting
|
58
|
+
# the response back it's checked to see if there are any API errors
|
59
|
+
# and raises the relevant one if there is.
|
60
|
+
#
|
61
|
+
# @param phone [String] the phone number
|
62
|
+
# @return [Faraday::Response] the raw response back from the connection
|
63
|
+
def phone_request(phone)
|
64
|
+
result = @client.connection.get PATH, phone
|
65
|
+
Error.check_for_error(result)
|
66
|
+
result
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Copyright (c) Jobcase, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'erb'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
require 'yelp/fusion/responses/review'
|
25
|
+
|
26
|
+
module Yelp
|
27
|
+
module Fusion
|
28
|
+
module Endpoint
|
29
|
+
class Review
|
30
|
+
PATH = '/v3/businesses/'.freeze
|
31
|
+
|
32
|
+
def initialize(client)
|
33
|
+
@client = client
|
34
|
+
end
|
35
|
+
|
36
|
+
# Make a request to the business endpoint on the API
|
37
|
+
#
|
38
|
+
# @param id [String] the business id
|
39
|
+
# @param locale [Hash] a hash of supported locale-related parameters
|
40
|
+
# @return [Response::Review] the parsed response object from the API
|
41
|
+
#
|
42
|
+
# @example Get Review
|
43
|
+
# id = 'xAG4O7l-t1ubbwVAlPnDKg'
|
44
|
+
# locale = { lang: 'fr' }
|
45
|
+
# response = client.review(id, locale)
|
46
|
+
# response.name # => 'Yelp'
|
47
|
+
# response.url # => 'http://www.yelp.com/biz/yelp-san-francisco'
|
48
|
+
def review(id, locale = {})
|
49
|
+
Responses::Review.new(JSON.parse(review_request(id, locale).body))
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Make a request to the review endpoint of the API
|
55
|
+
# The endpoint requires a format of v3/businesses/{id}/reviews
|
56
|
+
# so the primary request parameter is concatenated. After getting
|
57
|
+
# the response back it's checked to see if there are any API errors
|
58
|
+
# and raises the relevant one if there is.
|
59
|
+
#
|
60
|
+
# @param id [String] the business id
|
61
|
+
# @param locale [Hash] a hash of supported locale-related parameters
|
62
|
+
# @return [Faraday::Response] the raw response back from the connection
|
63
|
+
def review_request(id, locale = {})
|
64
|
+
result = @client.connection.get (PATH +
|
65
|
+
ERB::Util.url_encode(id) + '/reviews'), locale
|
66
|
+
Error.check_for_error(result)
|
67
|
+
result
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# Copyright (c) Jobcase, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'json'
|
22
|
+
require 'yelp/fusion/responses/search'
|
23
|
+
|
24
|
+
module Yelp
|
25
|
+
module Fusion
|
26
|
+
module Endpoint
|
27
|
+
class Search
|
28
|
+
PATH = '/v3/businesses/search'.freeze
|
29
|
+
def initialize(client)
|
30
|
+
@client = client
|
31
|
+
end
|
32
|
+
|
33
|
+
# Take a search_request and return the formatted/structured
|
34
|
+
# response from the API
|
35
|
+
#
|
36
|
+
# @param location [String] a string location of the neighborhood,
|
37
|
+
# address, or city
|
38
|
+
# @param params [Hash] a hash that corresponds to params on the API:
|
39
|
+
# https://www.yelp.com/developers/documentation/v3/business_search
|
40
|
+
# @return [Response::Search] a parsed object of the response.
|
41
|
+
# For a complete list of possible response values visit:
|
42
|
+
# https://www.yelp.com/developers/documentation/v3/business_search
|
43
|
+
#
|
44
|
+
# @example Search for business with params
|
45
|
+
# params = { term: 'food',
|
46
|
+
# limit: 3,
|
47
|
+
# category: 'discgolf' }
|
48
|
+
#
|
49
|
+
# response = client.search('San Francisco', params)
|
50
|
+
# response.businesses # [<Business 1>, <Business 2>, <Business 3>]
|
51
|
+
# response.businesses[0].name # 'Yelp'
|
52
|
+
def search(location, params = {})
|
53
|
+
params[:location] = location
|
54
|
+
|
55
|
+
Responses::Search.new(JSON.parse(search_request(params).body))
|
56
|
+
end
|
57
|
+
|
58
|
+
# Search by coordinates: give it a latitude and longitude along with
|
59
|
+
# option accuracy, altitude, and altitude_accuracy to search an area.
|
60
|
+
# More info at:
|
61
|
+
# https://www.yelp.com/developers/documentation/v3/business_search
|
62
|
+
#
|
63
|
+
# @param coordinates [Hash] a hash of latitude and longitude.
|
64
|
+
# @param params [Hash] a hash that corresponds to params on the API:
|
65
|
+
# https://www.yelp.com/developers/documentation/v3/business_search
|
66
|
+
# @return [Response::Search] a parsed object of the response.
|
67
|
+
# For a complete list of possible response values visit:
|
68
|
+
# https://www.yelp.com/developers/documentation/v3/business_search
|
69
|
+
#
|
70
|
+
# @example Search for business with params
|
71
|
+
# coordinates = { latitude: 37.786732,
|
72
|
+
# longitude: -122.399978 }
|
73
|
+
#
|
74
|
+
# params = { term: 'food',
|
75
|
+
# limit: 3,
|
76
|
+
# category: 'discgolf' }
|
77
|
+
#
|
78
|
+
# response = client.search(coordinates, params)
|
79
|
+
# response.businesses # [<Business 1>, <Business 2>, <Business 3>]
|
80
|
+
# response.businesses[0].name # 'Yelp'
|
81
|
+
def search_by_coordinates(coordinates, params = {})
|
82
|
+
raise Error::MissingLatLng if coordinates[:latitude].nil? ||
|
83
|
+
coordinates[:longitude].nil?
|
84
|
+
coordinates.merge!(params)
|
85
|
+
Responses::Search.new(JSON.parse(search_request(coordinates).body))
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
# Make a request against the search endpoint from the API and return the
|
91
|
+
# raw response. After getting the response back it's checked to see if
|
92
|
+
# there are any API errors and raises the relevant one if there is.
|
93
|
+
#
|
94
|
+
# @param params [Hash] a hash of parameters for the search request
|
95
|
+
# @return [Faraday::Response] the raw response back from the connection
|
96
|
+
def search_request(params)
|
97
|
+
result = @client.connection.get PATH, params
|
98
|
+
Yelp::Fusion::Error.check_for_error(result)
|
99
|
+
result
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# Copyright (c) Jobcase, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'erb'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
require 'yelp/fusion/responses/business'
|
25
|
+
|
26
|
+
module Yelp
|
27
|
+
module Fusion
|
28
|
+
module Endpoint
|
29
|
+
class Transaction
|
30
|
+
PATH = '/v3/transactions/'.freeze
|
31
|
+
|
32
|
+
def initialize(client)
|
33
|
+
@client = client
|
34
|
+
end
|
35
|
+
|
36
|
+
# Make a request to the business endpoint on the API
|
37
|
+
#
|
38
|
+
# @param id [String] the business id
|
39
|
+
# @param locale [Hash] a hash of supported locale-related parameters
|
40
|
+
# @return [Response::Review] the parsed response object from the API
|
41
|
+
#
|
42
|
+
# @example Get Transaction
|
43
|
+
# review = client.transaction('delivery', 'San Francisco')
|
44
|
+
# review.name # => 'Yelp'
|
45
|
+
# review.url # => 'http://www.yelp.com/biz/yelp-san-francisco'
|
46
|
+
def transaction_search(transaction_type, location)
|
47
|
+
result = transaction_request(transaction_type, location)
|
48
|
+
Responses::Transaction.new(JSON.parse(result.body))
|
49
|
+
end
|
50
|
+
|
51
|
+
# Search by coordinates: give it a latitude and longitude along with
|
52
|
+
# option accuracy, altitude, and altitude_accuracy to search an area.
|
53
|
+
# More info at
|
54
|
+
# https://www.yelp.com/developers/documentation/v3/transaction_search
|
55
|
+
#
|
56
|
+
# @param coordinates [Hash] a hash of latitude and longitude.
|
57
|
+
# @param params [Hash] a hash that corresponds to params on the API:
|
58
|
+
# https://www.yelp.com/developers/documentation/v3/transaction_search
|
59
|
+
# @return [Response::Search] a parsed object of the response.
|
60
|
+
# For a complete list of possible response values visit:
|
61
|
+
# https://www.yelp.com/developers/documentation/v3/transaction_search
|
62
|
+
#
|
63
|
+
# @example Search for business with params
|
64
|
+
# coordinates = { latitude: 37.786732,
|
65
|
+
# longitude: -122.399978 }
|
66
|
+
#
|
67
|
+
# response = client.search('delivery', coordinates)
|
68
|
+
# response.businesses # [<Business 1>, <Business 2>, <Business 3>]
|
69
|
+
# response.businesses[0].name # 'Yelp'
|
70
|
+
def transaction_by_coordinates(transaction_type, coordinates)
|
71
|
+
raise Error::MissingLatLng if coordinates[:latitude].nil? ||
|
72
|
+
coordinates[:longitude].nil?
|
73
|
+
result = transaction_request(transaction_type, coordinates)
|
74
|
+
Responses::Transaction.new(JSON.parse(result.body))
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# Make a request to the transaction endpoint of the API
|
80
|
+
# The endpoint requires a format of /v3/transaction_search
|
81
|
+
# so the primary request parameter is concatenated. After getting
|
82
|
+
# the response back it's checked to see if there are any API errors
|
83
|
+
# and raises the relevant one if there is.
|
84
|
+
#
|
85
|
+
# @param transaction_type [String] it has to be delivery
|
86
|
+
# @param location [Hash] a hash of supported location
|
87
|
+
# @return [Faraday::Response] the raw response back from the connection
|
88
|
+
def transaction_request(transaction_type, location)
|
89
|
+
result = @client.connection.get (PATH +
|
90
|
+
ERB::Util.url_encode(transaction_type) + '/search'), location
|
91
|
+
Error.check_for_error(result)
|
92
|
+
result
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|