R
ry an
I'm trying to interface with the flickr API to pull my photos into my
site. I don't want to use the "flickr.rb" gem, I'd like to do it the
other way so I can learn (plus I had trouble loading the gem on my
server). Anyway, here's what I have:
#Application.rb controller
def get_response(path, http)
request = Net::HTTP::Get.new(path)
response = http.request(request)
response.value
response.body
end
path =
"/services/rest/?api_key=API_KEY&method=flickr.photos.search&user_id=USER_ID&tags=TAG"
http = Net::HTTP.new('flickr.com')
@photo_ids = Array.new
http.start do |http|
xml = get_response(path, http)
REXML:ocument.new(xml).root.get_elements('photo').each do
|photo|
id = photo.attributes['id']
@photo_ids << id
end
end
#Application.rhtml layout
<% for p in @photo_ids %>
<%= p %>
<% end %>
This just doesn't do anything. It doesn't give me errors, but it the
@photo_ids variable is empty. I've also tried <%= p.id %> and so on.
Can someone see something wrong with this code? Thanks!
site. I don't want to use the "flickr.rb" gem, I'd like to do it the
other way so I can learn (plus I had trouble loading the gem on my
server). Anyway, here's what I have:
#Application.rb controller
def get_response(path, http)
request = Net::HTTP::Get.new(path)
response = http.request(request)
response.value
response.body
end
path =
"/services/rest/?api_key=API_KEY&method=flickr.photos.search&user_id=USER_ID&tags=TAG"
http = Net::HTTP.new('flickr.com')
@photo_ids = Array.new
http.start do |http|
xml = get_response(path, http)
REXML:ocument.new(xml).root.get_elements('photo').each do
|photo|
id = photo.attributes['id']
@photo_ids << id
end
end
#Application.rhtml layout
<% for p in @photo_ids %>
<%= p %>
<% end %>
This just doesn't do anything. It doesn't give me errors, but it the
@photo_ids variable is empty. I've also tried <%= p.id %> and so on.
Can someone see something wrong with this code? Thanks!