Topic: Flickr tutorial behind a proxy?

Hi,

I' beginning to play with RoR, so I've been trying to follow this tutorial step by step : http://media.rubyonrails.org/video/flic … s-ajax.mov

The corporate proxy prevents my application from connecting to the flickr server.

My flickrController class looks like this :

class FlickrController < ApplicationController
 
  def search
    flickr = Flickr.new 'myflikrapikey'
    render :partial=>'photo', :collection => flickr.photos(
      :tags=>params[:tags],
      :per_page=>'24'
    )
  end
 
end

Hence I extended the Flickr class
class ProxyFlickr < Flickr
  attr_accessor :proxy_host, :proxy_port, :proxy_username, :proxy_pwd 
   
  def http_get(url)
    Net::HTTP::Proxy(proxy_host, proxy_port,
                     proxy_user, proxy_pass).get_response(URI.parse(url)).body.to_s
  end
end

and after that, a quick'n dirty change in the controller :
class FlickrController < ApplicationController
 
  def search
    flickr = ProxyFlickr.new 'myflikrapikey'
    flickr.proxy_host = '10.1.1.3'
    flickr.proxy_port = '8080'
    flickr.proxy_username = 'myusername'
    flickr.proxy_pwd = 'mypassword'
    render :partial=>'photo', :collection => flickr.photos(
      :tags=>params[:tags],
      :per_page=>'24'
    )
  end
 
end

When calling the overwritten get_http method, the server starts to loop and eventually spits this out :

C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    /app/helpers/proxy_flickr.rb:8:in `http_get'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:148:in `method_missing'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `method_missing'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `method_missing'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:102:in `photos'
    /app/controllers/flickr_controller.rb:10:in `search'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `send'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `perform_action_without_filters'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:579:in `call_filters'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:572:in `perform_action_without_benchmark'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    C:/Dev/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/rescue.rb:201:in `perform_action'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `send'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `process_without_filters'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:568:in `process_without_session_management_support'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/session_management.rb:130:in `process'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:389:in `process'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:149:in `handle_request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:107:in `dispatch'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:104:in `synchronize'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:104:in `dispatch'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:35:in `dispatch'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/../lib/mongrel/rails.rb:76:in `process'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/../lib/mongrel/rails.rb:74:in `synchronize'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/../lib/mongrel/rails.rb:74:in `process'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in `process_client'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `each'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `process_client'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `initialize'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `new'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `initialize'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `new'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `each'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/servers/mongrel.rb:64
    C:/Dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    C:/Dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/server.rb:39
    C:/Dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    C:/Dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    ./script/server:3
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.1.10/lib/ruby-debug.rb:90:in `debug_load'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.1.10/lib/ruby-debug.rb:90:in `main'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.1.10/bin/rdebug-ide:74
    C:\Dev\ruby\bin\rdebug-ide:19:in `load'
    C:\Dev\ruby\bin\rdebug-ide:19
    -e:2:in `load'
    -e:2

lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:66:in `method_missing'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/flickr-1.0.2/./flickr.rb:102:in `photos'
    /app/controllers/flickr_controller.rb:10:in `search'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `send'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:1166:in `perform_action_without_filters'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:579:in `call_filters'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:572:in `perform_action_without_benchmark'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    C:/Dev/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/rescue.rb:201:in `perform_action'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `send'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:529:in `process_without_filters'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/filters.rb:568:in `process_without_session_management_support'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/session_management.rb:130:in `process'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/base.rb:389:in `process'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:149:in `handle_request'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:107:in `dispatch'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:104:in `synchronize'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:104:in `dispatch'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:120:in `dispatch_cgi'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/dispatcher.rb:35:in `dispatch'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/../lib/mongrel/rails.rb:76:in `process'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/../lib/mongrel/rails.rb:74:in `synchronize'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/../lib/mongrel/rails.rb:74:in `process'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:159:in `process_client'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `each'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:158:in `process_client'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `initialize'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `new'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:285:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `initialize'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `new'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel.rb:268:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:282:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `each'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/configurator.rb:281:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:128:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/lib/mongrel/command.rb:212:in `run'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-x86-mswin32/bin/mongrel_rails:281
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:503:in `load'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/servers/mongrel.rb:64
    C:/Dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    C:/Dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in `new_constants_in'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in `require'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/rails-2.1.1/lib/commands/server.rb:39
    C:/Dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
    C:/Dev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
    ./script/server:3
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.1.10/lib/ruby-debug.rb:90:in `debug_load'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.1.10/lib/ruby-debug.rb:90:in `main'
    C:/Dev/ruby/lib/ruby/gems/1.8/gems/ruby-debug-ide-0.1.10/bin/rdebug-ide:74
    C:\Dev\ruby\bin\rdebug-ide:19:in `load'
    C:\Dev\ruby\bin\rdebug-ide:19
    -e:2:in `load'
    -e:2

Rendering C:/Dev/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/templates/rescues/layout.erb (internal_server_error)

I'm using Ruby 1.8.6, RoR 2.1.1, Mongrel (same error w/ WEBrick).

Any idea why it's going haywire?

thx

Fred B.
(Ruby on Rails uber noob)