yelp 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,23 @@
1
+ == YELP_20091019_1_0_0
2
+
3
+ * [shaper] allow specifying multiple categories for review search by
4
+ passing an array of the category names in the request.
5
+
6
+ * [shaper] fix tests to gracefully alert user if YWSID is not set in
7
+ their environment.
8
+
9
+ * [shaper] updated README to reflect the latest reality.
10
+
11
+ * [shaper] updated Rakefile to reflect latest hoe usage.
12
+
13
+ * [shaper] fixed test neighborhood search to reflect add'l info passed
14
+ along in yelp response.
15
+
16
+ * [shaper] fixed test json validation to reflect new version of 1.1.1.
17
+
18
+ * [shaper] fixed neighborhood test to suit new www.yelp.com return
19
+ url.
20
+
1
21
  == 0.2.1 / 2007-11-24
2
22
 
3
23
  * [shaper] fixed extra dependencies specified in Rakefile to allow for proper
data/Manifest.txt CHANGED
@@ -1,7 +1,7 @@
1
- History.txt
1
+ CHANGELOG.rdoc
2
2
  LICENSE.txt
3
3
  Manifest.txt
4
- README.txt
4
+ README.rdoc
5
5
  Rakefile
6
6
  TODO.txt
7
7
  lib/yelp.rb
@@ -12,6 +12,8 @@ More detailed information on the underlying Yelp API, error response codes, and
12
12
 
13
13
  The RubyForge project is hosted at http://rubyforge.org/projects/yelp. This documentation is available at http://yelp.rubyforge.org.
14
14
 
15
+ The latest source code is at http://github.com/shaper/yelp.
16
+
15
17
  == About
16
18
 
17
19
  Everybody loves Yelp! For those seeking burritos in the Mission District of
@@ -38,15 +40,15 @@ retrieved via their API, documented at http://www.yelp.com/developers/getting_st
38
40
  For tests to execute successfully you must have the YWSID set in your
39
41
  environment via (shell-dependent, bash example provided):
40
42
 
41
- % export YWSID='YOUR_ID_HERE'
43
+ % export YWSID='YOUR_ID_HERE'
42
44
 
43
45
  == Installing
44
46
 
45
- We recommend installing <tt>yelp</tt> via rubygems[http://rubyforge.org/projects/rubygems/] (see also http://www.rubygems.org).
47
+ Install +rubygems+ if you don't already have it. See http://rubyforge.org/projects/rubygems/.
46
48
 
47
- Once you have +rubygems+ installed on your system, you can easily install the <tt>yelp</tt> gem by executing:
49
+ Then install the +yelp+ gem by executing:
48
50
 
49
- % gem install --include-dependencies yelp
51
+ % gem install yelp
50
52
 
51
53
  == Usage
52
54
 
@@ -70,31 +72,39 @@ types.
70
72
 
71
73
  A few examples:
72
74
 
73
- # construct a client instance
74
- client = Yelp::Client.new
75
-
76
- # perform an address/location-based search for cream puffs nearby
77
- request = Yelp::Review::Request::Location.new(
78
- :address => '650 Mission St',
79
- :city => 'San Francisco',
80
- :state => 'CA',
81
- :radius => 2,
82
- :term => 'cream puffs',
83
- :yws_id => 'YOUR_YWSID_HERE')
84
- response = client.search(request)
85
-
86
- # perform a neighborhood name lookup for a specific geo-location point
87
- request = Yelp::Neighborhood::Request::GeoPoint.new(
88
- :latitude => 37.782093,
89
- :longitude => -122.483230,
90
- :yws_id => 'YOUR_YWSID_HERE')
91
- response = client.search(request)
92
-
93
- # perform a business review search based on a business phone number
94
- request = Yelp::Phone::Request::Number.new(
95
- :phone_number => '4155551212',
96
- :yws_id => 'YOUR_YWSID_HERE')
97
- response = client.search(request)
75
+ # construct a client instance
76
+ client = Yelp::Client.new
77
+
78
+ # perform an address/location-based search for cream puffs nearby
79
+ request = Yelp::Review::Request::Location.new(
80
+ :address => '650 Mission St',
81
+ :city => 'San Francisco',
82
+ :state => 'CA',
83
+ :radius => 2,
84
+ :term => 'cream puffs',
85
+ :yws_id => 'YOUR_YWSID_HERE')
86
+ response = client.search(request)
87
+
88
+ # perform a location-based category search for either ice cream or donut shops in SF
89
+ request = Yelp::Review::Request::Location.new(
90
+ :city => 'San Francisco',
91
+ :state => 'CA',
92
+ :category => [ 'donuts', 'icecream' ],
93
+ :yws_id => 'YOUR_YWSID_HERE')
94
+ response = client.search(request)
95
+
96
+ # perform a neighborhood name lookup for a specific geo-location point
97
+ request = Yelp::Neighborhood::Request::GeoPoint.new(
98
+ :latitude => 37.782093,
99
+ :longitude => -122.483230,
100
+ :yws_id => 'YOUR_YWSID_HERE')
101
+ response = client.search(request)
102
+
103
+ # perform a business review search based on a business phone number
104
+ request = Yelp::Phone::Request::Number.new(
105
+ :phone_number => '4155551212',
106
+ :yws_id => 'YOUR_YWSID_HERE')
107
+ response = client.search(request)
98
108
 
99
109
  If you want to convert some addresses to latitude/longitude, or vice
100
110
  versa, for testing or what have you -- try http://stevemorse.org/jcal/latlon.php.
@@ -105,4 +115,4 @@ This library is provided via the GNU LGPL license at http://www.gnu.org/licenses
105
115
 
106
116
  == Authors
107
117
 
108
- Copyright 2007, Walter Korman <shaper@wgks.org>, http://lemurware.blogspot.com
118
+ Copyright 2007 - 2009, Walter Korman <shaper@fatgoose.com>, http://lemurware.blogspot.com
data/Rakefile CHANGED
@@ -3,14 +3,23 @@ require 'hoe'
3
3
  $:.unshift(File.dirname(__FILE__) + "/lib")
4
4
  require 'yelp'
5
5
 
6
- Hoe.new('yelp', Yelp::VERSION) do |p|
7
- p.rubyforge_name = 'yelp'
8
- p.author = 'Walter Korman'
9
- p.email = 'shaper@wgks.org'
10
- p.extra_deps << [ 'json', '>= 1.1.1' ]
11
- p.summary = 'An object-oriented interface to the Yelp Developer API.'
12
- p.description = 'An object-oriented interface to the Yelp Developer API.'
13
- p.url = 'http://rubyforge.org/projects/yelp'
14
- p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
15
- p.remote_rdoc_dir = '' # Release to root
6
+ Hoe.spec('yelp') do |p|
7
+ self.version = Yelp::VERSION
8
+ self.rubyforge_name = 'yelp'
9
+ self.author = 'Walter Korman'
10
+ self.email = 'shaper@fatgoose.com'
11
+ self.extra_deps << [ 'json', '>= 1.1.1' ]
12
+ self.summary = 'An object-oriented interface to the Yelp Developer API.'
13
+ self.description = <<EDOC
14
+ The yelp rubygem provides a Ruby object-oriented interface to the Yelp
15
+ REST API described in detail at:
16
+
17
+ http://www.yelp.com/developers/getting_started
18
+ EDOC
19
+ self.url = 'http://rubyforge.org/projects/yelp'
20
+ self.changes = p.paragraphs_of('CHANGELOG.rdoc', 0..1).join("\n\n")
21
+ self.remote_rdoc_dir = '' # Release to root
22
+ self.readme_file = 'README.rdoc'
23
+ self.history_file = 'CHANGELOG.rdoc'
24
+ self.extra_rdoc_files = [ 'CHANGELOG.rdoc', 'README.rdoc' ]
16
25
  end
data/lib/yelp/client.rb CHANGED
@@ -94,7 +94,9 @@ class Yelp
94
94
  params.each do |key, value|
95
95
  next if value.nil?
96
96
  url << '&' if (param_count > 0)
97
- url << "#{key}=#{CGI.escape(params[key].to_s)}"
97
+ key_str = (params[key].kind_of?(Array)) ?
98
+ params[key].map { |k| CGI.escape(k.to_s) }.join("+") : CGI.escape(params[key].to_s)
99
+ url << "#{CGI.escape(key.to_s)}=#{key_str}"
98
100
  param_count += 1
99
101
  end
100
102
  url
@@ -12,7 +12,8 @@ class Yelp
12
12
  # requested.
13
13
  attr_reader :term
14
14
 
15
- # optionally narrow the results by a category
15
+ # optionally narrow the results by one or more categories.
16
+ # may be a single string value, or an Array of multiple values.
16
17
  attr_reader :category
17
18
 
18
19
  def base_url
data/lib/yelp.rb CHANGED
@@ -12,5 +12,5 @@ require 'yelp/review/request/geo_point'
12
12
  require 'yelp/review/request/location'
13
13
 
14
14
  class Yelp
15
- VERSION = '0.2.1'
15
+ VERSION = '1.0.0'
16
16
  end
@@ -1,4 +1,3 @@
1
- require 'pp'
2
1
  require 'rubygems'
3
2
  require 'test/unit'
4
3
  require 'yelp'
@@ -8,14 +7,20 @@ class TestNeighborhoodSearch < Test::Unit::TestCase
8
7
  include YelpHelper
9
8
 
10
9
  def setup
11
- @client = Yelp::Client.new
12
- @yws_id = ENV['YWSID']
13
- # @client.debug = true
10
+ create_client
14
11
  end
15
12
 
16
13
  GORDO_LAT = 37.782093
17
14
  GORDO_LON = -122.483230
18
- GORDO_NEIGHBORHOOD = { "city" => "San Francisco", "name" => "Outer Richmond", "url" => "http://yelp.com/search?find_loc=Outer+Richmond%2C+San+Francisco%2C+CA", "state" => "CA" }
15
+ GORDO_NEIGHBORHOOD = {
16
+ "city" => "San Francisco",
17
+ "name" => "Outer Richmond",
18
+ "country_code" => "US",
19
+ "country" => "USA",
20
+ "borough" => "",
21
+ "url" => "http://www.yelp.com/search?find_loc=Outer+Richmond%2C+San+Francisco%2C+CA%2C+USA",
22
+ "state" => "CA",
23
+ "state_code" => "CA" }
19
24
 
20
25
  def test_geo_point_search
21
26
  request = Yelp::Neighborhood::Request::GeoPoint.new(:latitude => GORDO_LAT,
@@ -1,4 +1,3 @@
1
- require 'pp'
2
1
  require 'rubygems'
3
2
  require 'test/unit'
4
3
  require 'yelp'
@@ -8,9 +7,7 @@ class TestPhoneSearch < Test::Unit::TestCase
8
7
  include YelpHelper
9
8
 
10
9
  def setup
11
- @client = Yelp::Client.new
12
- @yws_id = ENV['YWSID']
13
- # @client.debug = true
10
+ create_client
14
11
  end
15
12
 
16
13
  GORDO_PHONE_NUMBER = '4155666011'
@@ -1,4 +1,3 @@
1
- require 'pp'
2
1
  require 'rubygems'
3
2
  require 'test/unit'
4
3
  require 'yelp'
@@ -8,9 +7,7 @@ class TestReviewSearch < Test::Unit::TestCase
8
7
  include YelpHelper
9
8
 
10
9
  def setup
11
- @client = Yelp::Client.new
12
- @yws_id = ENV['YWSID']
13
- # @client.debug = true
10
+ create_client
14
11
  end
15
12
 
16
13
  def test_bounding_box
@@ -71,7 +68,6 @@ class TestReviewSearch < Test::Unit::TestCase
71
68
  :category => 'playgrounds',
72
69
  :yws_id => @yws_id)
73
70
  narrowed_response = @client.search(narrowed_request)
74
- pp narrowed_response
75
71
 
76
72
  # make sure we got less for the second
77
73
  assert(response['businesses'].length > narrowed_response['businesses'].length)
@@ -113,6 +109,51 @@ class TestReviewSearch < Test::Unit::TestCase
113
109
  validate_json_to_ruby_response(response)
114
110
  end
115
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
+
116
157
  protected
117
158
 
118
159
  def basic_request (params = nil)
data/test/yelp_helper.rb CHANGED
@@ -1,8 +1,18 @@
1
+ require 'pp'
2
+
1
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
+
2
12
  def validate_json_response (response)
3
13
  assert_not_nil response
4
14
  assert_instance_of String, response
5
- assert_match(/^\{"message": \{"text": "OK", "code": 0, "version": 1\.1\}, "(businesses|neighborhoods)": .*?\}$/, response)
15
+ assert_match(/^\{"message": \{"text": "OK", "code": 0, "version": "1\.1\.1"\}, "(businesses|neighborhoods)": .*?\}$/, response)
6
16
  end
7
17
 
8
18
  def validate_json_to_ruby_response (response)
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yelp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
5
- platform: ""
4
+ version: 1.0.0
5
+ platform: ruby
6
6
  authors:
7
7
  - Walter Korman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-11-24 00:00:00 -08:00
12
+ date: 2009-10-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,30 +24,36 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: hoe
27
+ type: :development
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
29
31
  - - ">="
30
32
  - !ruby/object:Gem::Version
31
- version: 1.3.0
33
+ version: 2.3.3
32
34
  version:
33
- description: An object-oriented interface to the Yelp Developer API.
34
- email: shaper@wgks.org
35
+ description: |
36
+ The yelp rubygem provides a Ruby object-oriented interface to the Yelp
37
+ REST API described in detail at:
38
+
39
+ http://www.yelp.com/developers/getting_started
40
+
41
+ email: shaper@fatgoose.com
35
42
  executables: []
36
43
 
37
44
  extensions: []
38
45
 
39
46
  extra_rdoc_files:
40
- - History.txt
41
47
  - LICENSE.txt
42
48
  - Manifest.txt
43
- - README.txt
44
49
  - TODO.txt
50
+ - CHANGELOG.rdoc
51
+ - README.rdoc
45
52
  files:
46
- - History.txt
53
+ - CHANGELOG.rdoc
47
54
  - LICENSE.txt
48
55
  - Manifest.txt
49
- - README.txt
56
+ - README.rdoc
50
57
  - Rakefile
51
58
  - TODO.txt
52
59
  - lib/yelp.rb
@@ -69,10 +76,12 @@ files:
69
76
  - test/yelp_helper.rb
70
77
  has_rdoc: true
71
78
  homepage: http://rubyforge.org/projects/yelp
79
+ licenses: []
80
+
72
81
  post_install_message:
73
82
  rdoc_options:
74
83
  - --main
75
- - README.txt
84
+ - README.rdoc
76
85
  require_paths:
77
86
  - lib
78
87
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -90,9 +99,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
99
  requirements: []
91
100
 
92
101
  rubyforge_project: yelp
93
- rubygems_version: 0.9.5
102
+ rubygems_version: 1.3.5
94
103
  signing_key:
95
- specification_version: 2
104
+ specification_version: 3
96
105
  summary: An object-oriented interface to the Yelp Developer API.
97
106
  test_files:
98
107
  - test/test_client.rb