yelp 1.0.0 → 2.0.0
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 +18 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -504
- data/README.md +152 -0
- data/Rakefile +4 -24
- data/lib/yelp.rb +18 -13
- data/lib/yelp/burst_struct.rb +51 -0
- data/lib/yelp/client.rb +86 -86
- data/lib/yelp/configuration.rb +31 -0
- data/lib/yelp/endpoint/business.rb +42 -0
- data/lib/yelp/endpoint/search.rb +170 -0
- data/lib/yelp/error.rb +55 -0
- data/lib/yelp/version.rb +3 -0
- data/spec/fixtures/vcr_cassettes/business.yml +73 -0
- data/spec/fixtures/vcr_cassettes/search.yml +361 -0
- data/spec/fixtures/vcr_cassettes/search_bounding_box.yml +359 -0
- data/spec/fixtures/vcr_cassettes/search_by_coordinates.yml +387 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/request_error.rb +11 -0
- data/spec/support/shared_configuration.rb +11 -0
- data/spec/yelp/burst_struct_spec.rb +124 -0
- data/spec/yelp/client_spec.rb +75 -0
- data/spec/yelp/configuration_spec.rb +44 -0
- data/spec/yelp/endpoint/business_spec.rb +26 -0
- data/spec/yelp/endpoint/search_spec.rb +72 -0
- data/spec/yelp/error_spec.rb +22 -0
- data/spec/yelp/yelp_spec.rb +10 -0
- data/tasks/console.rake +4 -0
- data/yelp.gemspec +32 -0
- metadata +252 -90
- data/CHANGELOG.rdoc +0 -48
- data/Manifest.txt +0 -24
- data/README.rdoc +0 -118
- data/TODO.txt +0 -6
- data/lib/yelp/neighborhood/request/base.rb +0 -13
- data/lib/yelp/neighborhood/request/geo_point.rb +0 -23
- data/lib/yelp/neighborhood/request/location.rb +0 -53
- data/lib/yelp/phone/request/number.rb +0 -24
- data/lib/yelp/record.rb +0 -16
- data/lib/yelp/request.rb +0 -44
- data/lib/yelp/response_format.rb +0 -36
- data/lib/yelp/review/request/base.rb +0 -31
- data/lib/yelp/review/request/bounding_box.rb +0 -37
- data/lib/yelp/review/request/geo_point.rb +0 -28
- data/lib/yelp/review/request/location.rb +0 -63
- data/test/test_client.rb +0 -11
- data/test/test_neighborhood_search.rb +0 -46
- data/test/test_phone_search.rb +0 -20
- data/test/test_review_search.rb +0 -168
- data/test/yelp_helper.rb +0 -45
data/test/test_phone_search.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'yelp'
|
4
|
-
require File.dirname(__FILE__) + '/yelp_helper'
|
5
|
-
|
6
|
-
class TestPhoneSearch < Test::Unit::TestCase
|
7
|
-
include YelpHelper
|
8
|
-
|
9
|
-
def setup
|
10
|
-
create_client
|
11
|
-
end
|
12
|
-
|
13
|
-
GORDO_PHONE_NUMBER = '4155666011'
|
14
|
-
|
15
|
-
def test_phone_search
|
16
|
-
request = Yelp::Phone::Request::Number.new(:phone_number => GORDO_PHONE_NUMBER, :yws_id => @yws_id)
|
17
|
-
response = @client.search(request)
|
18
|
-
validate_json_to_ruby_response(response)
|
19
|
-
end
|
20
|
-
end
|
data/test/test_review_search.rb
DELETED
@@ -1,168 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'yelp'
|
4
|
-
require File.dirname(__FILE__) + '/yelp_helper'
|
5
|
-
|
6
|
-
class TestReviewSearch < Test::Unit::TestCase
|
7
|
-
include YelpHelper
|
8
|
-
|
9
|
-
def setup
|
10
|
-
create_client
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_bounding_box
|
14
|
-
request = Yelp::Review::Request::BoundingBox.new(
|
15
|
-
:bottom_right_latitude => 37.788022,
|
16
|
-
:bottom_right_longitude => -122.399797,
|
17
|
-
:top_left_latitude => 37.9,
|
18
|
-
:top_left_longitude => -122.5,
|
19
|
-
# :radius => 1,
|
20
|
-
# :business_count => 3,
|
21
|
-
:term => 'yelp',
|
22
|
-
:yws_id => @yws_id)
|
23
|
-
response = @client.search(request)
|
24
|
-
validate_json_to_ruby_response(response)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_geo_point
|
28
|
-
request = Yelp::Review::Request::GeoPoint.new(
|
29
|
-
:latitude => 37.78022,
|
30
|
-
:longitude => -122.399797,
|
31
|
-
:radius => 2,
|
32
|
-
# :business_count => 5,
|
33
|
-
:term => 'yelp',
|
34
|
-
:yws_id => @yws_id)
|
35
|
-
response = @client.search(request)
|
36
|
-
validate_json_to_ruby_response(response)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_location
|
40
|
-
request = Yelp::Review::Request::Location.new(
|
41
|
-
:address => '650 Mission St',
|
42
|
-
:city => 'San Francisco',
|
43
|
-
:state => 'CA',
|
44
|
-
:radius => 2,
|
45
|
-
# :business_count => 5,
|
46
|
-
:term => 'cream puffs',
|
47
|
-
:yws_id => @yws_id)
|
48
|
-
response = @client.search(request)
|
49
|
-
validate_json_to_ruby_response(response)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_category
|
53
|
-
# perform a basic search of businesses near SOMA
|
54
|
-
request = Yelp::Review::Request::GeoPoint.new(
|
55
|
-
:latitude => 37.78022,
|
56
|
-
:longitude => -122.399797,
|
57
|
-
:radius => 5,
|
58
|
-
:term => 'yelp',
|
59
|
-
:yws_id => @yws_id)
|
60
|
-
response = @client.search(request)
|
61
|
-
|
62
|
-
# perform the same search focusing only on playgrounds
|
63
|
-
narrowed_request = Yelp::Review::Request::GeoPoint.new(
|
64
|
-
:latitude => 37.78022,
|
65
|
-
:longitude => -122.399797,
|
66
|
-
:radius => 5,
|
67
|
-
:term => 'yelp',
|
68
|
-
:category => 'playgrounds',
|
69
|
-
:yws_id => @yws_id)
|
70
|
-
narrowed_response = @client.search(narrowed_request)
|
71
|
-
|
72
|
-
# make sure we got less for the second
|
73
|
-
assert(response['businesses'].length > narrowed_response['businesses'].length)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_json_response_format
|
77
|
-
request = basic_request(:response_format => Yelp::ResponseFormat::JSON)
|
78
|
-
response = @client.search(request)
|
79
|
-
validate_json_response(response)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_json_to_ruby_response_format
|
83
|
-
request = basic_request(:response_format => Yelp::ResponseFormat::JSON_TO_RUBY)
|
84
|
-
response = @client.search(request)
|
85
|
-
validate_json_to_ruby_response(response)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_pickle_response_format
|
89
|
-
request = basic_request(:response_format => Yelp::ResponseFormat::PICKLE)
|
90
|
-
@client.search(request)
|
91
|
-
# TODO: validation
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_php_response_format
|
95
|
-
request = basic_request(:response_format => Yelp::ResponseFormat::PHP)
|
96
|
-
response = @client.search(request)
|
97
|
-
# TODO: validation
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_compressed_response
|
101
|
-
request = basic_request(:compress_response => true)
|
102
|
-
response = @client.search(request)
|
103
|
-
validate_json_to_ruby_response(response)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_uncompressed_response
|
107
|
-
request = basic_request(:compress_response => false)
|
108
|
-
response = @client.search(request)
|
109
|
-
validate_json_to_ruby_response(response)
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_multiple_categories
|
113
|
-
# fetch results for only one category
|
114
|
-
params = {
|
115
|
-
:city => 'San Francisco',
|
116
|
-
:state => 'CA',
|
117
|
-
:yws_id => @yws_id,
|
118
|
-
:category => 'donuts'
|
119
|
-
}
|
120
|
-
request = Yelp::Review::Request::Location.new(params)
|
121
|
-
response = @client.search(request)
|
122
|
-
|
123
|
-
# make sure the overall request looks kosher
|
124
|
-
validate_json_to_ruby_response(response)
|
125
|
-
|
126
|
-
# make sure all businesses returned have at least the specified category
|
127
|
-
response['businesses'].each do |b|
|
128
|
-
cat_exists = b['categories'].find { |c| c['category_filter'] == 'donuts' }
|
129
|
-
assert_not_nil(cat_exists)
|
130
|
-
end
|
131
|
-
|
132
|
-
# now fetch for businesses with two categories
|
133
|
-
params[:category] = [ 'donuts', 'icecream' ]
|
134
|
-
request = Yelp::Review::Request::Location.new(params)
|
135
|
-
response = @client.search(request)
|
136
|
-
|
137
|
-
# make sure the overall request looks kosher
|
138
|
-
validate_json_to_ruby_response(response)
|
139
|
-
|
140
|
-
# make sure we have at least one of each specified category, and
|
141
|
-
# that each business has at least one
|
142
|
-
donut_count = 0
|
143
|
-
icecream_count = 0
|
144
|
-
response['businesses'].each do |b|
|
145
|
-
has_donut = b['categories'].find { |c| c['category_filter'] == 'donuts' }
|
146
|
-
has_icecream = b['categories'].find { |c| c['category_filter'] == 'icecream' }
|
147
|
-
|
148
|
-
donut_count += 1 if has_donut
|
149
|
-
icecream_count += 1 if has_icecream
|
150
|
-
|
151
|
-
assert(has_donut || has_icecream)
|
152
|
-
end
|
153
|
-
|
154
|
-
assert((donut_count > 0) && (icecream_count > 0))
|
155
|
-
end
|
156
|
-
|
157
|
-
protected
|
158
|
-
|
159
|
-
def basic_request (params = nil)
|
160
|
-
default_params = {
|
161
|
-
:city => 'San Francisco',
|
162
|
-
:state => 'CA',
|
163
|
-
:term => 'gordo',
|
164
|
-
:yws_id => @yws_id
|
165
|
-
}
|
166
|
-
Yelp::Review::Request::Location.new(default_params.merge(params))
|
167
|
-
end
|
168
|
-
end
|
data/test/yelp_helper.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
|
-
module YelpHelper
|
4
|
-
def create_client
|
5
|
-
@client = Yelp::Client.new
|
6
|
-
assert_not_nil(ENV['YWSID'], "Missing YWSID. Obtain from http://www.yelp.com/developer and " +
|
7
|
-
"set in your shell environment under 'YWSID'.")
|
8
|
-
@yws_id = ENV['YWSID']
|
9
|
-
# @client.debug = true
|
10
|
-
end
|
11
|
-
|
12
|
-
def validate_json_response (response)
|
13
|
-
assert_not_nil response
|
14
|
-
assert_instance_of String, response
|
15
|
-
assert_match(/^\{"message": \{"text": "OK", "code": 0, "version": "1\.1\.1"\}, "(businesses|neighborhoods)": .*?\}$/, response)
|
16
|
-
end
|
17
|
-
|
18
|
-
def validate_json_to_ruby_response (response)
|
19
|
-
assert_not_nil response
|
20
|
-
assert_instance_of Hash, response
|
21
|
-
assert_not_nil response['message']
|
22
|
-
assert(response['message']['code'] == 0)
|
23
|
-
assert(response['message']['text'] == 'OK')
|
24
|
-
assert_not_nil((response['businesses'] || response['neighborhoods']))
|
25
|
-
if response['businesses']
|
26
|
-
response['businesses'].each { |b| validate_json_to_ruby_business(b) }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
YELP_BIZ_ID_LENGTH = 22
|
31
|
-
|
32
|
-
def validate_json_to_ruby_business (business)
|
33
|
-
# rudimentary checks to make sure it looks like a typical yelp business
|
34
|
-
# result converted to a ruby hash
|
35
|
-
assert business['id'].length == YELP_BIZ_ID_LENGTH
|
36
|
-
assert_valid_url business['url']
|
37
|
-
end
|
38
|
-
|
39
|
-
# just a rudimentary check will serve us fine
|
40
|
-
VALID_URL_REGEXP = /^https?:\/\/[a-z0-9]/i
|
41
|
-
|
42
|
-
def assert_valid_url (url)
|
43
|
-
assert_match VALID_URL_REGEXP, url
|
44
|
-
end
|
45
|
-
end
|