yelpster 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,168 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'yelpster'
4
+ require File.dirname(__FILE__) + '/yelp_helper'
5
+
6
+ class TestReviewSearch < Test::Unit::TestCase
7
+ include YelpHelper
8
+
9
+ def setup
10
+ create_client YelpHelper::API_V1
11
+ end
12
+
13
+ def test_bounding_box
14
+ request = Yelp::V1::Review::Request::BoundingBox.new(
15
+ :bottom_right_latitude => 37.788022,
16
+ :bottom_right_longitude => -122.399797,
17
+ :top_left_latitude => 37.9,
18
+ :top_left_longitude => -122.5,
19
+ # :radius => 1,
20
+ # :business_count => 3,
21
+ :term => 'yelp',
22
+ :yws_id => @yws_id)
23
+ response = @client.search(request)
24
+ validate_json_to_ruby_response(response)
25
+ end
26
+
27
+ def test_geo_point
28
+ request = Yelp::V1::Review::Request::GeoPoint.new(
29
+ :latitude => 37.78022,
30
+ :longitude => -122.399797,
31
+ :radius => 2,
32
+ # :business_count => 5,
33
+ :term => 'yelp',
34
+ :yws_id => @yws_id)
35
+ response = @client.search(request)
36
+ validate_json_to_ruby_response(response)
37
+ end
38
+
39
+ def test_location
40
+ request = Yelp::V1::Review::Request::Location.new(
41
+ :address => '650 Mission St',
42
+ :city => 'San Francisco',
43
+ :state => 'CA',
44
+ :radius => 2,
45
+ # :business_count => 5,
46
+ :term => 'cream puffs',
47
+ :yws_id => @yws_id)
48
+ response = @client.search(request)
49
+ validate_json_to_ruby_response(response)
50
+ end
51
+
52
+ def test_category
53
+ # perform a basic search of businesses near SOMA
54
+ request = Yelp::V1::Review::Request::GeoPoint.new(
55
+ :latitude => 37.78022,
56
+ :longitude => -122.399797,
57
+ :radius => 5,
58
+ :term => 'yelp',
59
+ :yws_id => @yws_id)
60
+ response = @client.search(request)
61
+
62
+ # perform the same search focusing only on playgrounds
63
+ narrowed_request = Yelp::V1::Review::Request::GeoPoint.new(
64
+ :latitude => 37.78022,
65
+ :longitude => -122.399797,
66
+ :radius => 5,
67
+ :term => 'yelp',
68
+ :category => 'playgrounds',
69
+ :yws_id => @yws_id)
70
+ narrowed_response = @client.search(narrowed_request)
71
+
72
+ # make sure we got less for the second
73
+ assert(response['businesses'].length > narrowed_response['businesses'].length)
74
+ end
75
+
76
+ def test_json_response_format
77
+ request = basic_request(:response_format => Yelp::ResponseFormat::JSON)
78
+ response = @client.search(request)
79
+ validate_json_response(response)
80
+ end
81
+
82
+ def test_json_to_ruby_response_format
83
+ request = basic_request(:response_format => Yelp::ResponseFormat::JSON_TO_RUBY)
84
+ response = @client.search(request)
85
+ validate_json_to_ruby_response(response)
86
+ end
87
+
88
+ def test_pickle_response_format
89
+ request = basic_request(:response_format => Yelp::ResponseFormat::PICKLE)
90
+ @client.search(request)
91
+ # TODO: validation
92
+ end
93
+
94
+ def test_php_response_format
95
+ request = basic_request(:response_format => Yelp::ResponseFormat::PHP)
96
+ response = @client.search(request)
97
+ # TODO: validation
98
+ end
99
+
100
+ def test_compressed_response
101
+ request = basic_request(:compress_response => true)
102
+ response = @client.search(request)
103
+ validate_json_to_ruby_response(response)
104
+ end
105
+
106
+ def test_uncompressed_response
107
+ request = basic_request(:compress_response => false)
108
+ response = @client.search(request)
109
+ validate_json_to_ruby_response(response)
110
+ end
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::V1::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::V1::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
+
157
+ protected
158
+
159
+ def basic_request (params = nil)
160
+ default_params = {
161
+ :city => 'San Francisco',
162
+ :state => 'CA',
163
+ :term => 'gordo',
164
+ :yws_id => @yws_id
165
+ }
166
+ Yelp::V1::Review::Request::Location.new(default_params.merge(params))
167
+ end
168
+ end
@@ -0,0 +1,74 @@
1
+ require 'pp'
2
+
3
+ module YelpHelper
4
+ API_V1 = 'v1'
5
+ API_V2 = 'v2'
6
+
7
+ def create_client(api_ver)
8
+ @client = Yelp::Client.new
9
+ @api_ver = api_ver
10
+
11
+ case @api_ver
12
+ when API_V1
13
+ assert_not_nil(ENV['YWSID'], "Missing YWSID. Obtain from http://www.yelp.com/developer and " +
14
+ "set in your shell environment under 'YWSID'.")
15
+ @yws_id = ENV['YWSID']
16
+ when API_V2
17
+ assert_not_nil(ENV['CONSUMER_KEY'], "Missing CONSUMER_KEY. Obtain from http://www.yelp.com/developer and " +
18
+ "set in your shell environment under 'CONSUMER_KEY'.")
19
+ @consumer_key = ENV['CONSUMER_KEY']
20
+ assert_not_nil(ENV['CONSUMER_SECRET'], "Missing CONSUMER_SECRET. Obtain from http://www.yelp.com/developer and " +
21
+ "set in your shell environment under 'CONSUMER_SECRET'.")
22
+ @consumer_secret = ENV['CONSUMER_SECRET']
23
+ assert_not_nil(ENV['TOKEN'], "Missing TOKEN. Obtain from http://www.yelp.com/developer and " +
24
+ "set in your shell environment under 'TOKEN'.")
25
+ @token = ENV['TOKEN']
26
+ assert_not_nil(ENV['TOKEN_SECRET'], "Missing TOKEN_SECRET. Obtain from http://www.yelp.com/developer and " +
27
+ "set in your shell environment under 'TOKEN_SECRET'.")
28
+ @token_secret = ENV['TOKEN_SECRET']
29
+ else
30
+ assert_false("No api version specified in test case; cannot continue")
31
+ end
32
+
33
+ # @client.debug = true
34
+ end
35
+
36
+ def validate_json_response (response)
37
+ assert_not_nil response
38
+ assert_instance_of String, response
39
+ assert_match(/^\{\"message\":\{\"text\":\"OK\",\"code\":0,\"version\":\"1\.1\.1\"\},\"(businesses|neighborhoods)\":.*?\}$/, response)
40
+ end
41
+
42
+ def validate_json_to_ruby_response (response)
43
+ assert_not_nil response
44
+ assert_instance_of Hash, response
45
+ case @api_ver
46
+ when API_V1
47
+ assert_not_nil response['message']
48
+ assert(response['message']['code'] == 0)
49
+ assert(response['message']['text'] == 'OK')
50
+ when API_V2
51
+ # v2 responses do not have a message field
52
+ end
53
+ assert_not_nil((response['businesses'] || response['neighborhoods']))
54
+ if response['businesses']
55
+ response['businesses'].each { |b| validate_json_to_ruby_business(b) }
56
+ end
57
+ end
58
+
59
+ #YELP_BIZ_ID_LENGTH = 22
60
+
61
+ def validate_json_to_ruby_business (business)
62
+ # rudimentary checks to make sure it looks like a typical yelp business
63
+ # result converted to a ruby hash
64
+ assert business['id'].length > 0
65
+ assert_valid_url business['url']
66
+ end
67
+
68
+ # just a rudimentary check will serve us fine
69
+ VALID_URL_REGEXP = /^https?:\/\/[a-z0-9]/i
70
+
71
+ def assert_valid_url (url)
72
+ assert_match VALID_URL_REGEXP, url
73
+ end
74
+ end
data/yelpster.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "yelpster"
5
+ s.version = "1.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Naveed Siddiqui"]
9
+ s.date = "2011-10-13"
10
+ s.description = "Extension of Korman's Ruby wrapper to interface with Yelp's REST API described in detail at:\n\nhttp://www.yelp.com/developers/getting_started\n"
11
+ s.email = "naveed@10eighteen.com"
12
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "LICENSE.txt", "README.rdoc", "TODO.txt", "lib/yelpster.rb", "lib/yelpster/client.rb", "lib/yelpster/record.rb", "lib/yelpster/response_format.rb", "lib/yelpster/v1/neighborhood/request/base.rb", "lib/yelpster/v1/neighborhood/request/geo_point.rb", "lib/yelpster/v1/neighborhood/request/location.rb", "lib/yelpster/v1/phone/request/number.rb", "lib/yelpster/v1/request.rb", "lib/yelpster/v1/review/request/base.rb", "lib/yelpster/v1/review/request/bounding_box.rb", "lib/yelpster/v1/review/request/geo_point.rb", "lib/yelpster/v1/review/request/location.rb", "lib/yelpster/v2/business/request/id.rb", "lib/yelpster/v2/request.rb", "lib/yelpster/v2/search/request/base.rb", "lib/yelpster/v2/search/request/bounding_box.rb", "lib/yelpster/v2/search/request/geo_point.rb", "lib/yelpster/v2/search/request/location.rb"]
13
+ s.files = ["CHANGELOG.rdoc", "LICENSE.txt", "Manifest", "README.rdoc", "Rakefile", "TODO.txt", "lib/yelpster.rb", "lib/yelpster/client.rb", "lib/yelpster/record.rb", "lib/yelpster/response_format.rb", "lib/yelpster/v1/neighborhood/request/base.rb", "lib/yelpster/v1/neighborhood/request/geo_point.rb", "lib/yelpster/v1/neighborhood/request/location.rb", "lib/yelpster/v1/phone/request/number.rb", "lib/yelpster/v1/request.rb", "lib/yelpster/v1/review/request/base.rb", "lib/yelpster/v1/review/request/bounding_box.rb", "lib/yelpster/v1/review/request/geo_point.rb", "lib/yelpster/v1/review/request/location.rb", "lib/yelpster/v2/business/request/id.rb", "lib/yelpster/v2/request.rb", "lib/yelpster/v2/search/request/base.rb", "lib/yelpster/v2/search/request/bounding_box.rb", "lib/yelpster/v2/search/request/geo_point.rb", "lib/yelpster/v2/search/request/location.rb", "test/test_business_retrieve.rb", "test/test_business_search.rb", "test/test_client.rb", "test/test_neighborhood_search.rb", "test/test_phone_search.rb", "test/test_review_search.rb", "test/yelp_helper.rb", "yelpster.gemspec"]
14
+ s.homepage = "https://github.com/nvd/yelpster"
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Yelpster", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "yelpster"
18
+ s.rubygems_version = "1.8.11"
19
+ s.summary = "An object-oriented interface to the Yelp Developer API."
20
+ s.test_files = ["test/test_business_retrieve.rb", "test/test_business_search.rb", "test/test_client.rb", "test/test_neighborhood_search.rb", "test/test_phone_search.rb", "test/test_review_search.rb"]
21
+ s.signing_key = '/Users/naveed/Desktop/dev/Certificates/yelpster/gem-private_key.pem'
22
+ s.cert_chain = ['gem-public_cert.pem']
23
+
24
+ if s.respond_to? :specification_version then
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<json>, [">= 1.1.1"])
29
+ s.add_runtime_dependency(%q<oauth>, [">= 0.4.5"])
30
+ else
31
+ s.add_dependency(%q<json>, [">= 1.1.1"])
32
+ s.add_dependency(%q<oauth>, [">= 0.4.5"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<json>, [">= 1.1.1"])
36
+ s.add_dependency(%q<oauth>, [">= 0.4.5"])
37
+ end
38
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1,3 @@
1
+ ��� *㲣�=�ׁkJ���6��S$Q��2ғ����Rz�d{M� -W�_�.��f�-]@b�Q΄�W�=7S�V��ʢ�`Kx��X�u@ ��m���� �u���{�&h��� �eU|,+[�.�+���>C��s�W��Y�!��� �m�
2
+ F��G�H��k��'�~v%£k>�M;�?쓞����>�����mq��VP�st*mԃE5o�5RP
3
+ ��2W��9�<Ÿ9�.�@n��^�u)�
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yelpster
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.1.1
6
+ platform: ruby
7
+ authors:
8
+ - Naveed Siddiqui
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIDODCCAiCgAwIBAgIBADANBgkqhkiG9w0BAQUFADBCMQ8wDQYDVQQDDAZuYXZl
15
+ ZWQxGjAYBgoJkiaJk/IsZAEZFgoxMGVpZ2h0ZWVuMRMwEQYKCZImiZPyLGQBGRYD
16
+ Y29tMB4XDTExMTAxMzE0MTg0NloXDTEyMTAxMjE0MTg0NlowQjEPMA0GA1UEAwwG
17
+ bmF2ZWVkMRowGAYKCZImiZPyLGQBGRYKMTBlaWdodGVlbjETMBEGCgmSJomT8ixk
18
+ ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM/MW7owmvsy
19
+ BlEVc5yDWxLMWQvK6igewl4YBienALpPzcVnLEcYVS9gQIGbx4weiw3gNMm+6keY
20
+ lFYFOzu29KvYQrmc8QqSfLq8r8hRe/3Lcx4fQdZHQuoPtvZ7YOZSAGRIQuBont9W
21
+ 8VVgbF8KjDj1IUFi/YI+VfMXD4xypyXC8mzaEaHFpquM9GKh46++s382IBOv2sZV
22
+ UNVBRvmHYkV+8ysGiH6vgwkNTTHC9+oHhXQYPQ51A+I1CI1jnMs5LRgwKiZ/L93G
23
+ V8NbvR/CdKKbAtOs20QT60CMVOF5UsF9XTynu3+HRNYQ7eQirukp8275R5I3Geh8
24
+ 2XtRv8hzO+MCAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQUGgYrXrTHBcRx
25
+ IGkT4AgsUqHCPUIwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQDLI4Li
26
+ SDEmqnyONx7uFK9vDnzr1crqRyK5F3HkFYLudCrtgpPz2PSHxg9z421rWp34n18Z
27
+ E9mWA8SrBVAFmqH9zuj5TSmXKrO72157MdNy2MIIych8auu3CATZTVCFdGVkcYXx
28
+ HyAiuqfHI73U1D0BWRz7ZzOnE2QqVBekmDLmEGZyiJUoQPSAFb1Zr7h8hKyPkHev
29
+ 0iXzgNY1VjcdDGmhcbg86mk3sWk0AnVk3oLwxo+6r8lc+AuRT59edeRkxN7HA3zb
30
+ ahJOnBb3+Ql5b9v2KMN1rct+SqTnjD+zEkVeGz9gW5zsRWvx1sbNCxgD6zQJ9SXH
31
+ zztOQ91rVpCrfFhH
32
+ -----END CERTIFICATE-----
33
+
34
+ date: 2011-10-13 00:00:00 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ prerelease: false
39
+ requirement: &id001 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 1.1.1
45
+ type: :runtime
46
+ version_requirements: *id001
47
+ - !ruby/object:Gem::Dependency
48
+ name: oauth
49
+ prerelease: false
50
+ requirement: &id002 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.4.5
56
+ type: :runtime
57
+ version_requirements: *id002
58
+ description: |
59
+ Extension of Korman's Ruby wrapper to interface with Yelp's REST API described in detail at:
60
+
61
+ http://www.yelp.com/developers/getting_started
62
+
63
+ email: naveed@10eighteen.com
64
+ executables: []
65
+
66
+ extensions: []
67
+
68
+ extra_rdoc_files:
69
+ - CHANGELOG.rdoc
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ - TODO.txt
73
+ - lib/yelpster.rb
74
+ - lib/yelpster/client.rb
75
+ - lib/yelpster/record.rb
76
+ - lib/yelpster/response_format.rb
77
+ - lib/yelpster/v1/neighborhood/request/base.rb
78
+ - lib/yelpster/v1/neighborhood/request/geo_point.rb
79
+ - lib/yelpster/v1/neighborhood/request/location.rb
80
+ - lib/yelpster/v1/phone/request/number.rb
81
+ - lib/yelpster/v1/request.rb
82
+ - lib/yelpster/v1/review/request/base.rb
83
+ - lib/yelpster/v1/review/request/bounding_box.rb
84
+ - lib/yelpster/v1/review/request/geo_point.rb
85
+ - lib/yelpster/v1/review/request/location.rb
86
+ - lib/yelpster/v2/business/request/id.rb
87
+ - lib/yelpster/v2/request.rb
88
+ - lib/yelpster/v2/search/request/base.rb
89
+ - lib/yelpster/v2/search/request/bounding_box.rb
90
+ - lib/yelpster/v2/search/request/geo_point.rb
91
+ - lib/yelpster/v2/search/request/location.rb
92
+ files:
93
+ - CHANGELOG.rdoc
94
+ - LICENSE.txt
95
+ - Manifest
96
+ - README.rdoc
97
+ - Rakefile
98
+ - TODO.txt
99
+ - lib/yelpster.rb
100
+ - lib/yelpster/client.rb
101
+ - lib/yelpster/record.rb
102
+ - lib/yelpster/response_format.rb
103
+ - lib/yelpster/v1/neighborhood/request/base.rb
104
+ - lib/yelpster/v1/neighborhood/request/geo_point.rb
105
+ - lib/yelpster/v1/neighborhood/request/location.rb
106
+ - lib/yelpster/v1/phone/request/number.rb
107
+ - lib/yelpster/v1/request.rb
108
+ - lib/yelpster/v1/review/request/base.rb
109
+ - lib/yelpster/v1/review/request/bounding_box.rb
110
+ - lib/yelpster/v1/review/request/geo_point.rb
111
+ - lib/yelpster/v1/review/request/location.rb
112
+ - lib/yelpster/v2/business/request/id.rb
113
+ - lib/yelpster/v2/request.rb
114
+ - lib/yelpster/v2/search/request/base.rb
115
+ - lib/yelpster/v2/search/request/bounding_box.rb
116
+ - lib/yelpster/v2/search/request/geo_point.rb
117
+ - lib/yelpster/v2/search/request/location.rb
118
+ - test/test_business_retrieve.rb
119
+ - test/test_business_search.rb
120
+ - test/test_client.rb
121
+ - test/test_neighborhood_search.rb
122
+ - test/test_phone_search.rb
123
+ - test/test_review_search.rb
124
+ - test/yelp_helper.rb
125
+ - yelpster.gemspec
126
+ homepage: https://github.com/nvd/yelpster
127
+ licenses: []
128
+
129
+ post_install_message:
130
+ rdoc_options:
131
+ - --line-numbers
132
+ - --inline-source
133
+ - --title
134
+ - Yelpster
135
+ - --main
136
+ - README.rdoc
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: "0"
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: "1.2"
151
+ requirements: []
152
+
153
+ rubyforge_project: yelpster
154
+ rubygems_version: 1.8.11
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: An object-oriented interface to the Yelp Developer API.
158
+ test_files:
159
+ - test/test_business_retrieve.rb
160
+ - test/test_business_search.rb
161
+ - test/test_client.rb
162
+ - test/test_neighborhood_search.rb
163
+ - test/test_phone_search.rb
164
+ - test/test_review_search.rb
metadata.gz.sig ADDED
Binary file