Created
August 11, 2014 02:59
-
-
Save spq24/5368d889c9be76938165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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