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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE.txt +22 -504
  5. data/README.md +152 -0
  6. data/Rakefile +4 -24
  7. data/lib/yelp.rb +18 -13
  8. data/lib/yelp/burst_struct.rb +51 -0
  9. data/lib/yelp/client.rb +86 -86
  10. data/lib/yelp/configuration.rb +31 -0
  11. data/lib/yelp/endpoint/business.rb +42 -0
  12. data/lib/yelp/endpoint/search.rb +170 -0
  13. data/lib/yelp/error.rb +55 -0
  14. data/lib/yelp/version.rb +3 -0
  15. data/spec/fixtures/vcr_cassettes/business.yml +73 -0
  16. data/spec/fixtures/vcr_cassettes/search.yml +361 -0
  17. data/spec/fixtures/vcr_cassettes/search_bounding_box.yml +359 -0
  18. data/spec/fixtures/vcr_cassettes/search_by_coordinates.yml +387 -0
  19. data/spec/spec_helper.rb +14 -0
  20. data/spec/support/request_error.rb +11 -0
  21. data/spec/support/shared_configuration.rb +11 -0
  22. data/spec/yelp/burst_struct_spec.rb +124 -0
  23. data/spec/yelp/client_spec.rb +75 -0
  24. data/spec/yelp/configuration_spec.rb +44 -0
  25. data/spec/yelp/endpoint/business_spec.rb +26 -0
  26. data/spec/yelp/endpoint/search_spec.rb +72 -0
  27. data/spec/yelp/error_spec.rb +22 -0
  28. data/spec/yelp/yelp_spec.rb +10 -0
  29. data/tasks/console.rake +4 -0
  30. data/yelp.gemspec +32 -0
  31. metadata +252 -90
  32. data/CHANGELOG.rdoc +0 -48
  33. data/Manifest.txt +0 -24
  34. data/README.rdoc +0 -118
  35. data/TODO.txt +0 -6
  36. data/lib/yelp/neighborhood/request/base.rb +0 -13
  37. data/lib/yelp/neighborhood/request/geo_point.rb +0 -23
  38. data/lib/yelp/neighborhood/request/location.rb +0 -53
  39. data/lib/yelp/phone/request/number.rb +0 -24
  40. data/lib/yelp/record.rb +0 -16
  41. data/lib/yelp/request.rb +0 -44
  42. data/lib/yelp/response_format.rb +0 -36
  43. data/lib/yelp/review/request/base.rb +0 -31
  44. data/lib/yelp/review/request/bounding_box.rb +0 -37
  45. data/lib/yelp/review/request/geo_point.rb +0 -28
  46. data/lib/yelp/review/request/location.rb +0 -63
  47. data/test/test_client.rb +0 -11
  48. data/test/test_neighborhood_search.rb +0 -46
  49. data/test/test_phone_search.rb +0 -20
  50. data/test/test_review_search.rb +0 -168
  51. data/test/yelp_helper.rb +0 -45
data/TODO.txt DELETED
@@ -1,6 +0,0 @@
1
- * look into rails partials inability to properly enumerate the response
2
- business records with the :collection param.
3
- * think about how to gracefully report errors
4
- * should we use "require 'json/add/rails'" for json for rails happiness?
5
- * use SAX-based XML parsing rather than DOM
6
- * consider supporting keep-alive for high volume requests
@@ -1,13 +0,0 @@
1
- require 'yelp/request'
2
-
3
- class Yelp
4
- module Neighborhood
5
- module Request
6
- class Base < Yelp::Request
7
- def base_url
8
- 'http://api.yelp.com/neighborhood_search'
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,23 +0,0 @@
1
- require 'yelp/neighborhood/request/base'
2
-
3
- class Yelp
4
- module Neighborhood
5
- module Request
6
- # Describes a request to search for the name of a neighborhood at a
7
- # specific geo-point location.
8
- #
9
- class GeoPoint < Yelp::Neighborhood::Request::Base
10
- # latitude of geo-point for which a neighborhood name is desired
11
- attr_reader :latitude
12
-
13
- # longitude of geo-point for which a neighborhood name is desired
14
- attr_reader :longitude
15
-
16
- def to_yelp_params
17
- super.merge(:lat => latitude,
18
- :long => longitude)
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,53 +0,0 @@
1
- require 'yelp/neighborhood/request/base'
2
-
3
- class Yelp
4
- module Neighborhood
5
- module Request
6
- # Describes a request to search for a neighborhood name for a specific
7
- # address/location. You do not need to specify all of the address
8
- # attributes -- some subset of the core +address+, +city+,
9
- # +state+ and +zipcode+ will suffice.
10
- #
11
- class Location < Yelp::Neighborhood::Request::Base
12
- # the street address of the location sought
13
- attr_reader :address
14
-
15
- # the city of the location sought
16
- attr_reader :city
17
-
18
- # the state of the location sought
19
- attr_reader :state
20
-
21
- # the zipcode of the location sought
22
- attr_reader :zipcode
23
-
24
- def initialize (params)
25
- # we explicitly initialize the location fields since we reference
26
- # them later when building a full location string and we want
27
- # to know they were initialized properly (and avoid warnings)
28
- super({
29
- :address => nil,
30
- :city => nil,
31
- :state => nil,
32
- :zipcode => nil
33
- }.merge(params))
34
- end
35
-
36
- def to_yelp_params
37
- super.merge(:location => build_location_string)
38
- end
39
-
40
- protected
41
-
42
- # Returns the Yelp-compatible concatenated string with the various
43
- # possible bits of an address-oriented location.
44
- #
45
- def build_location_string
46
- # per the Yelp documentation, the location string is to be built
47
- # as some combination of "address, city, state, or zip".
48
- [ @address, @city, @state, @zipcode ].compact.join(" ")
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,24 +0,0 @@
1
- require 'yelp/request'
2
-
3
- class Yelp
4
- module Phone
5
- module Request
6
- # Describes a request to search for a business review for the business
7
- # associated with a specific phone number.
8
- #
9
- class Number < Yelp::Request
10
- # the phone number of the business to search for, formatted as
11
- # '1112223333'. Make sure you don't have any hyphens or parentheses.
12
- attr_reader :phone_number
13
-
14
- def base_url
15
- 'http://api.yelp.com/phone_search'
16
- end
17
-
18
- def to_yelp_params
19
- super.merge(:phone => phone_number)
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,16 +0,0 @@
1
- class Yelp
2
- # General-purpose record that allows passing a hash with parameters
3
- # to populate object attributes defined via methods like
4
- # +attr_reader+ or +attr_accessor+.
5
- #
6
- class Record
7
- def initialize (params)
8
- if !params.nil?
9
- params.each do |key, value|
10
- name = key.to_s
11
- instance_variable_set("@#{name}", value) if respond_to?(name)
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,44 +0,0 @@
1
- require 'yelp/record'
2
-
3
- class Yelp
4
- class Request < Yelp::Record
5
- # specifies whether the response content should be transmitted
6
- # over the wire compressed, defaulting to true.
7
- attr_reader :compress_response
8
-
9
- # one of the Yelp::ResponseFormat format specifiers detailing the
10
- # desired format of the search results, defaulting to
11
- # Yelp::ResponseFormat::JSON_TO_RUBY.
12
- attr_reader :response_format
13
-
14
- # the Yelp Web Services ID to be passed with the request for
15
- # authentication purposes. See http://www.yelp.com/developers/getting_started/api_access
16
- # to get your own.
17
- attr_reader :yws_id
18
-
19
- alias :compress_response? :compress_response
20
-
21
- def initialize (params)
22
- default_params = {
23
- :compress_response => true,
24
- :response_format => Yelp::ResponseFormat::JSON_TO_RUBY
25
- }
26
- super(default_params.merge(params))
27
- end
28
-
29
- def to_yelp_params
30
- params = {
31
- :ywsid => yws_id
32
- }
33
-
34
- # if they specified anything other than a json variant, we
35
- # need to tell yelp what we're looking for
36
- case @response_format
37
- when Yelp::ResponseFormat::PICKLE: params[:output] = 'pickle'
38
- when Yelp::ResponseFormat::PHP: params[:output] = 'php'
39
- end
40
-
41
- params
42
- end
43
- end
44
- end
@@ -1,36 +0,0 @@
1
- require 'yelp/record'
2
-
3
- class Yelp
4
- # Describes the available response formats when querying the Yelp web
5
- # service for results.
6
- #
7
- class ResponseFormat < Record
8
- # the name of the response format
9
- attr_reader :name
10
-
11
- # whether this response format returns serialized data (and, so, data that
12
- # we probably don't want to print to a log file and suchlike)
13
- attr_reader :serialized
14
-
15
- # the format specifier to retrieve results as straight JSON content
16
- JSON = Yelp::ResponseFormat.new(:name => 'json')
17
-
18
- # the format specifier to retrieve results as Ruby objects converted
19
- # from the returned JSON content via the +json+ rubygem.
20
- JSON_TO_RUBY = Yelp::ResponseFormat.new(:name => 'json_to_ruby')
21
-
22
- # the format specifier to retrieve results as a serialized Python
23
- # response. We're not quite sure why you'd want to use this if
24
- # you're calling it from Ruby code, but we like to see completeness
25
- # in an API.
26
- PICKLE = Yelp::ResponseFormat.new(:name => 'pickle', :serialized => true)
27
-
28
- # the format specifier to retrieve results as a serialized PHP
29
- # response. We're not quite sure why you'd want to use this if
30
- # you're calling it from Ruby code, but we like to see completeness
31
- # in an API.
32
- PHP = Yelp::ResponseFormat.new(:name => 'php', :serialized => true)
33
-
34
- alias :serialized? :serialized
35
- end
36
- end
@@ -1,31 +0,0 @@
1
- require 'yelp/request'
2
-
3
- class Yelp
4
- module Review
5
- module Request
6
- class Base < Yelp::Request
7
- # specifies the number of businesses to return in the result set.
8
- # default is 10. minimum value is 1 and maximum value is 20.
9
- attr_reader :business_count
10
-
11
- # string representing the name of business or search term being
12
- # requested.
13
- attr_reader :term
14
-
15
- # optionally narrow the results by one or more categories.
16
- # may be a single string value, or an Array of multiple values.
17
- attr_reader :category
18
-
19
- def base_url
20
- 'http://api.yelp.com/business_review_search'
21
- end
22
-
23
- def to_yelp_params
24
- super.merge(:term => term,
25
- :num_biz_requested => business_count,
26
- :category => category)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,37 +0,0 @@
1
- require 'yelp/review/request/base'
2
-
3
- class Yelp
4
- module Review
5
- module Request
6
- # Describes a request to search for business reviews for businesses
7
- # within a geo-point-specific bounding box and radius around
8
- # that box.
9
- #
10
- class BoundingBox < Yelp::Review::Request::Base
11
- # bottom right latitude of bounding box
12
- attr_reader :bottom_right_latitude
13
-
14
- # bottom right longitude of bounding box
15
- attr_reader :bottom_right_longitude
16
-
17
- # radius to use while searching around specified geo-point.
18
- # default value is 1, maximum value is 25.
19
- attr_reader :radius
20
-
21
- # top left latitude of bounding box
22
- attr_reader :top_left_latitude
23
-
24
- # top left longitude of bounding box
25
- attr_reader :top_left_longitude
26
-
27
- def to_yelp_params
28
- super.merge(:tl_lat => top_left_latitude,
29
- :tl_long => top_left_longitude,
30
- :br_lat => bottom_right_latitude,
31
- :br_long => bottom_right_longitude,
32
- :radius => radius)
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,28 +0,0 @@
1
- require 'yelp/review/request/base'
2
-
3
- class Yelp
4
- module Review
5
- module Request
6
- # Describes a request to search for business reviews for businesses near
7
- # a specific geo-point and radius around that point.
8
- #
9
- class GeoPoint < Yelp::Review::Request::Base
10
- # latitude of geo-point to search near
11
- attr_reader :latitude
12
-
13
- # longitude of geo-point to search near
14
- attr_reader :longitude
15
-
16
- # radius to use while searching around specified geo-point.
17
- # default value is 1, maximum value is 25.
18
- attr_reader :radius
19
-
20
- def to_yelp_params
21
- super.merge(:lat => latitude,
22
- :long => longitude,
23
- :radius => radius)
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,63 +0,0 @@
1
- require 'yelp/review/request/base'
2
-
3
- class Yelp
4
- module Review
5
- module Request
6
- # Describes a request to search for business reviews near a specific
7
- # address/location. You do not need to specify all of the address
8
- # attributes -- some subset of the core +address+, +city+,
9
- # +neighborhood+, +state+ and +zipcode+ will suffice.
10
- #
11
- class Location < Yelp::Review::Request::Base
12
- # the street address of the location sought
13
- attr_reader :address
14
-
15
- # the city of the location sought
16
- attr_reader :city
17
-
18
- # the neighborhood of the location sought
19
- attr_reader :neighborhood
20
-
21
- # radius to use while searching around specified geo-point.
22
- # default value is 1, maximum value is 25.
23
- attr_reader :radius
24
-
25
- # the state of the location sought
26
- attr_reader :state
27
-
28
- # the zipcode of the location sought
29
- attr_reader :zipcode
30
-
31
- def initialize (params)
32
- # we explicitly initialize the location fields since we reference
33
- # them later when building a full location string and we want
34
- # to know they were initialized properly (and avoid warnings)
35
- super({
36
- :address => nil,
37
- :city => nil,
38
- :neighborhood => nil,
39
- :state => nil,
40
- :zipcode => nil
41
- }.merge(params))
42
- end
43
-
44
- def to_yelp_params
45
- super.merge(:location => build_location_string,
46
- :radius => radius)
47
- end
48
-
49
- protected
50
-
51
- # Returns the Yelp-compatible concatenated string with the various
52
- # possible bits of an address-oriented location.
53
- #
54
- def build_location_string
55
- # per the Yelp documentation, the location string is to be built
56
- # as some combination of "address, neighborhood, city, state, or
57
- # zip".
58
- [ @address, @neighborhood, @city, @state, @zipcode ].compact.join(" ")
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,11 +0,0 @@
1
- require 'test/unit'
2
- require 'yelp'
3
-
4
- class TestClient < Test::Unit::TestCase
5
- def test_validation
6
- # make sure we can do basic client instantiation
7
- assert_nothing_raised do
8
- @client = Yelp::Client.new
9
- end
10
- end
11
- end
@@ -1,46 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'yelp'
4
- require File.dirname(__FILE__) + '/yelp_helper'
5
-
6
- class TestNeighborhoodSearch < Test::Unit::TestCase
7
- include YelpHelper
8
-
9
- def setup
10
- create_client
11
- end
12
-
13
- GORDO_LAT = 37.782093
14
- GORDO_LON = -122.483230
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" }
24
-
25
- def test_geo_point_search
26
- request = Yelp::Neighborhood::Request::GeoPoint.new(:latitude => GORDO_LAT,
27
- :longitude => GORDO_LON,
28
- :yws_id => @yws_id)
29
- response = @client.search(request)
30
- validate_json_to_ruby_response(response)
31
- assert_equal response['neighborhoods'].first, GORDO_NEIGHBORHOOD
32
- end
33
-
34
- GORDO_ADDRESS = '2252 Clement Street'
35
-
36
- def test_location_search
37
- request = Yelp::Neighborhood::Request::Location.new(:address => GORDO_ADDRESS,
38
- :city => 'San Francisco',
39
- :state => 'CA',
40
- :zipcode => 94121,
41
- :yws_id => @yws_id)
42
- response = @client.search(request)
43
- validate_json_to_ruby_response(response)
44
- assert_equal response['neighborhoods'].first, GORDO_NEIGHBORHOOD
45
- end
46
- end