yelpster 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.rdoc +5 -0
- data/{README.rdoc → README.md} +35 -27
- data/lib/yelpster.rb +1 -1
- data/lib/yelpster/client.rb +31 -33
- data/lib/yelpster/v1/neighborhood/request/base.rb +7 -7
- data/lib/yelpster/v1/neighborhood/request/geo_point.rb +15 -15
- data/lib/yelpster/v1/neighborhood/request/location.rb +46 -46
- data/lib/yelpster/v1/phone/request/number.rb +16 -16
- data/lib/yelpster/v1/request.rb +48 -48
- data/lib/yelpster/v1/review/request/base.rb +21 -21
- data/lib/yelpster/v1/review/request/bounding_box.rb +30 -30
- data/lib/yelpster/v1/review/request/geo_point.rb +19 -19
- data/lib/yelpster/v1/review/request/location.rb +51 -51
- data/lib/yelpster/v2/business/request/id.rb +19 -19
- data/lib/yelpster/v2/request.rb +50 -50
- data/lib/yelpster/v2/search/request/base.rb +51 -51
- data/lib/yelpster/v2/search/request/bounding_box.rb +21 -21
- data/lib/yelpster/v2/search/request/geo_point.rb +46 -46
- data/lib/yelpster/v2/search/request/location.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDhiOTVjZGU2NWRiMTI1ZjU4OGJjMWVmOWI5MWMxNTZhMGVmODA5Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmUyZjBmNmUzZTJkMjE1M2QyMzUzNjNkZTA1Y2VkMmVhMTJhMTFjNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTc2MzAyOTdhN2I4NWFmMTA1OTUyYzI3MDc0ZDdiNGRkMWNmNjg5NDA0ODI1
|
10
|
+
Zjc5OWZlOTQxYzNlZWNjNmQ4NmJhOWJhOGMyOTliZjY0ZjRmMzdkNDExNWQ0
|
11
|
+
MWIxMmE1MDdiZDk1MjE4ZjIzNDc5NzA5ODQxYWRiOGNhYzQ1ZTQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTg4Mzc5MGIwYWRjMzNjMDEyYzhjODdkODZkYzU1ZGNjYzQ3NGQzMjAyMzNl
|
14
|
+
NzU3ZGU0ZTRlZGQyODIwNmY1MGEzODc5ZjY1NmJhYWI3MmNjOTJlZTdjNzYz
|
15
|
+
M2QzYjU5OWVmOGFiNzM3ODcwNjVjM2ZhODY4N2IwMWE5MTI0MjU=
|
data/CHANGELOG.rdoc
CHANGED
data/{README.rdoc → README.md}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
## Yelpster
|
2
2
|
|
3
3
|
A Ruby object-oriented interface to the local business content available
|
4
4
|
on Yelp at http://www.yelp.com. Functionality is provided to perform
|
@@ -12,11 +12,11 @@ all searches available via the developer API including:
|
|
12
12
|
|
13
13
|
More detailed information on the underlying Yelp API, error response codes, and so forth is available at http://www.yelp.com/developers/getting_started.
|
14
14
|
|
15
|
-
|
15
|
+
This documentation is available at http://rubydoc.info/github/nvd/yelpster.
|
16
16
|
|
17
17
|
The latest source code is at http://github.com/nvd/yelpster.
|
18
18
|
|
19
|
-
|
19
|
+
## Requirements
|
20
20
|
|
21
21
|
You must have a Yelp Web Service ID (YWSID) if you're using v1 of the api or Consumer Key, Consumer Secret, Token and a Token Secret for version 2. These are available at http://www.yelp.com/developers/getting_started/api_access.
|
22
22
|
|
@@ -25,20 +25,26 @@ retrieved via their API, documented at http://www.yelp.com/developers/getting_st
|
|
25
25
|
|
26
26
|
For tests to execute successfully you must have the YWSID (for v1) or YELP_CONSUMER_KEY, YELP_CONSUMER_SECRET, YELP_TOKEN and YELP_TOKEN_SECRET(for v2) set in your environment via (shell-dependent, bash example provided):
|
27
27
|
|
28
|
+
```console
|
28
29
|
% export YWSID='YOUR_ID_HERE'
|
30
|
+
```
|
29
31
|
|
30
32
|
or
|
31
33
|
|
34
|
+
```console
|
32
35
|
% export YELP_CONSUMER_KEY='YOUR_CONSUMER_KEY_HERE'
|
33
36
|
% export YELP_CONSUMER_SECRET='YOUR_CONSUMER_SECRET_HERE'
|
34
37
|
% export YELP_PTOKEN='YOUR_TOKEN_HERE'
|
35
38
|
% export YELPP_TOKEN_SECRET='YOUR_TOKEN_SECRET_HERE'
|
39
|
+
```
|
36
40
|
|
37
|
-
|
41
|
+
## Installing
|
38
42
|
|
43
|
+
```console
|
39
44
|
% gem install yelpster
|
45
|
+
```
|
40
46
|
|
41
|
-
|
47
|
+
## Usage
|
42
48
|
|
43
49
|
Instantiate a Yelp::Client and use its +search+ method to make requests of
|
44
50
|
the Yelp server.
|
@@ -64,6 +70,7 @@ types.
|
|
64
70
|
|
65
71
|
A few examples:
|
66
72
|
|
73
|
+
```ruby
|
67
74
|
# construct a client instance
|
68
75
|
client = Yelp::Client.new
|
69
76
|
|
@@ -101,10 +108,10 @@ A few examples:
|
|
101
108
|
# retrieve details of business vi yelp business id
|
102
109
|
request = Yelp::V2::Business::Request::Id.new(
|
103
110
|
:yelp_business_id => "pjb2WMwa0AfK3L-dWimO8w",
|
104
|
-
:consumer_key =>
|
105
|
-
:consumer_secret =>
|
106
|
-
:token =>
|
107
|
-
:token_secret =>
|
111
|
+
:consumer_key => 'YOUR_CONSUMER_KEY',
|
112
|
+
:consumer_secret => 'YOUR_CONSUMER_SECRET',
|
113
|
+
:token => 'YOUR_TOKEN',
|
114
|
+
:token_secret => 'YOUR_TOKEN_SECRET')
|
108
115
|
response = client.search(request)
|
109
116
|
|
110
117
|
# search for businesses via bounding box geo coords'
|
@@ -115,10 +122,10 @@ A few examples:
|
|
115
122
|
:ne_latitude => 37.788022,
|
116
123
|
:ne_longitude => -122.399797,
|
117
124
|
:limit => 3,
|
118
|
-
:consumer_key =>
|
119
|
-
:consumer_secret =>
|
120
|
-
:token =>
|
121
|
-
:token_secret =>
|
125
|
+
:consumer_key => 'YOUR_CONSUMER_KEY',
|
126
|
+
:consumer_secret => 'YOUR_CONSUMER_SECRET',
|
127
|
+
:token => 'YOUR_TOKEN',
|
128
|
+
:token_secret => 'YOUR_TOKEN_SECRET')
|
122
129
|
response = client.search(request)
|
123
130
|
|
124
131
|
# search for businesses via lat/long geo point'
|
@@ -126,20 +133,20 @@ A few examples:
|
|
126
133
|
:term => "cream puffs",
|
127
134
|
:latitude => 37.788022,
|
128
135
|
:longitude => -122.399797,
|
129
|
-
:consumer_key =>
|
130
|
-
:consumer_secret =>
|
131
|
-
:token =>
|
132
|
-
:token_secret =>
|
136
|
+
:consumer_key => 'YOUR_CONSUMER_KEY',
|
137
|
+
:consumer_secret => 'YOUR_CONSUMER_SECRET',
|
138
|
+
:token => 'YOUR_TOKEN',
|
139
|
+
:token_secret => 'YOUR_TOKEN_SECRET')
|
133
140
|
response = client.search(request)
|
134
141
|
|
135
142
|
# search for businesses via location (address, neighbourhood, city, state, zip, country, latitude, longitude)'
|
136
143
|
request = Yelp::V2::Search::Request::Location.new(
|
137
144
|
:term => "cream puffs",
|
138
145
|
:city => "San Francisco",
|
139
|
-
:consumer_key =>
|
140
|
-
:consumer_secret =>
|
141
|
-
:token =>
|
142
|
-
:token_secret =>
|
146
|
+
:consumer_key => 'YOUR_CONSUMER_KEY',
|
147
|
+
:consumer_secret => 'YOUR_CONSUMER_SECRET',
|
148
|
+
:token => 'YOUR_TOKEN',
|
149
|
+
:token_secret => 'YOUR_TOKEN_SECRET')
|
143
150
|
response = client.search(request)
|
144
151
|
|
145
152
|
request = Yelp::V2::Search::Request::Location.new(
|
@@ -147,20 +154,21 @@ A few examples:
|
|
147
154
|
:address => "Hayes",
|
148
155
|
:latitude => 37.77493,
|
149
156
|
:longitude => -122.419415,
|
150
|
-
:consumer_key =>
|
151
|
-
:consumer_secret =>
|
152
|
-
:token =>
|
153
|
-
:token_secret =>
|
157
|
+
:consumer_key => 'YOUR_CONSUMER_KEY',
|
158
|
+
:consumer_secret => 'YOUR_CONSUMER_SECRET',
|
159
|
+
:token => 'YOUR_TOKEN',
|
160
|
+
:token_secret => 'YOUR_TOKEN_SECRET')
|
154
161
|
response = client.search(request)
|
162
|
+
```
|
155
163
|
|
156
164
|
If you want to convert some addresses to latitude/longitude, or vice
|
157
165
|
versa, for testing or what have you -- try http://stevemorse.org/jcal/latlon.php.
|
158
166
|
|
159
|
-
|
167
|
+
## License
|
160
168
|
|
161
169
|
This library is provided via the GNU LGPL license at http://www.gnu.org/licenses/lgpl.html.
|
162
170
|
|
163
|
-
|
171
|
+
## Authors
|
164
172
|
|
165
173
|
Copyright 2007 - 2009, Walter Korman <shaper@fatgoose.com>, http://lemurware.blogspot.com
|
166
174
|
|
data/lib/yelpster.rb
CHANGED
data/lib/yelpster/client.rb
CHANGED
@@ -29,10 +29,10 @@ class Yelp
|
|
29
29
|
class Client
|
30
30
|
# allows specifying the user agent string to submit with search requests
|
31
31
|
attr_accessor :agent
|
32
|
-
|
32
|
+
|
33
33
|
# whether debug mode is enabled for logging purposes, defaulting to false
|
34
34
|
attr_accessor :debug
|
35
|
-
|
35
|
+
|
36
36
|
# the Logger compatible object with which log messages are outputted,
|
37
37
|
# defaulting to output to STDOUT
|
38
38
|
attr_accessor :logger
|
@@ -48,7 +48,7 @@ class Yelp
|
|
48
48
|
@debug = false
|
49
49
|
@logger = nil
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
# Submits the supplied search request to Yelp and returns the response in
|
53
53
|
# the format specified by the request.
|
54
54
|
#
|
@@ -61,10 +61,10 @@ class Yelp
|
|
61
61
|
debug_msg "submitting search [url=#{url}, request=#{request.to_yaml}]."
|
62
62
|
|
63
63
|
# submit the http request for the results
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
# http_request_params not used in v2 as OAuth (implemented in v2) only takes response params
|
65
|
+
http_params = { 'User-Agent' => @agent }
|
66
|
+
http_params['Accept-Encoding'] = 'gzip,deflate' if request.compress_response?
|
67
|
+
content = request.pull_results(url, http_params)
|
68
68
|
|
69
69
|
# read the response content
|
70
70
|
debug_msg((request.response_format.serialized?) ? "received response [content_length=#{content.length}]." : "received response [content_length=#{content.length}, content=#{content}].")
|
@@ -75,31 +75,29 @@ class Yelp
|
|
75
75
|
|
76
76
|
protected
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
url
|
103
|
-
end
|
78
|
+
def format_content (response_format, content)
|
79
|
+
(response_format == Yelp::ResponseFormat::JSON_TO_RUBY) ? JSON.parse(content) : content
|
80
|
+
end
|
81
|
+
|
82
|
+
def debug_msg (message)
|
83
|
+
return if !@debug
|
84
|
+
@logger = Logger.new(STDOUT) if (!@logger)
|
85
|
+
@logger.debug message
|
86
|
+
end
|
87
|
+
|
88
|
+
def build_url (base_url, params)
|
89
|
+
"#{base_url}?#{to_query_string(params)}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def to_query_string(params)
|
93
|
+
params.delete_if { |_, v| v.nil? }
|
94
|
+
.to_a
|
95
|
+
.map { |key, value| "#{escape(key)}=#{escape(value)}" }
|
96
|
+
.join('&')
|
97
|
+
end
|
98
|
+
|
99
|
+
def escape(object)
|
100
|
+
object.kind_of?(Array) ? object.map { |v| CGI.escape(v.to_s) }.join('+') : CGI.escape(object.to_s)
|
101
|
+
end
|
104
102
|
end
|
105
103
|
end
|
@@ -2,13 +2,13 @@ require 'yelpster/v1/request'
|
|
2
2
|
|
3
3
|
class Yelp
|
4
4
|
module V1
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
module Neighborhood
|
6
|
+
module Request
|
7
|
+
class Base < Yelp::V1::Request
|
8
|
+
def base_url
|
9
|
+
'http://api.yelp.com/neighborhood_search'
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
@@ -2,23 +2,23 @@ require 'yelpster/v1/neighborhood/request/base'
|
|
2
2
|
|
3
3
|
class Yelp
|
4
4
|
module V1
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
module Neighborhood
|
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::V1::Neighborhood::Request::Base
|
11
|
+
# latitude of geo-point for which a neighborhood name is desired
|
12
|
+
attr_reader :latitude
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
# longitude of geo-point for which a neighborhood name is desired
|
15
|
+
attr_reader :longitude
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def to_yelp_params
|
18
|
+
super.merge(:lat => latitude,
|
19
|
+
:long => longitude)
|
20
|
+
end
|
21
|
+
end
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -2,52 +2,52 @@ require 'yelpster/v1/neighborhood/request/base'
|
|
2
2
|
|
3
3
|
class Yelp
|
4
4
|
module V1
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
5
|
+
module Neighborhood
|
6
|
+
module Request
|
7
|
+
# Describes a request to search for a neighborhood name for 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
|
+
# +state+ and +zipcode+ will suffice.
|
11
|
+
#
|
12
|
+
class Location < Yelp::V1::Neighborhood::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 state of the location sought
|
20
|
+
attr_reader :state
|
21
|
+
|
22
|
+
# the zipcode of the location sought
|
23
|
+
attr_reader :zipcode
|
24
|
+
|
25
|
+
def initialize (params)
|
26
|
+
# we explicitly initialize the location fields since we reference
|
27
|
+
# them later when building a full location string and we want
|
28
|
+
# to know they were initialized properly (and avoid warnings)
|
29
|
+
super({
|
30
|
+
:address => nil,
|
31
|
+
:city => nil,
|
32
|
+
:state => nil,
|
33
|
+
:zipcode => nil
|
34
|
+
}.merge(params))
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_yelp_params
|
38
|
+
super.merge(:location => build_location_string)
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
# Returns the Yelp-compatible concatenated string with the various
|
44
|
+
# possible bits of an address-oriented location.
|
45
|
+
#
|
46
|
+
def build_location_string
|
47
|
+
# per the Yelp documentation, the location string is to be built
|
48
|
+
# as some combination of "address, city, state, or zip".
|
49
|
+
[ @address, @city, @state, @zipcode ].compact.join(',')
|
50
|
+
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -2,24 +2,24 @@ require 'yelpster/v1/request'
|
|
2
2
|
|
3
3
|
class Yelp
|
4
4
|
module V1
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
module Phone
|
6
|
+
module Request
|
7
|
+
# Describes a request to search for a business review for the business
|
8
|
+
# associated with a specific phone number.
|
9
|
+
#
|
10
|
+
class Number < Yelp::V1::Request
|
11
|
+
# the phone number of the business to search for, formatted as
|
12
|
+
# '1112223333'. Make sure you don't have any hyphens or parentheses.
|
13
|
+
attr_reader :phone_number
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def base_url
|
16
|
+
'http://api.yelp.com/phone_search'
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def to_yelp_params
|
20
|
+
super.merge(:phone => phone_number)
|
21
|
+
end
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|