Skip to content

Instantly share code, notes, and snippets.

@spq24
Created August 11, 2014 02:59
Show Gist options
  • Save spq24/5368d889c9be76938165 to your computer and use it in GitHub Desktop.
Save spq24/5368d889c9be76938165 to your computer and use it in GitHub Desktop.
def create
@postcodes = Postcode.all
@postcodes.find_each do |p|
response = HTTParty.get("https://io.myrheem.com/v1/public/contractors/getcontractorsbyzipandradius?PostalCode=#{p.zip}&Radius=100&bHeatCool=true&bWHRes=false&bWHComm=false&bWHTankless=false&bSolarWH=false&bHomeGen=false&bPoolSpa=false&bDesignStar=false&bKwikComfort=false&bPPlus=false&bCashback=false&bTC=false&bASP=false&bRheem=true&bRuud=false&bPHCC=false").to_json
@contractors = JSON.parse(response)[ "Contractors" ]
@contractors.to_a.each do |c|
contractorname = c["OrganizationName"]
if Contractor.exists?(organizationname: contractorname)
next
else
Contractor.create(:OrganizationName => c["OrganizationName"], :phone => c["Phone"], :website => c["WebSite"], :postalcode => c["postalcode"], :email => c["CorporateEmail"], :address_one => c["AddressLine1"], :address_two => c["AddressLine2"], :city => c["City"], :state => c["State"])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment