Created
May 28, 2009 14:05
-
-
Save benbonnet/119319 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 photo | |
@photo_url = CGI::unescape("#{params[:photo_url]}") | |
id = params[:id] | |
# affiche la photo sur son format le plus grand dispo dans l'api | |
# la photo n'est pour le moment pas enregistré | |
# l'appel est caché | |
check = Item.find(:first, :conditions => {:item_type_id => 5, :remote_url => @photo_url}) | |
if check.nil? | |
api = "xxxxxx" | |
method = "flickr.photos.getInfo" | |
remote_url = "http://api.flickr.com/services/rest/?method=#{method}&api_key=#{api}&photo_id=#{id}" | |
@doc = Hpricot.parse(open(remote_url)) | |
it = Item.create( | |
:titre => @doc.search("title").inner_html, | |
:description => @doc.search("description").inner_html, | |
:remote_url => @photo_url, | |
:unixtime => Time.parse(@doc.search("dates").attr(:taken)).to_i, | |
:remote_id => id, | |
:remote_url => @photo_url, | |
:item_type_id => 5) | |
# @doc.search("dates").attr(:posted) | |
# @doc.search("dates").attr(:takengranularity) | |
# @doc.search("dates").attr(:lastupdate) | |
# @doc.search("notes").inner_html | |
# | |
############################################# | |
#it.user_id = u.id | |
############################################# | |
@doc.search('location').collect do |e| | |
l = Location.new | |
l.latitude = e['latitude'] | |
l.longitude = e['longitude'] | |
l.accuracy = e['accuracy'] | |
l.context = e['context'] | |
l.place_id = e['place_id'] | |
l.woeid = e['woeid'] | |
if @doc.search("neighbourhood").size >= 1 | |
l.neightbourhood_place_id = @doc.search("neighbourhood").attr(:place_id) | |
l.neightbourhood_woeid = @doc.search("neighbourhood").attr(:woeid) | |
l.neightbourhood_name = @doc.search("neighbourhood").inner_html | |
end | |
if @doc.search("locality").size >= 1 | |
l.locality_place_id = @doc.search("locality").attr(:place_id) | |
l.locality_woeid = @doc.search("locality").attr(:woeid) | |
l.locality_name = @doc.search("locality").inner_html | |
end | |
if @doc.search("county").size >= 1 | |
l.county_place_id = @doc.search("county").attr(:place_id) | |
l.county_woeid = @doc.search("county").attr(:woeid) | |
l.county_name = @doc.search("county").inner_html | |
end | |
if @doc.search("region").size >= 1 | |
l.region_place_id = @doc.search("region").attr(:place_id) | |
l.region_woeid = @doc.search("region").attr(:woeid) | |
l.region_name = @doc.search("region").inner_html | |
end | |
if @doc.search("country").size >= 1 | |
l.country_place_id = @doc.search("country").attr(:place_id) | |
l.country_woeid = @doc.search("country").attr(:woeid) | |
l.country_name = @doc.search("country").inner_html | |
end | |
l.save | |
end | |
end | |
render(:update) do |page| | |
page.replace_html "api_content", :partial => "flickr/photo" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment