class UsdaMarket::Api
Attributes
options[RW]
Public Class Methods
new(options={})
click to toggle source
# File lib/usda_market.rb, line 9 def initialize(options={}) @options = options raise ArgumentError, 'Missing argument zip' if @options[:zip].nil? end
Public Instance Methods
return_all()
click to toggle source
Returns an array of hashes. Each hash has an id, market name, address, time, products and google link
# File lib/usda_market.rb, line 21 def return_all market_details = return_names.collect do |value| url = URI.parse "http://search.ams.usda.gov/farmersmarkets/v1/data.svc/mktDetail?id=#{value['id']}" result = JSON.parse(Net::HTTP.get(url) ) value = value.merge(result.delete('marketdetails')) value end market_details end
return_names()
click to toggle source
Returns an array of hashes. Each hash has an id and market name key
# File lib/usda_market.rb, line 15 def return_names url = URI.parse"http://search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=#{@options[:zip]}" JSON.parse(Net::HTTP.get(url)).delete('results') end