Skip to content

Instantly share code, notes, and snippets.

@steveburkett
Created July 3, 2013 16:41
Show Gist options
  • Save steveburkett/5920285 to your computer and use it in GitHub Desktop.
Save steveburkett/5920285 to your computer and use it in GitHub Desktop.
class Middleware::Caring::Api
include HTTParty
#debug_output $stdout
base_uri 'dir.caring.com'
format :json
RESOURCE = '/api/v1/reviews/feed.json'
PID = 'fb0487e0'
def initialize(location)
@location = location
canonical_facility_url = location.business_listing_for(ReputationSite::CARING).url
@facility_name = URI.parse(canonical_facility_url).path.split('/').last
end
def all_reviews
total_pages = reviews_page(1)["total_pages"]
(2..total_pages).each_with_index do |index|
reviews_page index
end
end
protected
def reviews_page(index)
reviews = self.class.get(RESOURCE, query: { page: index, pid: PID})
save_reviews(reviews["results"])
reviews
end
def save_reviews(reviews)
reviews.each do |review|
ReviewPusher.push( @location, Hashie::Mash.new(review["local_review"]) )
end
end
end
class Middleware::Caring::ReviewPusher
self.push(location, caring_review) do
return if Review.exists_with_identifier?( caring_review.id )
location.reviews.create!(
reputation_site_id: ReputationSite::APARTMENT_RATINGS,
excerpt: caring_review.content,
author: caring_review.user.display_name,
url: caring_review.canonical_url,
identifier: caring_review.id,
rating: caring_review.rating,
date: caring_review.created_at,
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment