Skip to content

Commit d9bbae8

Browse files
committedSep 14, 2011
yelp model and reviews method for establishments
1 parent a283480 commit d9bbae8

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed
 

‎.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.bundle
2+
*.swp
3+
*~
24
db/*.sqlite3
35
log/*.log
46
tmp/**/*
57
config/database.yml
8+
config/initializers/yelp.rb

‎Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ gem 'friendly_id', '~> 3.2.1'
77
gem 'graticule'
88
gem 'texticle', '~> 2.0', :require => 'texticle/rails'
99
gem 'unicode_utils'
10+
gem 'rest-client'
11+
gem 'yajl-ruby', :require => 'yajl'
1012

1113
# Controllers
1214
gem 'kaminari'

‎Gemfile.lock

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ GEM
9191
thor (~> 0.14.4)
9292
rake (0.8.7)
9393
rdiscount (1.6.8)
94+
rest-client (1.6.7)
95+
mime-types (>= 1.16)
9496
routing-filter (0.2.3)
9597
actionpack
9698
rspec (2.5.0)
@@ -121,6 +123,7 @@ GEM
121123
polyglot (>= 0.3.1)
122124
tzinfo (0.3.26)
123125
unicode_utils (1.0.0)
126+
yajl-ruby (0.8.3)
124127

125128
PLATFORMS
126129
ruby
@@ -136,10 +139,12 @@ DEPENDENCIES
136139
rails (= 3.0.6)
137140
rails3-generators
138141
rdiscount
142+
rest-client
139143
routing-filter
140144
rspec-rails (>= 2.0.0.rc)
141145
shoulda
142146
sqlite3-ruby
143147
texticle (~> 2.0)
144148
thin
145149
unicode_utils
150+
yajl-ruby

‎app/models/establishment.rb

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ def self.find_or_create_by_name_and_address_and_city(name, address, city, attrib
3434
}.merge(attributes))
3535
end
3636

37+
def reviews
38+
term = name.gsub(/ Inc\.?/i, '')
39+
response = Yelp.reviews :term => term, :location => full_address
40+
if response['name'] == term
41+
response['reviews']
42+
else
43+
[]
44+
end
45+
end
46+
3747
def short_address
3848
if geocoded? && street
3949
street

‎app/models/yelp.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Yelp
2+
class YelpError < StandardError; end
3+
4+
def self.reviews(params)
5+
response = Yajl::Parser.parse RestClient.get('http://api.yelp.com/business_review_search', {params: {limit: 1, ywsid: ENV['YWSID'], cc: 'CA'}.merge(params)})
6+
if response['message']['text'] == 'OK'
7+
response['businesses'].first
8+
else
9+
raise YelpError, response['message']['text']
10+
end
11+
end
12+
13+
end

‎config/database.example.yml

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ development:
77
database: restonet_development
88
pool: 5
99
timeout: 5000
10+
username: postgres
11+
password: f(nt(dit?
1012

1113
# Warning: The database defined as "test" will be erased and
1214
# re-generated from your development database when you run "rake".
@@ -18,6 +20,8 @@ test:
1820
database: restonet_test
1921
pool: 5
2022
timeout: 5000
23+
username: postgres
24+
password: f(nt(dit?
2125

2226
production:
2327
host: localhost
@@ -26,3 +30,5 @@ production:
2630
database: restonet_production
2731
pool: 5
2832
timeout: 5000
33+
username: postgres
34+
password: f(nt(dit?

0 commit comments

Comments
 (0)
Please sign in to comment.