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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTBmZGM4MzdmNGI0OGRiNjRiNjc4YzEzYTJlZmJkZDg1ZTc5NTJlMQ==
4
+ MDhiOTVjZGU2NWRiMTI1ZjU4OGJjMWVmOWI5MWMxNTZhMGVmODA5Yg==
5
5
  data.tar.gz: !binary |-
6
- OTY2NmY2ZjJlMGMxY2EwMDM3MzkzODE4NTI0ZDhjYzRkYWJiOThmMw==
6
+ MmUyZjBmNmUzZTJkMjE1M2QyMzUzNjNkZTA1Y2VkMmVhMTJhMTFjNQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MWUxYzViMTVjNWM1NGMyZTk3ZmMzODYyYTAxMTFlOTY4MTZkMmQ2MWQ3MDAy
10
- NDZlNDE1NWQ3OWU4YzY0MmY4NTRhNmY0MDNkMDQ1ZTBmZWU0YmUwYjI2M2Mw
11
- MmM0MGJjMjllODY3ZGQ3OWViNjZkNGI4MTczYTEzZjk4YzlkZTM=
9
+ OTc2MzAyOTdhN2I4NWFmMTA1OTUyYzI3MDc0ZDdiNGRkMWNmNjg5NDA0ODI1
10
+ Zjc5OWZlOTQxYzNlZWNjNmQ4NmJhOWJhOGMyOTliZjY0ZjRmMzdkNDExNWQ0
11
+ MWIxMmE1MDdiZDk1MjE4ZjIzNDc5NzA5ODQxYWRiOGNhYzQ1ZTQ=
12
12
  data.tar.gz: !binary |-
13
- YWU0MWJmMTU2NjIxOWM3ZjM0NzFlM2UyN2MyZmZhMTc5ZGZmNGY0NWI3M2Fl
14
- NjkyNDhlNDNlNWY1ZmIyYjczOTZjYzk3ZjRlMzUzZDgzYjcyN2EwNTdiN2M3
15
- OWMzYTA0NmJmYWExNDFhMDNmN2EwYTY0NGE1Njk0MTJhNGEwYjY=
13
+ YTg4Mzc5MGIwYWRjMzNjMDEyYzhjODdkODZkYzU1ZGNjYzQ3NGQzMjAyMzNl
14
+ NzU3ZGU0ZTRlZGQyODIwNmY1MGEzODc5ZjY1NmJhYWI3MmNjOTJlZTdjNzYz
15
+ M2QzYjU5OWVmOGFiNzM3ODcwNjVjM2ZhODY4N2IwMWE5MTI0MjU=
@@ -1,3 +1,8 @@
1
+ == YELPSTER_20130608_1_1_3
2
+ * [naveed] Combine address components with ',' rather than space
3
+
4
+ * [naveed] Refactor build_url
5
+
1
6
  == YELPSTER_20130429_1_1_2
2
7
  * [naveed] switched testing and deployment libraries
3
8
 
@@ -1,4 +1,4 @@
1
- == Yelpster
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
- The RubyForge project is hosted at http://rubyforge.org/projects/yelpster. This documentation is available at http://yelpster.rubyforge.org.
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
- == Requirements
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
- == Installing
41
+ ## Installing
38
42
 
43
+ ```console
39
44
  % gem install yelpster
45
+ ```
40
46
 
41
- == Usage
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 => YOUR_CONSUMER_KEY’,
105
- :consumer_secret => YOUR_CONSUMER_SECRET’,
106
- :token => YOUR_TOKEN’,
107
- :token_secret => YOUR_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 => YOUR_CONSUMER_KEY’,
119
- :consumer_secret => YOUR_CONSUMER_SECRET’,
120
- :token => YOUR_TOKEN’,
121
- :token_secret => YOUR_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 => YOUR_CONSUMER_KEY’,
130
- :consumer_secret => YOUR_CONSUMER_SECRET’,
131
- :token => YOUR_TOKEN’,
132
- :token_secret => YOUR_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 => YOUR_CONSUMER_KEY’,
140
- :consumer_secret => YOUR_CONSUMER_SECRET’,
141
- :token => YOUR_TOKEN’,
142
- :token_secret => YOUR_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 => YOUR_CONSUMER_KEY’,
151
- :consumer_secret => YOUR_CONSUMER_SECRET’,
152
- :token => YOUR_TOKEN’,
153
- :token_secret => YOUR_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
- == License
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
- == Authors
171
+ ## Authors
164
172
 
165
173
  Copyright 2007 - 2009, Walter Korman <shaper@fatgoose.com>, http://lemurware.blogspot.com
166
174
 
@@ -20,5 +20,5 @@ require 'yelpster/v2/search/request/bounding_box'
20
20
  require 'yelpster/v2/search/request/location'
21
21
 
22
22
  class Yelp
23
- VERSION = '1.1.2'
23
+ VERSION = '1.1.3'
24
24
  end
@@ -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
- # 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)
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
- 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
- url = base_url.clone
90
- unless params.nil?
91
- url << '?'
92
- param_count = 0
93
- params.each do |key, value|
94
- next if value.nil?
95
- url << '&' if (param_count > 0)
96
- key_str = (params[key].kind_of?(Array)) ?
97
- params[key].map { |k| CGI.escape(k.to_s) }.join("+") : CGI.escape(params[key].to_s)
98
- url << "#{CGI.escape(key.to_s)}=#{key_str}"
99
- param_count += 1
100
- end
101
- end
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
- 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
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
- 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
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
- # longitude of geo-point for which a neighborhood name is desired
15
- attr_reader :longitude
14
+ # longitude of geo-point for which a neighborhood name is desired
15
+ attr_reader :longitude
16
16
 
17
- def to_yelp_params
18
- super.merge(:lat => latitude,
19
- :long => longitude)
20
- end
21
- end
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
- 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
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
- 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
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
- def base_url
16
- 'http://api.yelp.com/phone_search'
17
- end
15
+ def base_url
16
+ 'http://api.yelp.com/phone_search'
17
+ end
18
18
 
19
- def to_yelp_params
20
- super.merge(:phone => phone_number)
21
- end
22
- end
19
+ def to_yelp_params
20
+ super.merge(:phone => phone_number)
21
+ end
22
+ end
23
23
  end
24
24
  end
25
25
  end