class SinglePlatform::Location
Attributes
business_type[R]
factual_id[R]
general[R]
hours[R]
id[R]
location[R]
out_of_business[R]
phones[R]
published_at[R]
Public Class Methods
in_zipcode(zipcode, opts={})
click to toggle source
# File lib/single_platform/location.rb, line 6 def self.in_zipcode(zipcode, opts={}) data = in_zipcode_request(zipcode, opts) locations = parse_locations(data) locations.each(&:fetch_menus) if opts[:include_menus] locations end
new(data)
click to toggle source
# File lib/single_platform/location.rb, line 13 def initialize(data) data.each do |key, value| instance_variable_set :"@#{key.underscore}", value end end
Private Class Methods
in_zipcode_request(zip_code, opts={})
click to toggle source
# File lib/single_platform/location.rb, line 25 def self.in_zipcode_request(zip_code, opts={}) response = SinglePlatform::Request.get "/locations/search", count: 1000, q: zip_code, updatedSince: "2011-01-01" if response.body["total"] < 1000 response.body["results"] else data = response.body["results"] (response.body["total"].to_i / 1000.0).floor.times do |i| data << SinglePlatform::Request.get("/locations/search", count: 1000, q: zip_code, updatedSince: "2011-01-01", page: i+1).body["results"] end data end end
parse_locations(data)
click to toggle source
# File lib/single_platform/location.rb, line 38 def self.parse_locations(data) data.map{|result| new(result) } end