yelped 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ require 'yelped/v1/review/request/base'
2
+
3
+ class Yelp
4
+ module V1
5
+ module Review
6
+ module Request
7
+ # Describes a request to search for business reviews for businesses
8
+ # within a geo-point-specific bounding box and radius around
9
+ # that box.
10
+ #
11
+ class BoundingBox < Yelp::V1::Review::Request::Base
12
+ # bottom right latitude of bounding box
13
+ attr_reader :bottom_right_latitude
14
+
15
+ # bottom right longitude of bounding box
16
+ attr_reader :bottom_right_longitude
17
+
18
+ # radius to use while searching around specified geo-point.
19
+ # default value is 1, maximum value is 25.
20
+ attr_reader :radius
21
+
22
+ # top left latitude of bounding box
23
+ attr_reader :top_left_latitude
24
+
25
+ # top left longitude of bounding box
26
+ attr_reader :top_left_longitude
27
+
28
+ def to_yelp_params
29
+ super.merge(:tl_lat => top_left_latitude,
30
+ :tl_long => top_left_longitude,
31
+ :br_lat => bottom_right_latitude,
32
+ :br_long => bottom_right_longitude,
33
+ :radius => radius)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,30 @@
1
+ require 'yelped/v1/review/request/base'
2
+
3
+ class Yelp
4
+ module V1
5
+ module Review
6
+ module Request
7
+ # Describes a request to search for business reviews for businesses near
8
+ # a specific geo-point and radius around that point.
9
+ #
10
+ class GeoPoint < Yelp::V1::Review::Request::Base
11
+ # latitude of geo-point to search near
12
+ attr_reader :latitude
13
+
14
+ # longitude of geo-point to search near
15
+ attr_reader :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
+ def to_yelp_params
22
+ super.merge(:lat => latitude,
23
+ :long => longitude,
24
+ :radius => radius)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,65 @@
1
+ require 'yelped/v1/review/request/base'
2
+
3
+ class Yelp
4
+ module V1
5
+ module Review
6
+ module Request
7
+ # Describes a request to search for business reviews near a specific
8
+ # address/location. You do not need to specify all of the address
9
+ # attributes -- some subset of the core +address+, +city+,
10
+ # +neighborhood+, +state+ and +zipcode+ will suffice.
11
+ #
12
+ class Location < Yelp::V1::Review::Request::Base
13
+ # the street address of the location sought
14
+ attr_reader :address
15
+
16
+ # the city of the location sought
17
+ attr_reader :city
18
+
19
+ # the neighborhood of the location sought
20
+ attr_reader :neighborhood
21
+
22
+ # radius to use while searching around specified geo-point.
23
+ # default value is 1, maximum value is 25.
24
+ attr_reader :radius
25
+
26
+ # the state of the location sought
27
+ attr_reader :state
28
+
29
+ # the zipcode of the location sought
30
+ attr_reader :zipcode
31
+
32
+ def initialize (params)
33
+ # we explicitly initialize the location fields since we reference
34
+ # them later when building a full location string and we want
35
+ # to know they were initialized properly (and avoid warnings)
36
+ super({
37
+ :address => nil,
38
+ :city => nil,
39
+ :neighborhood => nil,
40
+ :state => nil,
41
+ :zipcode => nil
42
+ }.merge(params))
43
+ end
44
+
45
+ def to_yelp_params
46
+ super.merge(:location => build_location_string,
47
+ :radius => radius)
48
+ end
49
+
50
+ protected
51
+
52
+ # Returns the Yelp-compatible concatenated string with the various
53
+ # possible bits of an address-oriented location.
54
+ #
55
+ def build_location_string
56
+ # per the Yelp documentation, the location string is to be built
57
+ # as some combination of "address, neighborhood, city, state, or
58
+ # zip".
59
+ [ @address, @neighborhood, @city, @state, @zipcode ].compact.join(" ")
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ require 'yelped/v2/request'
2
+
3
+ class Yelp
4
+ module V2
5
+ module Business
6
+ module Request
7
+ class Id < Yelp::V2::Request
8
+ # the alphanumeric id of the business to search for as provided by yelp,
9
+ # eg: 'pjb2WMwa0AfK3L-dWimO8w'
10
+ attr_reader :yelp_business_id
11
+
12
+ def base_url
13
+ 'http://api.yelp.com/v2/business/'+yelp_business_id
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ require 'yelped/record'
2
+ require 'oauth'
3
+
4
+ class Yelp
5
+ module V2
6
+ class Request < Yelp::Record
7
+ # specifies whether the response content should be transmitted
8
+ # over the wire compressed, defaulting to true.
9
+ attr_reader :compress_response
10
+
11
+ # one of the Yelp::ResponseFormat format specifiers detailing the
12
+ # desired format of the search results, defaulting to
13
+ # Yelp::ResponseFormat::JSON_TO_RUBY.
14
+ attr_reader :response_format
15
+
16
+ # the Yelp consumer_key, consumer_secret, token, token_secret to be passed with the request for
17
+ # authentication purposes. See http://www.yelp.com/developers/getting_started/api_access
18
+ # to get your own.
19
+ attr_reader :consumer_key
20
+ attr_reader :consumer_secret
21
+ attr_reader :token
22
+ attr_reader :token_secret
23
+
24
+ alias :compress_response? :compress_response
25
+
26
+ def initialize (params)
27
+ default_params = {
28
+ :compress_response => true,
29
+ :response_format => Yelp::ResponseFormat::JSON_TO_RUBY
30
+ }
31
+ super(default_params.merge(params))
32
+ end
33
+
34
+ def to_yelp_params
35
+ params = {}
36
+
37
+ # if they specified anything other than a json variant, we
38
+ # need to tell yelp what we're looking for
39
+ case @response_format
40
+ when Yelp::ResponseFormat::PICKLE
41
+ params[:output] = 'pickle'
42
+ when Yelp::ResponseFormat::PHP
43
+ params[:output] = 'php'
44
+ end
45
+
46
+ params
47
+ end
48
+
49
+ def pull_results (url, http_params)
50
+ consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {:site => "http://api.yelp.com"})
51
+ access_token = OAuth::AccessToken.new(consumer, token, token_secret)
52
+ access_token.get(url).body
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ require 'yelped/v2/request'
2
+
3
+ class Yelp
4
+ module V2
5
+ module Search
6
+ module Request
7
+ class Base < Yelp::V2::Request
8
+ #------------------------General Search Params -----------------
9
+ # string representing the name of business or search term being
10
+ #requested.
11
+ attr_reader :term
12
+
13
+ # integer representing number of business results to return
14
+ attr_reader :limit
15
+
16
+ # integer representing number of results to skip (for pagination)
17
+ attr_reader :offset
18
+
19
+ # integer for specifying how to sort results
20
+ # Sort Mode:
21
+ # 0 = Best matched (default)
22
+ # 1 = Distance
23
+ # 2 = Highest rated
24
+ # see www.yelp.com/developers/documentation/v2/search_api for more info
25
+ attr_reader :sort
26
+
27
+ # string specifying which business category to search in
28
+ # see www.yelp.com/developers/documentation/category_list for list of
29
+ # categories
30
+ attr_reader :category_filter
31
+
32
+ # integer specifying the search radius in meters
33
+ attr_reader :radius_filter
34
+
35
+ # boolean representing if business has claimed location
36
+ # not implemented by yelp as of 13-8-2011
37
+ attr_reader :claimed_filter
38
+ #---------------------------------------------------------------
39
+
40
+ #--------------------------- Locale Params ---------------------
41
+ # string representing default country to use while parsing location field
42
+ attr_reader :cc
43
+
44
+ # string representing which language of reviews to return
45
+ attr_reader :lang
46
+ #---------------------------------------------------------------
47
+
48
+ def base_url
49
+ 'http://api.yelp.com/v2/search'
50
+ end
51
+
52
+ def to_yelp_params
53
+ super.merge(:term => term,
54
+ :limit => limit,
55
+ :offset => offset,
56
+ :sort => sort,
57
+ :category_filter => category_filter,
58
+ :radius_filter => radius_filter,
59
+ :claimed_filter => claimed_filter,
60
+
61
+ :cc => cc,
62
+ :lang => lang)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,30 @@
1
+ require 'yelped/v2/search/request/base'
2
+
3
+ class Yelp
4
+ module V2
5
+ module Search
6
+ module Request
7
+ # Describes a request to search for businesses
8
+ # within a geo-point-specific bounding box
9
+ #
10
+ class BoundingBox < Yelp::V2::Search::Request::Base
11
+ # REQUIRED - double, bottom right latitude of bounding box (SOUTH-WEST LAT)
12
+ attr_reader :sw_latitude
13
+
14
+ # REQUIRED - double, bottom right longitude of bounding box (SOUTH-WEST LONG)
15
+ attr_reader :sw_longitude
16
+
17
+ # REQUIRED - double, top left latitude of bounding box (NORTH-EAST LAT)
18
+ attr_reader :ne_latitude
19
+
20
+ # REQUIRED - double, top left longitude of bounding box (NORTH-EAST LONG)
21
+ attr_reader :ne_longitude
22
+
23
+ def to_yelp_params
24
+ super.merge(:bounds => "#{sw_latitude},#{sw_longitude}|#{ne_latitude},#{ne_longitude}")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,54 @@
1
+ require 'yelped/v2/search/request/base'
2
+
3
+ class Yelp
4
+ module V2
5
+ module Search
6
+ module Request
7
+ # Describes a request to search for the name of a neighborhood at a
8
+ # specific geo-point location.
9
+ #
10
+ class GeoPoint < Yelp::V2::Search::Request::Base
11
+ # REQUIRED - double, latitude of geo-point to search
12
+ attr_reader :latitude
13
+
14
+ # REQUIRED - double, longitude of geo-point to search
15
+ attr_reader :longitude
16
+
17
+ # OPTIONAL - double, accuracy of latitude and longitude of geo-point to search
18
+ attr_reader :accuracy
19
+
20
+ # OPTIONAL - double, altitude of geo-point to search
21
+ attr_reader :altitude
22
+
23
+ # OPTIONAL - double, accuracy of altitude geo-point to search
24
+ attr_reader :altitude_accuracy
25
+
26
+ def initialize(params)
27
+ # we explicitly initialize the location fields since we reference
28
+ # them later when building a full location string and we want
29
+ # to know they were initialized properly (and avoid warnings)
30
+ # 50 and -100 default values are provided as they lie within yelp API's geo-location range
31
+ super({
32
+ :latitude => 50.0,
33
+ :longitude => -100.0,
34
+ :accuracy => nil,
35
+ :altitude => nil,
36
+ :altitude_accuracy => nil
37
+ }.merge(params))
38
+ end
39
+
40
+ def to_yelp_params
41
+ super.merge(:ll => build_geo_loc_string)
42
+ end
43
+
44
+ # Returns the Yelp-compatible concatenated string with the various
45
+ # possible bits of an address-oriented location.
46
+ #
47
+ def build_geo_loc_string
48
+ [ @latitude, @longitude, @accuracy, @altitude, @altitude_accuracy ].compact.join(",")
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,76 @@
1
+ require 'yelped/v2/search/request/base'
2
+
3
+ class Yelp
4
+ module V2
5
+ module Search
6
+ module Request
7
+ # Describes a request to search for a businesses by a
8
+ # address/location. You do not need to specify all of the address
9
+ # attributes -- some subset of the core
10
+ # address, neighborhood, city, state or zip, optional country
11
+ #
12
+ class Location < Yelp::V2::Search::Request::Base
13
+ # NOTE: At least one of address, neighborhood, city, state,
14
+ # zipcode or country must be specified
15
+
16
+ # string representing the street address of the location sought
17
+ attr_reader :address
18
+
19
+ # string representing the neighborhood of the location sought
20
+ attr_reader :neighborhood
21
+
22
+ # string representing the city of the location sought
23
+ attr_reader :city
24
+
25
+ # string representing the state of the location sought
26
+ attr_reader :state
27
+
28
+ # string representing the zipcode of the location sought
29
+ attr_reader :zipcode
30
+
31
+ # string representing the country of the location sought
32
+ attr_reader :country
33
+
34
+ # additional attributes that can be specified = latitude + longitude
35
+ attr_reader :latitude
36
+ attr_reader :longitude
37
+
38
+ def initialize (params)
39
+ # we explicitly initialize the location fields since we reference
40
+ # them later when building a full location string and we want
41
+ # to know they were initialized properly (and avoid warnings)
42
+ super({ :address => nil,
43
+ :neighborhood => nil,
44
+ :city => nil,
45
+ :state => nil,
46
+ :zipcode => nil,
47
+ :country => nil,
48
+ :latitude => nil,
49
+ :longitude => nil
50
+ }.merge(params))
51
+ end
52
+
53
+ def to_yelp_params
54
+ super.merge(:location => build_location_string,
55
+ :cll => build_geo_location_string)
56
+ end
57
+
58
+ protected
59
+
60
+ # Returns the Yelp-compatible concatenated string with the various
61
+ # possible bits of an address-oriented location.
62
+ #
63
+ def build_location_string
64
+ # per the Yelp documentation, the location string is to be built
65
+ # as some combination of "address, neighborhood, city, state, or zip, country".
66
+ [ @address, @neighborhood, @city, @state, @zipcode, @country ].compact.join(" ")
67
+ end
68
+
69
+ def build_geo_location_string
70
+ [ @latitude, @longitude ].collect{|var| var || 0}.join(",")
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end