added support for alternative flickr ids
This commit is contained in:
parent
cf547f8f6f
commit
5f8a974a7f
2 changed files with 37 additions and 13 deletions
|
@ -1,18 +1,21 @@
|
|||
class FlickrController < ApplicationController
|
||||
FlickrawOptions = { :lazyload => true, :timeout => 2 }
|
||||
require 'flickraw'
|
||||
@@flickr_id = "13827925@N00"
|
||||
|
||||
|
||||
|
||||
caches_action :interesting, :recent
|
||||
|
||||
|
||||
|
||||
|
||||
def photo
|
||||
@pid = params[:id]
|
||||
begin
|
||||
@pinfo = flickr.photos.getInfo :photo_id => @pid
|
||||
rescue => e
|
||||
flash[:error] = "Photo " + params[:id].to_s + " could not be found. Random photo displayed."
|
||||
@pid = flickr.photos.search(:user_id => @@flickr_id).rand.id
|
||||
@pid = flickr.photos.search(:user_id => get_user_id).rand.id
|
||||
@pinfo = flickr.photos.getInfo :photo_id => @pid
|
||||
end
|
||||
@psize = flickr.photos.getSizes(:photo_id => @pid).find{|m| m.label == "Medium"}
|
||||
|
@ -24,7 +27,7 @@ class FlickrController < ApplicationController
|
|||
end
|
||||
|
||||
def home
|
||||
@pid = flickr.photos.search(:user_id => @@flickr_id).rand.id
|
||||
@pid = flickr.photos.search(:user_id => get_user_id).rand.id
|
||||
@pinfo = flickr.photos.getInfo(:photo_id => @pid)
|
||||
@psize = flickr.photos.getSizes(:photo_id => @pid).find{|m| m.label == "Medium"}
|
||||
|
||||
|
@ -36,7 +39,7 @@ class FlickrController < ApplicationController
|
|||
def interesting
|
||||
@parray = Array.new
|
||||
|
||||
result = flickr.photos.search(:user_id => @@flickr_id, :per_page => 20, :sort => "interestingness-desc")
|
||||
result = flickr.photos.search(:user_id => get_user_id, :per_page => 20, :sort => "interestingness-desc")
|
||||
for r in result do
|
||||
@parray += [:id => r.id, :source => flickr.photos.getSizes(:photo_id => r.id).find{|m| m.label == "Thumbnail"}.source]
|
||||
end
|
||||
|
@ -49,7 +52,7 @@ class FlickrController < ApplicationController
|
|||
def recent
|
||||
@parray = Array.new
|
||||
|
||||
result = flickr.photos.search(:user_id => @@flickr_id, :per_page => 20)
|
||||
result = flickr.photos.search(:user_id => get_user_id, :per_page => 20)
|
||||
for r in result do
|
||||
@parray += [:id => r.id, :source => flickr.photos.getSizes(:photo_id => r.id).find{|m| m.label == "Thumbnail"}.source]
|
||||
end
|
||||
|
@ -59,4 +62,25 @@ class FlickrController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def get_user_id
|
||||
if params and params[:user_id]
|
||||
user_id = params[:user_id]
|
||||
else
|
||||
user_id = "13827925@N00"
|
||||
end
|
||||
|
||||
return user_id
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -39,19 +39,19 @@ ActionController::Routing::Routes.draw do |map|
|
|||
# Note: These default routes make all actions in every controller accessible via GET requests. You should
|
||||
# consider removing or commenting them out if you're using named routes and resources.
|
||||
|
||||
map.connect 'f/i', :controller => "flickr", :action => "interesting"
|
||||
map.connect 'p/:id', :controller => "flickr", :action => "photo"
|
||||
map.connect 'f/:action/:id', :controller => "flickr", :action => "recent"
|
||||
map.connect 'u/:user_id/r', :controller => "flickr", :action => "recent", :requirements => { :user_id => /.*/ }
|
||||
map.connect 'u/:user_id/i', :controller => "flickr", :action => "interesting", :requirements => { :user_id => /.*/ }
|
||||
map.connect 'u/:user_id/p/:id', :controller => "flickr", :action => "photo", :requirements => { :user_id => /.*/ }
|
||||
map.connect 'u/:user_id', :controller => "flickr", :action => "home", :requirements => {:user_id => /.*/}
|
||||
|
||||
map.connect 'r', :controller => "flickr", :action => "recent"
|
||||
map.connect 'i', :controller => "flickr", :action => "interesting"
|
||||
map.connect 'p/:id', :controller => "flickr", :action => "photo"
|
||||
|
||||
map.connect 's/i', :controller => "screenshot", :action => "index"
|
||||
map.connect 's/:filename', :controller => "screenshot", :action => "single", :requirements => { :filename => /.*/ }
|
||||
|
||||
|
||||
map.connect 'i/:action', :controller => "info"
|
||||
|
||||
map.connect ':controller/:action/:id'
|
||||
map.connect ':controller/:action/:id.:format'
|
||||
map.connect 'o/:action', :controller => "info"
|
||||
|
||||
map.root :controller => "flickr", :action => "home"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue