Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

retrive data from nycopendata restaurant health inspection

  • Loading branch information...
commit 5281ae1734fb12812e3708982b8181dad264031f 1 parent b86e82f
Andrea C. Granata threeturn authored

Showing 1 changed file with 48 additions and 0 deletions. Show diff stats Hide diff stats

  1. +48 0 lib/fetcher/nycopendata/restaurant_health_inspection.rb
48 lib/fetcher/nycopendata/restaurant_health_inspection.rb
... ... @@ -0,0 +1,48 @@
  1 +module Fetcher
  2 + module Nycopendata
  3 + class RestaurantHealthInspection
  4 +
  5 + attr_reader :json
  6 +
  7 + def initialize
  8 + @sess = Patron::Session.new
  9 + @sess.timeout = 10
  10 + @sess.base_url = 'http://nycopendata.socrata.com'
  11 + @sess.headers['User-Agent'] = 'nytimes-hackday-restaurant-app/0.1'
  12 + end
  13 +
  14 + def get(name)
  15 + escaped_name=CGI.escape(name)
  16 + resp = @sess.get("/api/views/zf7n-cm69/rows.json?search=#{escaped_name}")
  17 + @json = ActiveSupport::JSON.decode(resp.body)
  18 + @data = @json["data"]
  19 + resp = mice_roaches_alert
  20 + resp.merge!({:category => category, :last_inspected => last_inspected_date})
  21 + resp
  22 + end
  23 +
  24 + def mice_roaches_alert
  25 + mice_data = roaches_data = nil
  26 + @data.reverse.each do |inspection|
  27 + if inspection[20].include?("mice")
  28 + mice_data = Time.at(inspection[16])
  29 + end
  30 + if inspection[20].include?("roaches")
  31 + roaches_data = Time.at(inspection[16])
  32 + end
  33 + end
  34 + { :mice_data => mice_data, :roaches_data => roaches_data }
  35 + end
  36 +
  37 + def category
  38 + @data.first[22] if @data
  39 + end
  40 +
  41 + def last_inspected_date
  42 + Time.at(@data.first[16]) if @data
  43 + end
  44 +
  45 +
  46 + end
  47 + end
  48 +end

0 comments on commit 5281ae1

Please sign in to comment.
Something went wrong with that request. Please try again.