[Facebooker-talk] relative root

David Clements digidigo at gmail.com
Mon Jan 21 23:05:17 EST 2008


Hey Shawn,

FYI:
I played around with this some more today with the application that
has the same requirements as yours:

Canvas path is http://apps.facebook.com/travelerstable
Callback URL is http://www.travelerstable.com/facebook

Controller is facebook_controller, and the is only one controller that
handles all the facebook requests.  This is the same sort of setup
that you have right?

I was able to get facebooker to work by implementing the previous
mentioned change that allows AbstractRequest.relative_root_url to
return nil if it is not set and by adding this route.

map.canvas_page_base("#{ENV["FACEBOOK_APP_NAME"]}/:action/:id",
:controller => 'facebook')

I remember you saying that you didn't really like this approach, but I
thought I would try it out anyway.



I would like to take a poll to understand how many people fall into
one of these four use cases.


1) Callback path and canvas path have the same ending.
2) Callback path and canvas path have a different ending and app uses
multiple controllers to handle facebook requests
3) Callback path and canvas path have a different ending and app use
one controller to handle all facebook requests ( This is what Shawn
and I have been discussing. )
4) Callback path only contains the host portion. (ex. http://www.example.com/ )

I hope that is clear, did I cover them all?
Dave




On Jan 20, 2008 8:14 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote:
> I hacked a bit and got the rfacebook behavior to work.  I've probably broken the Facebooker way, so we'll need to reconcile the changes somehow to make it backward compatible with existing Facebooker apps.
>
> Here's the new sub as I have it:
>
> def rewrite_url_with_facebooker(*args)
>       options = args.first.is_a?(Hash) ? args.first : args.last
>       is_link_to_canvas = link_to_canvas?(@request.request_parameters, options)
>       #options[:skip_relative_url_root] ||= !is_link_to_canvas
>       options[:skip_relative_url_root] = true
>       if is_link_to_canvas && !options.has_key?(:host)
>         options[:host] = "apps.facebook.com"
>       end
>       options.delete(:canvas)
>
>       path = rewrite_url_without_facebooker(*args)
>
>       facebook_canvas_path = ENV['FACEBOOKER_RELATIVE_URL_ROOT'] || ENV['FACEBOOK_CANVAS_PATH']
>       facebook_callback_path = ENV['FACEBOOKER_CALLBACK_PATH']
>
>       print "path: #{path}\n\n"  # for debugging only
>
>       # replace anything that references the callback with the
>       # Facebook canvas equivalent (apps.facebook.com/*)
>       if path.starts_with?(facebook_callback_path)
>         path.sub!(facebook_callback_path, facebook_canvas_path)
>         path = "http://apps.facebook.com#{path}"
>       elsif "#{path}/".starts_with?(facebook_callback_path)
>         path.sub!(facebook_callback_path.chop, facebook_canvas_path.chop)
>         path = "http://apps.facebook.com#{path}"
>       elsif (path.starts_with?("http://www.facebook.com") or path.starts_with?("https://www.facebook.com"))
>         # be sure that URLs that go to some other Facebook service redirect back to the canvas
>         if path.include?("?")
>           path = "#{path}&canvas=true"
>         else
>           path = "#{path}?canvas=true"
>         end
>       elsif (!path.starts_with?("http://") and !path.starts_with?("https://"))
>         # this will fail here because 'request' is not defined; need to translate to Facebooker vars
>
>         # default to a full URL (will link externally)
>         RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to get canvas-friendly URL ("+path+") for ["+options.inspect+"], creating an external URL instead"
>         path = "#{request.protocol}#{request.host}:#{request.port}#{path}"
>       end
>     end
>
> Shawn
>
>
> On Sun, 20 Jan 2008 18:30:52 -0700, David Clements wrote:
> > Hey Shawn,
> >
> > The Facebooker way is to set your relative root via
> > ENV["FACEBOOKER_RELATIVE_URL_ROOT"] , this root should have nothing to
> > do with your controller names.  For me I make it my app name.
> >
> > The facebooker way to do this is to utilize the rails support for
> > relative root path.  This allows for all of your URLs, whether you are
> > a facebook app or not,  to have a prefix to the path.  Facebooker
> > strips this FACEBOOKER_RELATIVE_ROOT on the way in, and the url
> > rewrite code adds it in for you along with apps.facebook.com.  This
> > effects all the urls generated via url_for.
> >
> > After doing this, all of your controllers will generate canvas based
> > urls, whether link_to or url_for.
> >
> > Does that make sense?  I am not familiar with rfacebook, so I think I
> > misunderstood your original intent.
> >
> > I will also start documenting some of the code so that some of these
> > answers can be gleaned from a quick read.
> >
> > Dave
> >
> > On Jan 20, 2008 6:15 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote:
> >> How does Facebooker alter the ActionController::Base class?  I see
> >> that rfacebook uses an include:
> >>
> >> ActionController::Base.send(:include,
> >> RFacebook::Rails::ControllerExtensions)
> >> ActionController::Base.send(:include,
> >> RFacebook::Rails::Plugin::ControllerExtensions)
> >>
> >> I need to do something similar to write the url_for wrapper, so I
> >> can rewrite the path returned by url_for.  But I want to include the
> >> new function in the "right" Facebooker way.
> >>
> >> Shawn
> >>
> >> On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote:
> >>
> >>> Hey Shawn,
> >>>
> >>> Are you saying that you basically only want one controller to handle
> >>> all your facebook requests?   And that appname == controller?
> >>>
> >>> I looked into this scenario and it looks like maybe the code would
> >>> need to change to handle it.  Basically you don't want to have any
> >>> relative_root_url and you set the Callback Url in your facebook
> >>> application settings to the same name as your controller.
> >>>
> >>> Something like http://appserver.com/facebook_handler
> >>>
> >>> Then create a facebook_handler_controller.
> >>>
> >>> And then change the code in facebook_url_rewriting to this
> >>>
> >>> def relative_url_root
> >>>
> >>> "/#{ENV['FACEBOOKER_RELATIVE_URL_ROOT']||ENV['FACEBOOK_CANVAS_PATH']}"
> >>> if (parameters['fb_sig']  &&
> >>> (ENV['FACEBOOKER_RELATIVE_URL_ROOT']||ENV['FACEBOOK_CANVAS_PATH'])
> >>> )
> >>> end
> >>>
> >>>
> >>> This will effectively remove the relative url root.
> >>>
> >>> But maybe I am wrong as to what you are trying to do.
> >>>
> >>>
> >>> Dave
> >>>
> >>>
> >>>
> >>> On Jan 19, 2008 7:23 PM, Shawn Van Ittersum
> >>> <svicalifornia at gmail.com> wrote:
> >>>> Hey guys,
> >>>>
> >>>> In rfacebook, the callback_path variable allows the developer to
> >>>> strip part of the URL off of auto-generated links (link_to).  For
> >>>> example, if an app's canvas pages lead to a certain controller:
> >>>>
> >>>>   http://apps.facebook.com/appname/index
> >>>>   -> http://appserver.com/controller/index
> >>>>
> >>>> I want the link_to method to prefix the action with
> >>>> 'http://apps.facebook.com/appname/', automatically stripping out the
> >>>> app server and controller.  The rfacebook config variables allows
> >>>> this with callback_path set to '/controller/'.
> >>>>
> >>>> Is there an equivalent behavior/config for Facebooker?
> >>>>
> >>>> Thanks,
> >>>> Shawn
> >>>> _______________________________________________
> >>>> Facebooker-talk mailing list
> >>>> Facebooker-talk at rubyforge.org
> >>>> http://rubyforge.org/mailman/listinfo/facebooker-talk
> >>>>
> >>
>


More information about the Facebooker-talk mailing list