diff options
| author | mo khan <mo@mokhan.ca> | 2016-05-28 16:11:10 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2016-05-28 16:11:10 -0600 |
| commit | 032defa413b4e775bbf2aab041a385c7d4f57f1d (patch) | |
| tree | 8dccd9cb6c74a8f6b972d245554d0af9e308b771 /app/models | |
| parent | 890fc6b147cd92a2c336457cd044868abcad92e7 (diff) | |
convert search to a static gateway
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/gym.rb | 7 | ||||
| -rw-r--r-- | app/models/search.rb | 10 |
2 files changed, 10 insertions, 7 deletions
diff --git a/app/models/gym.rb b/app/models/gym.rb index a05c553..1b8cc32 100644 --- a/app/models/gym.rb +++ b/app/models/gym.rb @@ -43,8 +43,8 @@ class Gym < ActiveRecord::Base end def self.search_yelp(q: "gym", categories: ["gyms"], city: , page: 1, per_page: 20) - Search.yelp(q, categories, city, page, per_page) do |result| - map_from(result) + Search.yelp.for(q, city, categories, page, per_page) do |result| + Gym.map_from(result) end end @@ -65,8 +65,7 @@ class Gym < ActiveRecord::Base end def self.create_from_yelp!(id) - Gym.find_by(yelp_id: id) || - Gym.map_from(::Yelp.client.business(id).business) + Gym.find_by(yelp_id: id) || Gym.map_from(Search.yelp.for_business(id)) end def self.import(city, pages: 5) diff --git a/app/models/search.rb b/app/models/search.rb index b41a277..6ef0484 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -6,7 +6,7 @@ class Search @client = client end - def search(q, city, categories = [], page = 1, per_page = 20, &block) + def for(q, city, categories = [], page = 1, per_page = 20, &block) return paginate([]) if city.blank? cache(key: key_for(q, city, page, per_page)) do @@ -14,6 +14,10 @@ class Search end end + def for_business(yelp_id) + client.business(yelp_id).try(:business) + end + private def key_for(*args) @@ -45,7 +49,7 @@ class Search end end - def self.yelp(q, categories = [], city, page, per_page, &block) - Yelp.new.search(q, city, categories, page, per_page, &block) + def self.yelp + @yelp ||= Yelp.new end end |
