Created
February 10, 2012 18:58
-
-
Save ryancurtin/1791654 to your computer and use it in GitHub Desktop.
Rake task to build list of countries to call api
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
# Here is the rake task I've created. The API has a little quirk though -- I'm calling 'subcontinent,' but it isn't #working because the subcontinent is stored in the name property (i.e. <subcontinent name="England">). For reference, #the API file I'm referring to is here: http://www.instantworldbooking.com/xml/files/locations.xml | |
# Aside from the first loop, the rest of the should work. I may have to find a way around populating an array with the #locations (such as copying the results and reformatting them - I just need a list of countries from that file). Once I #have the list of locations, I can continue (I'm not sure how to run the rake task yet) | |
"desc" | |
task | |
# make an array of all countries that the api supports -- STILL NEED TO FIGURE OUT HOW TO GET THIS FROM API | |
response = HTTParty.get("http://www.instantworldbooking.com/xml/files/locations.xml") | |
country = response['locations']['continent']['subcontinent'] | |
countryarr = [] | |
country.each do |i| | |
countryarr << i['name'] | |
end | |
# loop over this array and request the country xml | |
countryarr.each do |country| | |
response = HTTParty.get("http://www.instantworldbooking.com/xml/files/#{country}.xml") | |
response.each do |newproperty| | |
hotel = Hotel.new | |
hotel.city << newproperty['properties']['property']['city'] | |
hotel.name << newproperty['properties']['property']['dest'] | |
hotel.country << newproperty['properties']['property']['subcontinent'] | |
hotel.save | |
end | |
end | |
# loop over results using the 'count.times' method we created today | |
# parse those results into the database (save it using active record objects) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lel what is rake?